Loading…
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
SELECT * FROM users WHERE country = 'IN' on 1,000,000 users. There is an index on country, but about 40% of users are in India. Timings are an illustrative model.
App server
report
Query planner
uses statistics
B-tree index
users.country
users table
1M rows · 12,500 pages
Swipe the diagram sideways to see every column →
Where the time goes
432 ms total
SELECT * FROM users WHERE country = 'IN' on 1,000,000 users. There is an index on country, but about 40% of users are in India. Timings are an illustrative model.
Illustrative timings. Real numbers vary with distance, network quality and server load.