Full scan
no index200 pages
Every page of 10,000 orders, read to find one.
Module 22 · Databases & indexes
A database with no index reads every page to find one row. Here you find an order in Larkspur’s table, build the index that jumps straight to it, and learn what that index costs every time an order is written.
The whole idea in one example
200 pages
Every page of 10,000 orders, read to find one.
4 pages
One page per level of the tree, then the row.
Page counts come from Larkspur’s generated table and a real B-tree, counted as they run: a teaching database, not any real database’s numbers.
How it works
With no index, every drawer opens
PostgreSQL’s docs: fetching rows separately is much more expensive than reading them sequentially, and a table on one page nearly always gets a sequential scan, indexes or not.
Source, checked 24 October 2026
A B-tree walks one page per level
Use The Index, Luke: tree depth grows very slowly compared to the number of leaf nodes; real-world indexes with millions of records have a depth of four or five.
Source, checked 24 October 2026
Each new order is filed in every index
Use The Index, Luke: the number of indexes on a table is the most dominant factor for insert performance, and each additional index slows inserts further.
Source, checked 24 October 2026
Too many rows, and a scan is cheaper
PostgreSQL’s planner estimates each plan’s cost, in arbitrary units, and seeks the lowest estimated total cost; EXPLAIN shows its estimated rows.
Source, checked 24 October 2026
The story
Larkspur Supply Co.’s orders page crawls; the team finds one order among ten thousand, builds indexes, pays for them on every write and plans the day’s set. You’re on the team that runs the order system.
Your path







Chapter 7 · done
Which indexes make the day’s reads cheapest within the write budget?
Anyone whose product keeps its data in a database and has wondered why one page is quick and another crawls, or why adding an index made writes slower. No background needed; the SQL stays folded away.