MySQL 百万级以上分页优化

正常我们码农数据库的时候一般都是以下这种查询方式:
select * from table order by id limit 100000, 10;
但是以上这种查询会导致我们数据慢死,一般我们采用以下方式:
select * from table order by id limit 1000000, 10;
以上这种查询也不算最快 查询大概也要十几秒,数据不算太多采用以上方式,反之可以尝试以下方式:
celect * from table where id >= (select id from table limit 1000000, 1) limit 10;
以上的也只是提速一点点 正点的来了…:
select * from table where id between 1000000 and 1000010;
另外,如果需要查询 id 不是连续的一段,最佳的方法就是先找出 id ,然后用 in 查询:
select * from table where id in(10000, 100000, 1000000…);
优化Mysql千万级快速分页
Limit 1,111 数据大了确实有些性能上的问题,而通过各种方法给用上where id >= XX,这样用上索引的id号可能速度上快点儿。

猜你喜欢

转载自blog.csdn.net/weixin_43341426/article/details/83389103
今日推荐