mysql 分页查询及优化
1、分页查询
select * from table limit startNum,pageSize
或者
select * from table limit pageSize offset startNum
2、优化
mysql 做查询时偏移量越大,效率越低。
select * from product limit 10, 20 0.016秒
select * from product limit 100, 20 0.016秒
select * from product limit 1000, 20 0.047秒
select * from product limit 10000, 20 0.094秒
优化方式1:
SELECT * FROM product WHERE ID > =(select id from product limit 866613, 1) limit 20
优化方式2:
SELECT * FROM product a JOIN (select id from product limit 866613, 20) b ON a.ID = b.id