0
0
SQLquery~10 mins

Why indexes matter in SQL - Visual Breakdown

Choose your learning style9 modes available
Concept Flow - Why indexes matter
Start Query
Scan Table Rows
Check Each Row for Condition
Return Matching Rows
Start Query
Use Index to Find Rows
Directly Access Matching Rows
Return Matching Rows
This flow shows how a query searches data without and with an index, highlighting how indexes speed up finding rows.
Execution Sample
SQL
SELECT * FROM employees WHERE employee_id = 5;
This query finds the employee with ID 5, showing how an index helps find it faster.
Execution Table
StepActionRows CheckedIndex UsedResult
1Start query execution0NoNo rows found yet
2Scan row 11NoCheck if employee_id=5 (No)
3Scan row 22NoCheck if employee_id=5 (No)
4Scan row 33NoCheck if employee_id=5 (No)
5Scan row 44NoCheck if employee_id=5 (No)
6Scan row 55NoCheck if employee_id=5 (Yes) - Return row
7End query5NoReturned 1 row
1Start query execution0YesNo rows found yet
2Use index to find employee_id=50YesDirectly locate row 5
3Access row 51YesReturn row immediately
4End query1YesReturned 1 row
💡 Without index, all rows scanned until match found; with index, direct access to matching row.
Variable Tracker
VariableStartAfter Step 2After Step 5Final
Rows Checked0145
Index UsedNoNoNoNo
Rows Returned0001
Key Moments - 2 Insights
Why does scanning all rows take longer than using an index?
Because scanning checks each row one by one (see execution_table rows 2-6), while using an index jumps directly to the matching row (rows 2-3 with index).
Does using an index mean fewer rows are checked?
Yes, with an index only the matching row is accessed (execution_table row 3 with index), unlike scanning all rows without index.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, how many rows are checked when using the index?
A0
B1
C5
DAll rows
💡 Hint
Check the 'Rows Checked' column in the rows where 'Index Used' is Yes.
At which step does the query find the matching row without using an index?
AStep 6
BStep 2
CStep 7
DStep 3
💡 Hint
Look at the 'Result' column for the first 'Yes' match without index.
If the table had 1000 rows, how would using an index affect the number of rows checked?
AStill checks all 1000 rows
BChecks half the rows
CChecks fewer rows, close to 1
DChecks twice as many rows
💡 Hint
Indexes allow direct access, so rows checked stay low regardless of table size.
Concept Snapshot
Why Indexes Matter:
- Without index: query scans every row to find matches.
- With index: query uses index to jump directly to matching rows.
- Indexes reduce rows checked, speeding up queries.
- Especially helpful for large tables.
- Use indexes on columns often searched or joined.
Full Transcript
This visual shows how a database query finds data with and without an index. Without an index, the query checks each row one by one until it finds the match, which can be slow for big tables. With an index, the query uses a special data structure to jump directly to the matching row, checking far fewer rows and returning results faster. The execution table traces each step, showing rows checked and whether the index is used. This helps beginners see why indexes matter for query speed.