Database Indexing hard
When would you choose a BRIN (Block Range Index) over a B-Tree for a Timestamp column?
- A When the table is exceptionally large, naturally sorted by the indexed column, and you require an index that is thousands of times smaller than a B-Tree.
- B When you need to enforce a strictly 'Unique' constraint across several disparate database partitions while maintaining millisecond-level lookup speed.
- C When the dataset suffers from frequent, random primary key updates that would otherwise cause massive fragmentation in a standard B-Tree structure.
- D When you require absolute millisecond-level precision for point-lookups on columns with high cardinality and a random distribution of values.
Answer: A. When the table is exceptionally large, naturally sorted by the indexed column, and you require an index that is thousands of times smaller than a B-Tree.
A B-Tree stores a pointer for every single row in the table, which can consume gigabytes of RAM for massive datasets. BRIN (Block Range Index) is designed for multi-terabyte 'Timeseries' data that is naturally ordered by the column (e.g., `created_at`). Instead of indexing every row, BRIN only stores the MIN and MAX value for each physical 1MB 'block' of the table. When you query for a specific time, the database only reads blocks where your target could possibly exist. This allows for an index that is often 10,000x smaller than a B-Tree, effectively fitting an index for a petabyte-scale table 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')?