2015-11-17 98 views
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的改变顺序因此它使用临时文件和文件夹,并且需要执行很多操作。

回答

0

查看表格的索引会很有用。我怀疑“navigation.cid”没有索引。尝试在此列上添加索引,并仅添加此索引。

+0

不,我有索引在cid列 – user3311313