Composite Indexes and Lexicographic Ranges
Use the order of a two-column index to identify contiguous search ranges and explain which predicates can narrow them.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
Leftmost equality creates one contiguous region
In an index ordered by \((a,b)\), entries for \(a=7\) lie together in order of \(b\). A condition \(a=7\) and \(10\le b<20\) then describes a contiguous interval within that region. A condition on \(b\) alone can match separate intervals for every distinct \(a\). Some engines can use repeated seeks under suitable statistics, while the simple one-range scan does not capture all such values together.
Sorting and scanning depend on the same order
If \(a\) is fixed to one value, scanning its part of the index can often produce results in \(b\) order. With several \(a\) groups, their local \(b\) orders do not automatically form global \(b\) order. B-tree nodes define lookup by separators. Cost-based optimization weighs useful output ordering against alternative access costs.[1][2]