0
0
MySQLquery~10 mins

Creating indexes in MySQL - Visual Walkthrough

Choose your learning style9 modes available
Concept Flow - Creating indexes
Start with Table
Choose Column(s) to Index
Run CREATE INDEX Command
Index Created in Database
Queries Use Index for Faster Search
End
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
CREATE INDEX 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
StepActionCommand/QueryEffectOutput/Result
1Start with tableTable: employeesTable exists with dataTable ready
2Choose column to indexColumn: last_nameDecide to index last_nameColumn selected
3Create indexCREATE INDEX idx_name ON employees(last_name);Index idx_name created on last_nameIndex created
4Run query using indexSELECT * FROM employees WHERE last_name = 'Smith';Query optimizer uses idx_nameFaster search results
5Return resultsQuery returns matching rowsRows with last_name='Smith' fetchedResult set returned
6End--Process complete
💡 Index created and query executed using the index for faster search
Variable Tracker
VariableStartAfter Step 3After Step 4Final
Table employeesExists with dataExists with index idx_name on last_nameSame table, index used in querySame table, index active
Index idx_nameNot presentCreated on last_nameUsed by query optimizerActive 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.