Machine Room

Database Indexes

How a database finds one row in ten million. The one-page notes from the reel.

Download the PDF

One-page notes on database indexes: without an index the database checks 10,000,000 rows one at a time; an index on users(id) is a sorted copy of the id column with a row address (page · slot) next to each id; a B-tree goes root, middle, leaf, then the row: 10,000,000 rows in 3 hops; one write touches the table and all 10 indexes, 11 places; index the columns you search by (WHERE), join on (JOIN) and sort by (ORDER BY), not every column.

On a phone, press and hold the image to save it. The reel: Database Indexes: How 10 Million Rows Become 3 Hops.