开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜