1
這是我的MySQL查詢:MySQL的:GROUP BY優化
SELECT [columns] FROM article a
LEFT JOIN category_article ca ON a.id=ca.aid
LEFT JOIN category c1 ON c1.id=ca.cid
LEFT JOIN navigation n ON n.cid=c1.id
LEFT JOIN navigation nn ON nn.id=n.parent
LEFT JOIN category c2 ON nn.cid=c2.id
GROUP BY a.id
LIMIT 10
,這是我的執行計劃:
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE n ref status,cid status 1 const 13 Using index condition; Using temporary; Using file...
1 SIMPLE c1 eq_ref PRIMARY,status_special PRIMARY 4 tb.n.cid 1 Using where
1 SIMPLE nn eq_ref PRIMARY PRIMARY 4 tb.n.parent 1 NULL
1 SIMPLE c2 eq_ref PRIMARY PRIMARY 4 tb.nn.cid 1 NULL
1 SIMPLE ca ref cid_aid cid_aid 4 tb.n.cid 53 Using where; Using index
1 SIMPLE a eq_ref PRIMARY,status_show_date PRIMARY 4 tb.ca.aid 1 Using where
我guestion是我使用GROUP BY的文章表,但MySQL的改變順序因此它使用臨時文件和文件夾,並且需要執行很多操作。
不,我有索引在cid列 – user3311313