开发者

Why does MySQL's boolean type map to a tinyint instead of an enum?

开发者 https://www.devze.com 2023-02-01 11:30 出处:网络
Were there performance or compatibilit开发者_如何学编程y reasons for going with tinyint(1) over an enum?Something else?It may interest you to know that MySQL indexes ENUMs with integers.

Were there performance or compatibilit开发者_如何学编程y reasons for going with tinyint(1) over an enum? Something else?


It may interest you to know that MySQL indexes ENUMs with integers.

The SQL standard has included a boolean data type since 1999 - with valid values being true, false, unknown, or null. Implementation across various database systems is spotty.

MySQL does not support a true boolean data type - BOOLEAN maps to TINYINT, which takes up only 1 byte. MySQL interprets 0 as false, all other numbers are true.


An enum with at most 8 values is stored in a byte. A tinyint is stored in an int, too. So there's no difference. MySQL has no idea about bools so people use either of the options, for performance etc. this makes no difference.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号