该查询在我的慢查询日志弹出:什么指数(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