Interactive LabRuns in your browser

B+ Tree Database Index

Interactive B+ Tree with node splits, key promotion, and leaf linked-list range scans.

Speed:
B+ tree of order 3: every node holds at most 2 keys, all data lives in the linked leaves.
–
5030701020304050607080
Height: 3Keys: 8Leaves: 4 next-leaf pointer

About this tool

A B+ tree is the index structure behind almost every relational database and many file systems. Each node holds many keys, so the tree is wide and very shallow: a few levels can index millions of rows, and each level costs one disk or page read. All records live in the leaves, which are linked left to right so range queries can scan them without climbing back up.

This lab implements a real B+ tree of configurable order. It animates the descent for inserts and lookups, splits overflowing leaves (copying the separator key up) and internal nodes (moving it up), grows a new root when needed, and shows a range scan walking the leaf chain.

How to use B+ Tree Database Index

  1. Choose the order — the maximum number of children per node. Small orders split often, which is easier to watch.
  2. Insert keys one by one, or click “Insert 9 more keys” to grow the tree quickly.
  3. Search a key to see one node read per level, then run a range scan to see the leaf-to-leaf pointer walk.
  4. Watch the counters: no matter how many keys you add, every leaf stays at the same depth.

Examples

Leaf split (order 3)

Input
Leaf [10, 20] receives 30
Result
Split into [10, 20] and [30]; 30 is copied up as a separator, so the new root is [30]

Range scan

Input
Range [15, 42]
Result
Descend once to the leaf containing 15, then follow next-leaf pointers until a key exceeds 42

B+ tree vs. B-tree

  • In a B+ tree internal nodes only hold separator keys; all values live in the leaves. In a B-tree values can sit in any node.
  • Smaller internal nodes mean higher fan-out and fewer levels.
  • Linked leaves make full scans and range queries sequential reads.

How shallow is it?

With 16 KB pages and 8-byte keys plus pointers, an InnoDB internal page holds roughly 1,000 children. Three levels then reach about a billion entries, which is why primary-key lookups in MySQL usually need only three or four page reads — and the top levels are almost always cached in memory.

Frequently asked questions

Everything you need to know about this tool and data security.

Why is the key copied up on a leaf split but moved on an internal split?

Leaves must keep every key because they hold the data. Internal nodes only guide the search, so the middle separator can leave the node and move to its parent.

What happens on delete?

An underfull node borrows a key from a sibling or merges with it, which can shrink the tree from the root. This lab focuses on insert, search and range scans.

Why do databases prefer sequential primary keys?

Increasing keys always go into the rightmost leaf, so pages fill completely and splits are cheap. Random keys (like UUIDv4) split pages all over the tree and leave them half empty.

Is my data safe when using this tool?

Yes, 100% safe. This tool operates entirely inside your web browser using client-side JavaScript and WebAssembly. Your data never touches any external server.