[英]Why this simple query not using any one index?
询问:
SELECT *, history_count as `count`
FROM pdf_history
WHERE 1 AND history_date>=1426180929 AND history_count!=0
解释
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
优化器选择不使用索引的原因之一是过滤器不减少搜索空间。
例如如果
history_date>=1426180929
或者
history_count!=0
已经带来了所有记录,然后使用索引并没有真正的帮助。
我的建议是执行这两个查询并检查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.