Database Indexing medium
You query `WHERE Age=30 AND Status='Active'`. You have separate indexes on `Age` and `Status`. Why is this often slower than a single composite index `(Age, Status)`?
- A Relational databases are fundamentally unable to utilize more than one index per query, making the redundant index a waste of resources.
- B The database must perform two independent B-Tree traversals and then merge the resulting pointer lists using expensive CPU-bound computations.
- C Maintaining two separate indexes on the same table significantly increases the risk of 'Deadlock' errors during high-concurrency write operations.
- D Composite indexes utilize specialized Hash Map architectures that offer significantly better spatial locality than standard single-column B-Trees.
Answer: B. The database must perform two independent B-Tree traversals and then merge the resulting pointer lists using expensive CPU-bound computations.
This is a common performance trap. When you have separate indexes on `Age` and `Status`, the database first finds all IDs matching `Age=30` and then all IDs matching `Status='Active'`. It must then perform an 'Index Merge' (Bitmap Intersection) to find the common IDs. This merge operation consumes significant CPU and memory bandwidth. A composite index `(Age, Status)` allows the database to navigate directly to the intersection in a single pass through the B-Tree.
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')?