An index turns "read every page" into "follow a few pointers", but only pays off when the query matches a small share of the rows.
Learn the idea first
A dashboard runs SELECT * FROM orders WHERE created_at >= now() - interval '7 days' on 50 million orders (about 600,000 pages). About 1% of rows match. Timings are an illustrative model.
App server
dashboard
Query planner
picks a strategy
B-tree index
orders.created_at
orders table
50M rows · 600,000 pages
Swipe the diagram sideways to see every column →
Where the time goes
6542 ms total
A dashboard runs SELECT * FROM orders WHERE created_at >= now() - interval '7 days' on 50 million orders (about 600,000 pages). About 1% of rows match. Timings are an illustrative model.
Illustrative timings. Real numbers vary with distance, network quality and server load.