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 login form runs SELECT * FROM users WHERE email = 'asha@example.com' on a table of 1,000,000 users stored in about 12,500 pages of 8 KB. Timings are an illustrative model of a warm server with fast SSDs.
App server
runs the login
Query planner
picks a strategy
B-tree index
users.email
users table
1M rows · 12,500 pages
Swipe the diagram sideways to see every column →
Where the time goes
382 ms total
A login form runs SELECT * FROM users WHERE email = 'asha@example.com' on a table of 1,000,000 users stored in about 12,500 pages of 8 KB. Timings are an illustrative model of a warm server with fast SSDs.
Illustrative timings. Real numbers vary with distance, network quality and server load.