A database can answer a query by checking every row (a full scan) or by using extra structures that let it skip most rows. Indexes are those extra structures.
Understanding indexes changes how you read query performance: you start seeing queries as “how many rows must be touched?” rather than “how fast is my server?” It also helps you make better schema and query choices—especially for large tables where the difference between scanning millions of rows and touching a few dozen is the difference between seconds and milliseconds.
A table is stored on disk/SSD in pages (blocks). If you run:
SELECT * FROM orders WHERE customer_id = 42;
Without an index on customer_id, the database may need to read many pages to check each row: O(N) work.
With an index, the database can do something closer to O(log N) (or O(1) in some cases) to find where matching rows live, then fetch only those rows.
Indexes speed up queries mainly by turning “look everywhere” into “go directly to the right neighborhood, then the right address.”
A query filters a 50-million-row table by a single column. What is the most accurate reason an index on that column often makes the query dramatically faster?
The speedup usually comes from avoiding touching most rows: the index provides a path to the matching row locations, so the engine reads far fewer pages. It’s tempting to think indexes are mainly about memory tricks or compression, but those are separate features. Parallelism can help some scans, but an index’s primary win is reducing the search space in the first place.