天天看点

Mysql 笔记--分页优化普通分页优化分页

表结构 xxxx(id,title,content,url,status) id为主键,自动递增

普通分页

select * from xxxx where status = 1 limit 1000,100;           

这样查询在数据量比较小,同时查询前面的数据的时候是很快的.但是如果表的数量持续增大(这里的测试数据有589530条数据),同时需要查询后面分页的数据,如:

select * from xxxx where status = 1 limit 235500,500;           

执行上面这条语句,就会很慢. 这里测试结果是 8-9s的样子

优化分页

利用id主键,如下:

select * from xxxx where id >=(select id from xxxx where status=1 limit 235500,1) and status = 1 limit 500;           

上面这条语句的执行结果是 0.24s

效率一下提升40多倍

继续阅读