我有一个很大的表,里面有大约700万条记录。(MySQL)
列是这样的;
id | atype | textbody | .... id是主键,atype是索引
当我跑的时候
select * from tablename where `atype`='doit' 它使用了一个类型索引。(表中有170万个doit行)
但是当我运行这个查询时
select * from tablename where `atype`='doit' or `atype`='payment'它不使用索引。我只是说possible_index不是一种类型。(表中有168行付款)
对这种行为有什么解释吗?
如果我运行这个查询;
select * from tablename where `atype`='paymentfailed' or `atype`='payment'它使用了一个类型索引。
所以每当我使用'doit‘的时候,它都不会使用atype index
发布于 2016-05-11 09:02:19
MySQL对索引相当挑剔。我认为IN比OR更聪明
select *
from tablename
where `atype` in ('doit', 'payment');如果这不起作用,那么使用union all
select *
from tablename
where `atype` = 'doit'
union all
select *
from tablename
where `atype` = 'payment';https://stackoverflow.com/questions/37151357
复制相似问题