MySQL为什么不在用作布尔值的int字段上使用索引? [英] Why does MySQL not use an index on a int field that's being used as a boolean?

查看:251
本文介绍了MySQL为什么不在用作布尔值的int字段上使用索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

select * from myTable where myInt

将不会显示即使myInt字段上有索引,在解释查询时也有任何possible_keys。

will not show any possible_keys when explaining the query even though there is an index on myInt field.

编辑:

索引问题不是唯一的。


The index in question is not unique.

推荐答案

要让MySQL使用索引,你必须明确地将int字段与值进行比较(例如是的,1)。

For MySQL to use the index, you have to explicitly compare the int field to a value (e.g. true, 1).

select * from myTable where myInt = true

这篇关于MySQL为什么不在用作布尔值的int字段上使用索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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