views:

28

answers:

1

I need to store set value in MySQL column. I completely like the build-in SET type, but it seems that FIND_IN_SET() function requires table scan which is bad.

It seems that SET uses binary values under the hood. If I use binary value to represent a set, for example for a set of four elements it could be something like this:

0100 0101 0110 etc

How I can store it (which type), how to query and take advantage of indexes?

P.S. I indeed need a solution without separate linking table, something similar to SET.

Thanks in advance!

+1  A: 

You can use BIT field type and use Bit functions for quering, however you will need hardcode somewhere yours set values in binary form. Other disadvantage that you can have only 64 possible values.

Michael Pakhantsov
Hadcoding values is not a problem. But if I'd like to select records where first and second bit are set to 1 it seems the full table scan is needed anyway?
artvolk
@artvolk, Index will be used if you create index for your field
Michael Pakhantsov
Your solution seems to be exactly what I need, but it seems indexes are not used if I put bitwise functions in WHERE. More details in separate question: http://stackoverflow.com/questions/3560514/mysql-doesnt-use-indexes-when-query-over-bit-field-using-bitwise-functions
artvolk