Are queries on bitmap indexed fields with low distinct values faster in comparison with b-tree indices?
The common idea that bitmap indices give better query performance on fields with low distinct values in comparison with b-tree indices. But is it true?
For example,
SELECT * FROM some_table WHERE color = 'RED'
.
Here the color
field has low distinct values and can be indexed with either b-tree or bitmap index:
- if
color
uses b-tree index, then for performing the query above, a database should do a binary search + in-order traversal (from the binary search result in both directions) which gives us O(log N + K) ~ O(log N) time complexity, where K - is the number of result rows. K <= N. - if
color
uses bitmap index, then a database does a full scan which gives O(N) time complexity.
So, from my perspective, the bitmap index is even worse. Am I right?