SQL & Relational Databases (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
B-Tree Indexes and the Leftmost Prefix Rule.
senior LevelMost AskedDatabases & SQLData Structures
In Simple Words: A B-Tree (Balanced Tree) index keeps keys sorted in logarithmic time $O(\log N)$ for lookups, range scans, and sorting:
- Composite Index
(A, B, C): Can accelerate queries filtering on:WHERE A = 1WHERE A = 1 AND B = 2WHERE A = 1 AND B = 2 AND C = 3
- Leftmost Prefix Rule: The index cannot be used if query skips column
A(e.g.WHERE B = 2 AND C = 3).