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

Insert thousands of keys and count the pages

7 min read

Count what an insert touches

The lab inserts keys into a B-tree, fifty a tick. The bars show how many pages sit at each level. The numbers below count splits, how full the leaves are, and how many pages each insert has to write. The last number is write amplification: the bytes written, including the log, for each byte of record.

Predict before you press play

You switch the key order from random to ascending. What happens to the page writes per insert?

inserts 3,000 of 30,000height 3page 4,096 bytes

Pages in each level of the tree

root1level 27leaves135

Every lookup reads one page per level, from the root down to a leaf.

leaf pages
135
page splits
140
leaf fill
69%
reads per lookup
2
page writes per insert
0.16
log bytes per insert
144
write amplification
6.4x
Bytes written per byte of record
Bytes written per byte of record. Text version available below the chart.0x3x5x8x10x501,5503,000insertsx
How full the leaf pages are
How full the leaf pages are. Text version available below the chart.0%25%50%75%100%501,5503,000inserts%

Full-page version with guided experiments: B-tree page writes lab.

Things to try

  1. Compare random and ascending key order. Read leaf fill and page writes per insert.
  2. Turn the write-ahead log off and read write amplification.
  3. With the log on, raise the checkpoint spacing to 5000 inserts.
  4. Set keys per page to 8 and watch the tree get taller.
  5. Change how many levels are held in memory and watch reads per lookup.

The full-page lab also has guided experiments to load in one click.

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