Database Indexing medium
What happens to a B-Tree index when you insert unrelated random keys (like UUID v4) compared to sequential keys (Integers)?
- A The tree structure becomes exponentially deeper with every insert, eventually leading to a O(N) traversal time for simple point-lookups.
- B Physical Page Fragmentation increases, as inserts occur in random pages rather than at the end, leaving pages partially empty and causing frequent splits.
- C The index automatically performs a 'Soft Sort' in the background to ensure that physical storage blocks remain sequentially aligned with the primary key.
- D There is no significant difference, as modern database engines utilize specialized SSD-aware algorithms to normalize the performance of random inserts.
Answer: B. Physical Page Fragmentation increases, as inserts occur in random pages rather than at the end, leaving pages partially empty and causing frequent splits.
Sequential identifiers (like integers) always append to the 'hot' rightmost edge of the B-Tree, filling disk pages to 100% capacity before moving on. Random keys like UUIDs force the database to insert data into random locations. If the target page is full, it must 'split' into two 50%-full pages. This results in 'Page Fragmentation' (wasted disk space) and massive random I/O as the database constantly loads and writes different pages from disk into memory.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- Z-Order Curves (Geohashing) map 2D data to 1D strings for indexing. What is their primary weakness?
- In-Memory databases (Hyper, HANA) often favor Adaptive Radix Trees (ART). Why?
- Log-Structured Merge (LSM) Trees (RocksDB, Cassandra) optimize for Write Throughput. How does their disk IO pattern differ from B-Trees?
- In LSM compaction strategies, 'Universal' (Tiered) compaction prioritizes what over 'Leveled' compaction?
- In LSM trees, what is 'Space Amplification'?
- Why is it generally ineffective to index a 'Low Cardinality' column like `Gender` ('Male'/'Female')?