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

Viewed 27679

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

5 Answers

For the best performance and space requirements you should collect your boolean values and save them in the same TINYINT. Eg. Save up to 8 boolean values in a TINYINT. 16 boolean values in a SMALLINT etc. Both BIT(1) and ENUM uses at least 1 byte BIT(M) - approximately (M+7)/8 bytes see: https://dev.mysql.com/doc/refman/8.0/en/storage-requirements.html. So if you are storing 1 boolean value I would use TINYINT as it has the same overhead as BIT and ENUM but gives you the option to store 7 more boolean values later if you need.

Related