1:已经由s表进行驱动,但是没有使用正确的索引去分组排序,所以产生了Using where; Using temporary; Using filesort,现在要把这个问题解决。
2:is_index就2个值,排序用的是share_id,新建索引需要把分组,排序字段包含进去
#添加索引
mysql> alter table fanwe_share add index idx_share_id_is_index2(share_id,sort,is_index);Query OK, 149462 rows affected (9.85 sec)Records: 149462 Duplicates: 0 Warnings: 0
#查看执行计划:
mysql> desc sELECT sql_no_cache s.*,st.tag_name FROM fanwe_share as s STRAIGHT_JOIN fanwe_share_category as sc ON sc.share_id = s.share_id INNER JOIN fanwe_share_tags as st ON st.share_id = s.share_id INNER JOIN fanwe_goods_category_tags as gct ON gct.cate_id = sc.cate_id WHERE gct.cate_id in(2,14,15,16,17,18)AND s.is_index=1 AND s.status=1 GROUP BY s.share_id ORDER BY s.share_id desc,s.sort desc limit 30;