qq_41265012 2019-02-08 00:11 采纳率: 70%
浏览 406
已采纳

mysql 简单的查询语句效率问题

为什么走索引还需要消耗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 组合,就变慢了

  • 写回答

3条回答 默认 最新

  • fc6_1 2019-02-20 13:49
    关注

    只能说明 条件 pid=4 的数据量很少;而status=1的数据有30万条以上。加上 判断条件pid=4 的查询语句都变快了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?