分页优化

Posted waterystone

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了分页优化相关的知识,希望对你有一定的参考价值。

一、传统分页

Select * from table limit 10000,10;

二、LIMIT原理

Limit 10000,10 偏移量越大则越慢


三、推荐分页

3.1  

Select * from table WHERE id>=23423 limit 11; #10+1 (每页10条) 
Select * from table WHERE id>=23434 limit 11;

  

3.2

Select * from table WHERE id >= ( select id from table limit 10000,1 ) limit 10;

  

 

3.3

Select * from table INNER JOIN (SELECT id from table limit 10000,10) USING(id)

  

 

3.4

程序取ID: Select id from table limit 10000,10;
Select * from table WHERE ID in(123,456…);

  




以上是关于分页优化的主要内容,如果未能解决你的问题,请参考以下文章