谁能告诉我为什么这个查询不使用索引 idx_accessorieslinkid 我创建了索引:
CREATE INDEX idx_accessorieslinkid ON `accessorieslink` (actionid);
我是索引的新手,并试图了解它们是如何工作的(以及为什么有时它们不这样做!)
sql
SELECT action.actionid
FROM
ACTION
LEFT JOIN
(SELECT
SUM(accprice) AS accprice,
actionid
FROM
accessorieslink
GROUP BY actionid) AS accprice
ON accprice.actionid = action.actionid
WHERE action.typeid = '2'
AND actiondate2 BETWEEN '20130301' AND '20130301'
ORDER BY actiondate2 DESC
解释结果
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY action index_merge idx_actiontypeid,idx_actiondate idx_actiondate,idx_actiontypeid 4,5 141 Using intersect(idx_actiondate,idx_actiontypeid); Using where; Using index; Using temporary; Using filesort
1 PRIMARY <derived2> ALL 7804
2 DERIVED accessorieslink ALL 12175 Using temporary; Using filesort