Generally speaking, no. The bi-state field does not speed up queries when indexing, because you should look at half the lines on average. You want your index entries to be selective โ this entry in the index should only make up a small percentage of the possible values โโ(say, less than 10%, preferably a fraction of a percent). Then using the index ignores most of the data in the table, which gives you a performance advantage.
Some DBMSs support bitmap indexes. They may help, but you are still faced with the problem of selectivity.
The updated question says that the number of values โโwith a value of 1 will be small (less than one percent); will the index be useful to you now?
Answer:
For those queries where you indicate that the value is 1, yes, the index in the column can provide an advantage, provided that the optimizer actually uses the index. You may need to configure the DBMS to understand that the index is distorted in favor of using it with queries, where the value is 1; this tends to be specific to the DBMS, but updating statistics in different guises is the name of the game, possibly using hints in SQL queries. Of course, if the optimizer never uses the index, then it still does not give any benefit - and the optimizer may decide that other indexes somehow help it.
For those queries where the value is 0, the index should not be used. Most likely, the DBMS will continue to maintain an index for values โโof 0, even if it should never use them. It would be an unusual DBMS that could be instructed to "only index this column for values โโother than zero," although this would be very useful.
So - it depends. It depends on the requests, and it depends on the optimizer.
Note also that a composite index for some other commonly used columns, and then for a bit field, may provide some benefit. Thus, if you almost always choose a date range, then the composite index of the date columns and bit fields (perhaps in that order) should provide you with a good index.
Jonathan leffler
source share