DataB+treebtreepage splitindex page

B-tree

Definition

A B-tree (in databases, the B+tree variant) keeps sorted keys in leaf pages linked to their neighbours, with branch pages and a root above them holding separator keys; all leaves sit at the same depth.

In practice

Each page holds hundreds of keys, so the fan-out keeps the tree only 3 to 4 levels deep for billions of rows, and the upper levels stay cached in memory. A lookup descends once; a range scan descends once and then follows the leaf chain. It is the default index in PostgreSQL, MySQL InnoDB, SQL Server, Oracle and SQLite.

When a leaf is full, an insert splits it into two half-empty pages, which costs extra writes. Time-ordered keys append at the right edge and stay compact; random keys such as UUIDv4 spread splits and cache misses over the whole index. Write-heavy workloads sometimes prefer LSM trees, which trade read cost for cheaper writes.

Example

With 8 KB pages and about 400 keys per page, 3 levels cover 64 million keys and 4 levels about 25 billion, so a lookup reads at most 4 pages.