In this lesson · topic 1 of 7
Topic 1
A disk reads pages, not keys
3 min read
The unit of storage is a page
A disk, or an SSD, does not hand back one key. It hands back a block, and a database reads and writes in fixed-size pages built on blocks. In the lab a page is 4,096 bytesmeasured and each record takes 128 bytesmeasured of it. That is 32measured records to a page.
This changes what a good index looks like. Memory is cheap to jump around in. A disk is not. Every pointer you follow that lands on a new page is a read, so you want to follow as few pointers as you can.
Why not a binary tree
A binary tree puts one key in each node and sends you left or right. A million keys need about twenty steps. If each step lands on a different page, that is twenty reads for one lookup.
A B-tree makes each node a whole page full of sorted keys, with a child for each gap between them. One page read narrows the search by a factor of dozens, not two. The tree stays shallow, so a lookup reads very few pages. In the lab, 267measured leaf pages sit under a tree that is only 3measured levels tall.
Predict first