已存在联合索引 idx_category_id_comments_views
查询语句是
select id from table where
category_id = 1
and
comments > 1
order by views desc;
上面的sql 会产生 下图的 type全表查 All 和 Extra 的 Using filesort , 是大忌
优化方案 : 1跟产品沟通, 功能的 sql 尽量使用定值 就是= ,少用 >
2 将原来的联和索引改成 idx_category_id_views 不要中间的c2
这样 type 是ref 级 和 Extra 是 Using where 大喜