简体   繁体   English

为什么MySQL的布尔类型映射到tinyint而不是枚举?

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

Were there performance or compatibility reasons for going with tinyint(1) over an enum? 在枚举上使用tinyint(1)是否存在性能或兼容性原因? Something else? 别的什么?

It may interest you to know that MySQL indexes ENUMs with integers . 您可能会感兴趣的是, MySQL会使用整数对ENUM进行索引

The SQL standard has included a boolean data type since 1999 - with valid values being true, false, unknown, or null. 自1999年以来,SQL标准包含一个布尔数据类型 - 有效值为true,false,unknown或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不支持真正的布尔数据类型 - BOOLEAN映射到TINYINT,它只占用1个字节。 MySQL interprets 0 as false, all other numbers are true. MySQL将0解释为false,其他所有数字都为true。

An enum with at most 8 values is stored in a byte. 具有最多8个值的枚举存储在一个字节中。 A tinyint is stored in an int, too. tinyint也存储在int中。 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. MySQL不知道bools所以人们使用其中任何一个选项,性能等等。这没什么区别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM