Try
↑ ↓ move↵ openesc close
In this lesson · topic 2 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 2

Walking down, splitting up

4 min read

Lookup

Each inner page holds sorted separator keys and a child pointer between each pair. To find a key, start at the root and pick the child whose range holds the key. Repeat until you reach a leaf page, which holds the keys and their records. That is one page read per level.

The root and the level under it are tiny next to the leaves, and every lookup uses them, so they stay in memory. Most lookups then read only the lower levels from disk. In the lab, with the top level cached, a lookup reads 2measured pages. With nothing cached it reads 3measured.

Insert

An insert finds the leaf where the key belongs and puts it in sorted position. If the leaf has room, that is all. One page changed.

If the leaf is full, it splits. A new page is allocated, about half the keys move to it, and the parent gets a new separator key and a pointer to the new page. A split writes the old leaf, the new leaf and the parent. If the parent was also full, it splits too, and the split can climb to the root. When the root splits, the tree gets one level taller. That is the only way a B-tree grows in height, so every leaf is always at the same depth.

The lab counts 277measured splits over its inserts. Nearly every one made a new leaf.

Fill

Splitting a full page in half leaves two half-full pages, and later inserts fill them. With random keys the leaves settle at about 70%measured full. Space is wasted, and the wasted space is what makes room for later inserts without a split.

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