Module 2 · Indexes
Episode 11 B+ Trees: Delete
▶ This video is coming to YouTube soon.
How does a B+ tree delete a key and stay balanced? This episode borrows keys between pages, merges them, cascades a merge up to the root and shrinks the tree, then shows on a real Postgres index that deleting 90% of the keys leaves all 276 pages in place, frees only empty pages, and needs REINDEX to compact.
Chapters
- 0:00Intro
- 0:14Delete 90%, keep every page
- 0:32Just take the key out?
- 1:24The textbook delete
- 1:56Underflow: borrow from a sibling
- 3:00No key to spare: merge
- 3:45Merges climb, the root shrinks
- 5:01The code: delete
- 5:38Postgres: free at empty
- 6:42Proof: deletes leave pages sparse
- 7:34Proof: only empty pages are freed
- 8:29Why Postgres doesn't merge
- 8:53Trade-offs
- 9:22Recap
- 9:49Next: B+ Trees in Practice