一 问题描述
select * from table limit 0,10扫描满足条件的10行,返回10行,
但当limit 99989,10的时候数据读取就很慢,limit 99989,10的意思扫描满足条件的99999行,扔掉前面的99989行,返回最后的10行,这样速度就会很慢了 。
二 解决方案
利用表的索引覆盖来加速分页查询,使用索引查询的sql语句中如果select的字段只包含索引列(覆盖索引),那么这种情况查询速度就会很快。
举个例子 :
当id字段是主键,在部分数据库引擎中会创建主键索引。
select id from table limit 99989,10;
会发现查询结果很快。
通过这个查询中返回的id,再次查询对应id(因为又主键索引也会很快).
select * from table where id >= (select id from product limit 99989,1) limit 10;
select * from table where id in (select id from product limit 99989,10);
select * from table t join (select id from table limit 99989,10) t1 on t.ID=t1.id;
原文地址 感谢大佬的分享 @小丛的知识窝
标签:10,99989,Mysql,页数,limit,mysql,table,id,select From: https://blog.csdn.net/2401_89793006/article/details/145569441