简体   繁体   中英

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? 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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