Definition · B-tree heightFor a tree in which every internal node holds up to B children, the height h is the smallest integer with Bʰ ≥ N, where N is the number of keys stored. Equivalently, h = ⌈log_B N⌉.
A lookup descends one node per level and reads one page per node, so an uncached lookup costs h page reads.
N = 1 000 000 000 B = 500
h = 1 500 < N
h = 2 250 000 < N
h = 3 125 000 000 < N
h = 4 62 500 000 000 ≥ N stop
height = 4 level sizes at 4 kB a page
L1 4.00 kB L2 2.00 MB L3 1.00 GB L4 500.00 GB
That table is not an illustration of the answer; it is the computation. Four multiplications and four comparisons, in exact integer arithmetic, and the height is the number of multiplications the accumulator needed. The lab draws the same four rows.
Why the lab multiplies instead of taking a logarithm
Because at every exact power of the fanout a quotient of two logarithms can land a few units in the last place above the integer, and the ceiling then adds a level that does not exist. At B = 3 and N = 9, log(9)/log(3) evaluates to 2.0000000000000004 and its ceiling is 3 — a two-level tree reported as three, which on a page about counting I/Os is a whole extra I/O. It is not a rare corner: B = 5 at N = 125, B = 8 at N = 2 097 152 and B = 19 at N = 2 476 099 all do the same thing. The lab prints what a logarithm would have said beside the exact answer and tells you when the two disagree.
Example · Where the height actually movesHold B = 500 and raise N. At 10⁶ the height is 3; at 10⁹ it is 4; at 10¹² it is 5. Three orders of magnitude buy one level. The height changes only when N crosses a whole power of B, so every tree holding between 125 000 001 and 62 500 000 000 keys — a range of five hundred to one — is exactly four levels deep.
The page cache takes the top off
Look at the level sizes rather than the level count. The top two levels together are 4.00 kB + 2.00 MB; the third is 1.00 GB and the fourth is 500.00 GB. So the levels that are cheap to keep in memory are exactly the ones every descent passes through, and keeping them is what an engine does without being asked. Two megabytes removes half the I/Os of every lookup in the system.
The number that multiplies into a workload is the cached one. Ten thousand lookups a second against this tree with two levels resident is 20 000 disk reads a second; against the same tree with nothing resident it is 40 000. The height did not change and the device's day did.
Two things the model assumes. Nodes are taken to be full, and a real B-tree's nodes sit somewhere between half full and full, so the effective fanout is below the page's capacity and the true height is occasionally one more than this calculation says. And a lookup is taken to be one page read per level, which ignores the leaf splitting across pages. Both errors point the same way — the real cost is at or just above the computed one — which is what makes the computed one usable.