At 04:13 PM 1/27/2004, Mike Boone wrote:
Hi all,

I was hoping to use a TINYINT to store 8 distinct boolean values. That works
fine, but is there any way to optimize searching on a specific bit? I didn't
see a way for MySQL to create an index on a specific bit of the TINYINT. Am
I better off "wasting" space by putting each boolean value in its own
TINYINT?

Thanks for the advice!
Mike Boone
http://boonedocks.net/mike

Mike,
You're making way too much work for yourself. Unless you're dealing with a hundred million rows and you are short of space, I'd use SET (if you need more than 1 of the 8 bits turned on at the same time) to store your values. If you need only 1 of the 8 turned on, use ENUM instead. Either option will make coding easier and people would actually understand your SQL statements.<g> See http://www.mysql.com/doc/en/SET.html and http://www.mysql.com/doc/en/ENUM.html.


BTW, if you choose to use 8 different columns, and have an index on each column, MySQL won't use an index in the search if the value you're searching for appears in more than 30% of the rows. Since you're only storing two values in each column (0 or 1), the indexes probably won't work if the values are evenly distributed.

Mike



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to