該查詢在我的慢查詢日誌彈出:什麼指數(ES)需要添加此查詢正常工作?
SELECT
COUNT(*) AS ordersCount,
SUM(ItemsPrice + COALESCE(extrasPrice, 0.0)) AS totalValue,
SUM(ItemsPrice) AS totalValue,
SUM(std_delivery_charge) AS totalStdDeliveryCharge,
SUM(extra_delivery_charge) AS totalExtraDeliveryCharge,
this_.type AS y5_,
this_.transmissionMethod AS y6_,
this_.extra_delivery AS y7_
FROM orders this_
WHERE this_.deliveryDate BETWEEN '2010-01-01 00:00:00' AND '2010-09-01 00:00:00'
AND this_.status IN(1, 3, 2, 10, 4, 5, 11)
AND this_.senderShop_id = 10017
GROUP BY this_.type, this_.transmissionMethod, this_.extra_delivery
ORDER BY this_.deliveryDate DESC;
表是InnoDB和擁有大約880K行和9-12秒之間需要執行。我嘗試添加下列指數ALTER TABLE orders ADD INDEX _deliverydate_senderShopId_status (deliveryDate , senderShop_id , status, type, transmissionMethod, extra_delivery);
,但沒有實際收益。任何幫助和/或建議是歡迎
這裏是查詢執行計劃現在:
id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE this_ ref FKC3DF62E57562BA6F 8 const 139894 100.00 Using where; Using temporary; Using filesort
我拿出possible_keys值出來的文字,因爲我認爲它在表中列出的所有索引。 (FKC3DF62E57562BA6F)所使用的關鍵看起來像
Keyname Type Unique Packed Field Cardinality Collation Null Comment FKC3DF62E57562BA6F BTREE No No senderShop_id 4671 A
deliveryDate的列類型是什麼? – Thilo 2010-09-28 08:20:57
索引應與查詢計劃分析結合使用,以查看它們如何被真正使用。關於數據庫如何基於數據庫完成的優化使用索引並不總是很明顯。發佈您的查詢計劃與此索引,然後我們將在一個更好的位置來幫助 – InSane 2010-09-28 08:23:49
@Thilo - deliveryDate是datetime – 2010-09-28 08:33:27