Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 07 · From Scratch · Database · with code: Go · about 27 min to read

Play it as a journeyTutor comes with a plan

Database 04: The B-Tree

The B-Tree
The B-Tree · Open board

Follows Pages, and hands off to Write-Ahead Log.

Before you start. This series builds a small database: a program that stores rows on disk and finds them again by key. So far it can split a file into fixed-size 4 KB blocks called pages, and give every row an address made of a page number plus a slot inside that page. It can also find one row instantly by key, using a table built for single lookups, but that table cannot answer “every row between these two keys,” only one key at a time, because the trick that makes it fast also scrambles the order of the keys. What’s missing is a catalog that keeps its entries in order and is still built out of those same fixed-size pages. That catalog is what this lesson builds.

Lesson 49 of 117 in From Scratch

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • 1979: a survey paper about an idea everyone had already had
  • The wall: a table that forgets the order of your keys
  • The fix: gates hold rows, signs hold directions
  • The signs: a page that holds no rows at all
  • Following the signs: three signs, two hundred thousand rows
  • When a gate fills up: the split
  • Why it never leans: balanced without any repair
  • Back to the wall: walking gates in order
  • Counting the fanout
  • The codec: turning a page into a struct
  • Search: the descent
  • The split, written out
  • Watch it happen
  • The range scan
  • The numbers, measured
  • What this build leaves out
  • The other fork

Terms it explains: leaf, internal node, separator, pointer, node, tree, disk read, height, splits, root, B-tree, 10 billion, After an internal split,, Delete the sibling re-threading.

Review From Scratch