簡體   English   中英

為什么這個簡單的查詢不使用任何索引?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM