数据库:mysql(innodb)ver 14.14 distrib 5.5.60,用于debian linux gnu(x86\u 64),使用readline 6.3
论坛帖子表大小:300万行
主查询(3个条件+1个订单):
SELECT * FROM forum_posts WHERE deleted = 0 AND published = 1 AND
show_homepage = 1 ORDER BY id DESC LIMIT 5 OFFSET 25;
5 rows in set (12.56 sec)
无订单查询(3个条件)
SELECT * FROM forum_posts WHERE deleted = 0 AND published = 1 AND
show_homepage = 1 LIMIT 5 OFFSET 25;
5 rows in set (0.01 sec)
使用order by和where中的2个条件进行查询(已删除+显示\u主页)
SELECT * FROM forum_posts WHERE deleted = 0 AND show_homepage = 1 ORDER
BY id DESC LIMIT 5 OFFSET 25;
5 rows in set (0.01 sec)
使用order by和where中仅有2个条件的查询(已删除+已发布)
SELECT * FROM forum_posts WHERE deleted = 0 AND published = 1 ORDER BY
id DESC LIMIT 5 OFFSET 25;
5 rows in set (0.01 sec)
为什么主查询运行时间约为12秒?表中有所有4个字段的索引(3个字段来自条件,1个字段来自顺序)。
我还为3个字段和所有4个字段创建了计算索引。什么都帮不了。
请帮助理解问题的原因。
暂无答案!
目前还没有任何答案,快来回答吧!