Database Indexing easy
In a composite index `(A, B)`, if specific rows have `NULL` for column B, are they included in the index?
- A No, standard B-Tree indexes strictly exclude all rows containing a NULL value to minimize the overall physical footprint of the index file.
- B Yes, modern B-Tree indexes typically include NULL as a sortable value, allowing the database to efficiently satisfy `IS NULL` query predicates.
- C Only in specialized NoSQL databases, as relational systems require all indexed columns to possess a concrete, non-null value for hash-consistency.
- D Yes, but only if the database is configured to automatically convert all incoming NULL values into empty strings or zero-value numeric equivalents.
Answer: B. Yes, modern B-Tree indexes typically include NULL as a sortable value, allowing the database to efficiently satisfy `IS NULL` query predicates.
Contrary to common belief, most modern relational databases (Postgres, SQL Server, etc.) *do* index NULL values. They treat NULL as a specific, sortable entry in the B-Tree (often placing it at the very beginning or end of the sort order). This allows the database to use the index for queries like `WHERE phone_number IS NULL`, avoiding a full table scan. Note that Oracle's standard B-Tree indexes are a notable exception, as they typically do not store entries where all columns in the index are NULL.
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')?