If I have 8 boolean values in a record and those 8 values are always used when doing a query against the table and the data in the table is static (read-only), is it faster to get matching records by indexing and querying against a one byte field like binary(1) or is it better to have 8 separate bit columns with all 8 added to an index?
Share
Indexes on single bit field will be basically useless. A bit has terrible selectivity, 0 or 1, and will be likely disregarded by the optimizer. 8 indexes on 8 bit fields are going to be 8 indexes disregarded by the optimizer.
An index on a byte column is only slightly more selective, with 256 distinct values. But if you are seeking individual bit patterns, like ‘is bit 3 on’, then there are no way to express this as a individual value to seek nor as a range.
Conclusion is that no matter what you try, you will end up with a table scan anyway.
So better explain what is your problem, not your solution, and perhaps we can think at something more efficient.