Indexes and Performance

Lesson 17 of 20

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.

Full scan

No index? The planner reads every row of the table — fine at 6 rows, painful at 6 million.

Index

CREATE INDEX builds a sorted structure of column values, each with a pointer to its row.

Index seek

The planner walks the sorted structure directly to matching entries — a handful of reads instead of all of them.

The write tax

Every index must be updated on INSERT and UPDATE — reads get faster, writes pay a small fee.