Alex Rivera | Logout

TINYINT vs ENUM(0, 1) for boolean values in MySQL

Asked 2010-08-23T09:19:31.667
31

Which one is better, Tinyint with 0 and 1 values or ENUM 0,1 in MyISAM tables and MySQL 5.1?

Edit
Report

2 Answers

4

My research shows that BIT(1) is a synonym for TINYINT(1) for versions of MySQL before 5.0.3.

MySQL versions after 5.0.3 change how the BIT datatype works. It is no longer a synonym for TINYINT and is the only data type that allows you to store anything in less than one byte.

This datatype may be preferrable to using TINYINT or ENUM. I plan on testing to see which is fastest and the space usage of the three on my blog. There is a link at the bottom if you care to see the size and speed results. Testbed: crummy consumer grade Pentium III box running OpenBSD and MySQL. (With a slower DB dev box, you can really feel the effects of bad code. Also, differences between test queries are more discernible. Alternatively, try using a VM with barely enough resources allocated.)

The MySQL Official Documentation.

Baron Schwartz has this to say about it.

http://www.xaprb.com/blog/2006/04/11/bit-values-in-mysql/

answered 2011-10-19T03:48:45.023
1

I'd suggest the ENUM is preferable because it makes clear what is expected; if it detracts from performance in any measurable way I would be very surprised. To make a tinyint do this work would require CHECK a constraint on the column; none of the MySQL storage engines currently support this.

answered 2010-08-23T09:30:32.370

Your Answer