我在我的网络应用程序中使用以下查询。它正在查询一个包含给定时间网上商店价格的结果表。它有大约 100 万条记录。索引是 shopID、StartTime、pID 和 WebsiteID 之一。
查询:
SELECT shopID, tresults.StartTime, tresults.Price
FROM tresults
WHERE tresults.pID = 7
AND WebsiteID = 1 AND StartTime BETWEEN "2013-4-10" AND "2013-4-11"
AND tresults.shopID IN (44, 68, 23, 16, 144, 8, 9, 5)
GROUP BY tresults.StartTime, tresults.Price
ORDER BY tresults.StartTime, tresults.Price
解释结果:
1, SIMPLE, tresults, index_merge, PRIMARY,idxPID,idxWebsite,idxStartTimeASC,idxStartTimeDESC,fk_shopID, idxPID,idxWebsite, 4,4, , 1062, Using intersect(idxPID,idxWebsite); Using where; Using temporary; Using filesort
对我来说看起来不错,但查询仍然需要大约一秒钟才能完成。这在快速网站中是不可接受的。
我怎样才能加快速度?
注意:速度看起来取决于 shopID 的数量
谢谢!