This flow shows how you start with a table, pick columns to index, create the index, and then queries use it to speed up searches.
Execution Sample
MySQL
CREATEINDEX idx_name ON employees(last_name);
SELECT * FROM employees WHERE last_name = 'Smith';
Create an index on the last_name column of employees, then run a query that can use this index to find rows faster.
Execution Table
Step
Action
Command/Query
Effect
Output/Result
1
Start with table
Table: employees
Table exists with data
Table ready
2
Choose column to index
Column: last_name
Decide to index last_name
Column selected
3
Create index
CREATE INDEX idx_name ON employees(last_name);
Index idx_name created on last_name
Index created
4
Run query using index
SELECT * FROM employees WHERE last_name = 'Smith';
Query optimizer uses idx_name
Faster search results
5
Return results
Query returns matching rows
Rows with last_name='Smith' fetched
Result set returned
6
End
-
-
Process complete
💡 Index created and query executed using the index for faster search
Variable Tracker
Variable
Start
After Step 3
After Step 4
Final
Table employees
Exists with data
Exists with index idx_name on last_name
Same table, index used in query
Same table, index active
Index idx_name
Not present
Created on last_name
Used by query optimizer
Active and ready for queries
Key Moments - 3 Insights
Why do we create an index on a column?
Creating an index on a column helps the database find rows faster when searching by that column, as shown in execution_table step 4 where the query uses the index.
Does creating an index change the data in the table?
No, creating an index does not change the actual data, it only creates a separate structure to speed up searches, as seen in variable_tracker where the table data remains the same.
Can the query run without the index?
Yes, the query can run without the index but it will be slower because the database must scan all rows, unlike step 4 where the index speeds up the search.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step is the index created?
AStep 4
BStep 2
CStep 3
DStep 1
💡 Hint
Check the 'Action' and 'Effect' columns in execution_table row for step 3
According to variable_tracker, what is the state of the index after step 4?
ACreated but not used
BUsed by query optimizer
CNot present
DDropped
💡 Hint
Look at the 'Index idx_name' row under 'After Step 4' in variable_tracker
If we did not create the index, how would the query performance change according to the flow?
AQuery would be slower
BQuery would be faster
CQuery would not run
DQuery results would be different
💡 Hint
Refer to concept_flow and key_moments about index speeding up searches
Concept Snapshot
CREATE INDEX syntax:
CREATE INDEX index_name ON table_name(column_name);
Indexes speed up searches on columns.
They do not change table data.
Queries use indexes automatically if available.
Useful for large tables with frequent searches.
Full Transcript
Creating indexes in a database helps speed up searching for data. You start with a table, pick columns to index, and run a CREATE INDEX command. This creates a special structure that the database uses to find rows faster. When you run a query that searches by the indexed column, the database uses the index to quickly locate matching rows instead of scanning the whole table. Creating an index does not change the actual data in the table. It only adds a helper structure. Queries can run without indexes but will be slower. Indexes are especially helpful for large tables and frequent searches.