真/假vs MySQL中的0/1 [英] True/False vs 0/1 in MySQL

查看:91
本文介绍了真/假vs MySQL中的0/1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

推荐答案

启用了使用布尔值"(Use Booleans)选项的某些前端"会将所有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.

这篇关于真/假vs MySQL中的0/1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆