简体   繁体   English

为什么这个简单的查询不使用任何索引?

[英]Why this simple query not using any one index?

Query:询问:

SELECT *, history_count as `count` 
FROM pdf_history  
WHERE 1  AND history_date>=1426180929  AND history_count!=0

EXPLAIN解释

id  select_type     table   type    possible_keys   key     key_len     ref     rows    Extra 

1   SIMPLE  pdf_history ALL history_date,history_count  NULL    NULL    NULL    697 Using where

One of the reason optimizer choose not to use the index is when the filter doesn't reduce the search space.优化器选择不使用索引的原因之一是过滤器不减少搜索空间。

for example if例如如果

history_date>=1426180929

or或者

history_count!=0

already bring all the records then using the index doesnt really help.已经带来了所有记录,然后使用索引并没有真正的帮助。

My suggestion do this both querys and check the ANALYZE to see how many of the 600 records are match that filter我的建议是执行这两个查询并检查ANALYZE以查看 600 条记录中有多少与该过滤器匹配

SELECT count(*) FROM pdf_history WHERE history_date>=1426180929;
SELECT count(*) FROM pdf_history WHERE history_count!=0;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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