As data grows, performance matters. An index is like a book's index — it lets the database find rows without scanning the whole table.
Database Indexes & Performance
Why some queries are instant and others crawl.
Tap or hover a part to learn more.
Read every row.
Without an index, finding matching rows means a full table scan — the database reads every row. Fine for tiny tables, slow as data grows.
Check your understanding
1. What is the main cost of adding indexes?
2. What tool shows whether a query uses an index?
Keep learning
The essentials
- Without an index, a query does a full table scan; with one on the searched column, it jumps straight to the rows.
- Trade-off: indexes speed up reads but slow down writes (INSERT/UPDATE) and use storage — so index what you search and join on, not everything.
- Primary keys are indexed automatically; add indexes to columns in WHERE and JOIN clauses.
- A query plan (EXPLAIN) shows whether an index is being used — the first tool for tuning slow queries.
This directly supports the JOINs you'll write most.
