问题描述
在 MySQL 数据库中哪个更快?布尔值,还是使用零和一来表示布尔值?我的前端只有一个是/否单选按钮.
Which is faster in a MySQL database? Booleans, or using zero and one to represent boolean values? My frontend just has a yes/no radio button.
推荐答案
某些前端"在启用使用布尔值"选项的情况下,会将所有 TINYINT(1) 列视为布尔值,反之亦然.
Some "front ends", with the "Use Booleans" option enabled, will treat all TINYINT(1) columns as Boolean, and vice versa.
这允许您在应用程序中使用 TRUE 和 FALSE 而不是 1 和 0.
This allows you to, in the application, use TRUE and FALSE rather than 1 and 0.
这根本不会影响数据库,因为它是在应用程序中实现的.
This doesn't affect the database at all, since it's implemented in the application.
在 MySQL 中并没有真正的 BOOLEAN
类型.BOOLEAN 只是 TINYINT(1) 的同义词,TRUE 和 FALSE 是 1 和 0 的同义词.
There is not really a BOOLEAN
type in MySQL. BOOLEAN is just a synonym for TINYINT(1), and TRUE and FALSE are synonyms for 1 and 0.
如果在编译器中完成转换,应用程序的性能不会有任何差异.否则,差异仍然不会很明显.
If the conversion is done in the compiler, there will be no difference in performance in the application. Otherwise, the difference still won't be noticeable.
您应该使用可以让您更有效地编码的任何方法,尽管不使用该功能可能会减少对特定前端"供应商的依赖.
You should use whichever method allows you to code more efficiently, though not using the feature may reduce dependency on that particular "front end" vendor.
这篇关于真/假与 MySQL 中的 0/1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!