B-tree and B-plus tree indexes, LSM trees, write-ahead logs, buffer pools, query planners and isolation anomalies.
35 cards · basic cards · AI-written, checked twice. Edit anything.
- What is a B-tree?
Show answer
A self-balancing tree where each node can have multiple children and multiple keys, used for efficient disk-based indexing in databases.
- In a B-tree of order m, what is the maximum number of keys per node?
Show answer
m - 1 keys.
- What property ensures all leaves in a B-tree are at the same depth?
Show answer
The balancing property that rebalances nodes during insertion and deletion.
- How do B-plus trees differ from B-trees in data storage?
Show answer
B-plus trees store actual data only in leaf nodes, while internal nodes contain only keys and pointers to child nodes.
- Why are B-plus trees preferred for database indexing?
Show answer
Leaf nodes are linked sequentially enabling efficient range queries and full scans, and all data resides at the same tree depth.
- What is the search time complexity in a balanced B-tree with n keys?
Show answer
O(log n) comparisons, with the actual number of disk I/Os proportional to tree height.
- Describe the B-tree insertion process when a node is full.
Show answer
The node splits into two, the median key is promoted to the parent, and insertion continues recursively upward if the parent also overflows.
- What must be maintained during B-tree deletion to keep the tree valid?
Show answer
The minimum occupancy invariant, which requires each non-root node to contain at least floor(m/2) - 1 keys, necessitating rebalancing through borrowing or merging.
- Why is a range query efficient in a B-plus tree?
Show answer
Leaf nodes are linked together sequentially, so after finding the start key, you can traverse the linked leaves linearly without revisiting internal nodes.
- What is an LSM tree?
Show answer
A data structure that optimizes writes by buffering changes in memory, then sequentially flushing sorted batches to disk as immutable files.
- What is a memtable in an LSM tree?
Show answer
An in-memory data structure, typically a balanced tree or skip list, that buffers recent writes before being flushed to disk as an SSTable.
- What is an SSTable?
Show answer
A Sorted String Table, an immutable file on disk containing key-value pairs in sorted order, created when a memtable is flushed.
- What is compaction in LSM trees?
Show answer
The process of merging overlapping SSTables into fewer SSTables while removing deleted keys, improving read performance at the cost of write overhead.
- What is write amplification in LSM trees?
Show answer
The ratio of total bytes written to disk versus logical bytes written by the application, increased by repeated data movement during compaction.
- How do LSM trees achieve lower write latency compared to B-trees?
Show answer
LSM trees write sequentially to a memtable and log without immediate sorting, while B-trees perform random disk I/O to maintain sorted order.