What happens when you insert a key into a B-tree page that is full?
Sketch your own answer first, then compare it with the one below.
A strong answer
The page splits. The engine allocates a new page, moves about half of the keys to it, and adds a separator key and a pointer to the parent page so lookups can find the new page.
If the parent is also full, it splits in the same way, and the split can climb to the root. When the root splits, the tree grows one level taller. That is the only way a B-tree gets taller, so all leaves stay at the same depth.
A split writes at least three pages for one insert: the old leaf, the new leaf and the parent. Splits are rare per insert, but they are why one small write can touch several pages.
Sources
- Douglas Comer (1979). The Ubiquitous B-Tree.