Page splits and rebalancing: preserve search boundaries
Trace leaf splits, separator propagation, root growth, and deletion policies while separating logical changes from durable structural updates.
On this page
The question for today
What you’ll understand
- Split an overflowing teaching leaf and choose a consistent separator.
- Explain when a split propagates to the root.
- Distinguish fill targets and deletion cleanup from universal occupancy promises.
An insertion is easy until the target page cannot hold another entry. Splitting creates room by redistributing entries and updating the routing information that makes them findable. The operation must preserve ordering during normal access, concurrent access, and crash recovery. Rebalancing is therefore more than dividing a sorted list into two visually equal halves.
A leaf split introduces a new routing boundary
Consider a teaching B+ leaf holding four entries at capacity. Inserting a fifth requires either reclaiming eligible obsolete space, changing representation, or creating another page. A simple split sorts all five entries and divides them into two valid groups. The parent receives a separator that routes searches to the new right page. In this lesson, the separator is the smallest right-page key and equality routes right. Other formats may choose a different fence-key convention, which must be used consistently by lookup and range traversal.
Separators in a B+ style tree are routing information; copying one into the parent does not remove the corresponding record from its leaf. With duplicates, a complete implementation needs rules that route and scan every matching entry, often using additional ordering components or boundary semantics. Sibling links and fence keys must agree with the redistributed ranges. A reader arriving during structural change cannot be allowed to conclude that a moved entry vanished merely because it followed a parent pointer created before the split.
Parent pressure can propagate upward
The new child reference consumes parent space. If that parent is full, it may split and require another separator in its own parent. This can propagate through several levels, but most leaf splits do not imply immediate root growth. Only an overflowing root requires creating a new root level under the teaching algorithm. Counting a split as a fixed one-page write therefore misses both the common local case and the rarer multi-level case. Recovery logging and sibling changes can add work beyond the new page itself.
Split policy depends on the expected workload and byte layout. A roughly balanced split can provide headroom on both sides for random insertions. An implementation may choose a different distribution for an append-heavy edge. Fill factor is typically a construction or maintenance policy, not a permanent guarantee that pages remain at that exact percentage. A lower initial fill spends space to leave insertion room; it does not eliminate all later splits. Evaluate the resulting page count and future write behavior together rather than optimizing one number.
Deletion and durability have their own invariants
Classical trees may redistribute or merge underfull siblings to maintain a stated minimum occupancy, with special handling for the root. Production MVCC indexes may defer removal until old versions are no longer needed and may use page deletion rules that differ from textbook immediate merging. A logically deleted row can retain index entries while snapshots still need them. Reclaiming obsolete versions can avoid a split, but deleting an entry before its visibility lifetime ends is a correctness error rather than useful space recovery.
Crash recovery must make every reachable state interpretable. A structural change can involve the original leaf, a new sibling, neighboring links, and a parent; these changes require the engine's prescribed logging and publication protocol. The queue lab isolates maintenance capacity instead. Reset, set λ=4 and μ=3, predict backlog grows by one work unit per second, then Play or Step. Reset again, set λ=2 and μ=3, predict four initial work units drain in four seconds, then Play or Step. This constant-rate model does not execute splits, replay a log, or verify a tree invariant.
Work it through
Split five distinct entries
A teaching leaf holds keys 10,20,30,40 with capacity four. Insert 25, split into a two-entry left leaf and a three-entry right leaf, and use the smallest right key as separator.
Sort the combined keys: 10,20,25,30,40. The chosen split gives left {10,20} and right {25,30,40}.
Copy separator 25 into the parent and route equality right. A lookup for 25 reaches the right leaf, while a lookup for 20 reaches the left.
If the parent has room, only its local routing structure expands and the tree height stays unchanged. If it cannot fit the additional child relationship, propagate according to the parent-splitting algorithm.
The separator is 25, and the record with key 25 remains in the leaf. This count-based example assumes fixed-width entries and distinct keys.
The living notebook
Explore the model
Interactive lab · queue
Structural maintenance still needs capacity
Reset, set λ=4 and μ=3, predict one extra queued work unit per second, then Play or Step. Separately Reset, set λ=2 and μ=3, predict the four-unit initial backlog drains in four seconds, then Play or Step. This fluid workload model does not split pages or implement durable recovery.
- Fluid backlog
- 4
- Net rate · λ − μ
- −1 /s
- M/M/1 mean residence
- 1 s
Fluid backlog starts at 4 and follows max(0, 4 + (λ − μ)t). The separate M/M/1 residence-time formula assumes Poisson arrivals, exponential service and λ < μ. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forSplits add conditional maintenance work whose arrival rate must fit the engine's effective capacity.
Pause & reason
Check your understanding
Your turn
Try it yourself
In a fictional workload, base insertion work is one page event. Two percent of insertions incur four additional page events on average. Find expected events per insert and for 10,000 inserts.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Weight the extra work by its probability, then scale the expectation.
Compare with the solution
Expected work is 1+0.02×4=1.08 page events per insertion. Across 10,000 insertions, the expected total is 10,800 events under stable assumptions. This is not a maximum, and repeated changes to one dirty page may be coalesced before physical writeback.
Keep the idea
Take it with you
- A split changes data placement and routing boundaries together.
- Split propagation can add levels only when the root must grow.
- Occupancy, version cleanup, and durable publication depend on the actual engine.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.