为什么走索引还需要消耗8秒,explain检查 这条扫描了30多万条
SELECT * FROM topic where pid=4 and status=1 and id<393203 order by id desc LIMIT 15
只要0.01秒
SELECT * FROM topic where pid=4 and status=1 order by id desc LIMIT 15
只要0.01秒
SELECT * FROM topic where status=1 and id<393203 order by id desc LIMIT 15
为什么where pid=4和id<393203 组合,就变慢了
只能说明 条件 pid=4 的数据量很少;而status=1的数据有30万条以上。加上 判断条件pid=4 的查询语句都变快了
https://www.cnblogs.com/balala/p/5601308.html
建议把执行计划和索引结构发出来,不然没法明确问题;全靠猜。