2016-05-16 63 views
0

我執行我將InnoDB數據庫以下沒有ORDER BY的查詢速度較慢?


查詢,而不ORDER BY

SELECT SQL_NO_CACHE second_designer 
    FROM itemrow FORCE INDEX(second_designer) 
    WHERE category like '%' 
     and type like '%' 
     and availability like '%' 
    GROUP BY second_designer 

259 results in 0.0286 seconds. 


查詢與ORDER BY DESC

SELECT SQL_NO_CACHE second_designer 
    FROM itemrow FORCE INDEX(second_designer) 
    WHERE category like '%' 
     and type like '%' 
     and availability like '%' 
    GROUP BY second_designer 
    ORDER BY second_designer DESC 

259 results in 0.0008 seconds. 


INDEX

ADD INDEX `second_designer` (`second_designer ` , `availability`, 
          `category`, `type`) USING BTREE 

EXPLAIN

id select_type table type possible_keys key   key_len ref rows Extra 
1 SIMPLE  itemrow index second_designer second_designer 608 NULL 44521 Using where; Using index 


爲什麼by子句所以比一個沒有更快地進行訂單查詢?

+0

這個問題是相當無意義的,您擁有的索引無法在任何查詢的WHERE子句中使用。你只給出一個查詢的解釋。 – e4c5

+0

解釋對兩個查詢都是一樣的。也不是解釋告訴索引'second_designer'正在使用? – Pieter

+0

如果您發佈了更清晰的縮進解釋輸出,那麼這僅適用於該組。 – e4c5

回答

0

當我們使用它的順序時,它使用索引對結果行進行排序。在您的查詢中沒有使用索引順序。即差異查詢以更快的順序運行,通過訂購