Try
↑ ↓ move↵ openesc close
In this lesson · topic 1 of 7
  1. 1. A disk reads pages, not keys
  2. 2. Walking down, splitting up
  3. 3. Insert thousands of keys and count the pages
  4. 4. One small record, one whole page
  5. 5. The log lets the pages wait
  6. 6. How often to write the pages out
  7. 7. Pages, splits and the log

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

A tree holds thousands of keys, and each page holds 32 of them. What do you expect the height to be?

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms