Why some queries fly and others crawl — watch CREATE INDEX turn a slow full-table scan into an instant seek.
The big picture
Same query, different speed
Without help, the engine answers every query by reading rows one by one. An index is a sorted lookup structure that lets it jump straight to the answer.
1
Full scan
No index? The planner reads every row of the table — fine at 6 rows, painful at 6 million.
2
Index
CREATE INDEX builds a sorted structure of column values, each with a pointer to its row.
3
Index seek
The planner walks the sorted structure directly to matching entries — a handful of reads instead of all of them.
4
The write tax
Every index must be updated on INSERT and UPDATE — reads get faster, writes pay a small fee.
Same query, different speed
Full scan1No index? The planner reads every row of the table — fine at 6 rows, painful at 6 million.
Index2CREATE INDEX builds a sorted structure of column values, each with a pointer to its row.
Index seek3The planner walks the sorted structure directly to matching entries — a handful of reads instead of all of them.
The write tax4Every index must be updated on INSERT and UPDATE — reads get faster, writes pay a small fee.
4 building blocks make up Same query, different speed
Watch it run
Create an index, then watch the plan change
Press play: the SQL text never mentions the index — the planner finds it and swaps the full scan for a seek.
create_index.sql
1-- Find a row without reading them all
2CREATEINDEX idx_emp_name
3ONemployees(name);
4
5SELECT salary
6FROM employees
7WHERE name ='Ava';
CREATE INDEX builds a sorted lookup structure over the name column.
Memory
no variables yet — press play
Console
Index created: idx_emp_name.
Step 1/6
How it works
An indexed query, end to end
Click each stage — this is the fast path a planner picks when an index fits the filter.
Visualize
Index or full scan?
For every query the planner asks one question: does an index fit this filter?
process decision input / output start / end
Practice
Match the performance vocabulary
Click a term, then click its description to lock the pair.
5 conceptsTap a card to expand
?Indexdrops into place
?Full scandrops into place
?Index seekdrops into place
?Plannerdrops into place
?Write taxdrops into place
Recap
Key takeaways
Key takeaways5 takeaways
01
An index turns a read-everything scan into a targeted seek.
02
The SQL text never changes — the planner finds the index by itself.
03
Indexes are not free: they cost disk space and slow down writes.
04
Index the columns you filter and join on, not every column you own.
05
Small tables are fast anyway — indexes shine when data grows.