关于Mysql的limit深度分页优化这件事
Mysql 的深度分页优化方法如下:
- 减少回表查询,条件直接转移到主键索引:
select * FROM Product where id >= (select p.id from Product p where p.timeCreated > "2025-09-12 13:34:20" limit 10000000, 1) LIMIT 10;-
优点:减少了回表次数,提高了查询效率
-
缺点:子查询可能产生临时表,影响性能
-
- 使用 inner join 查询:
select * from Product p1 inner join (select p.id from Product p where p.timeCreated > "2025-09-12 13:34:20" limit 10000000,10) as p2 on p1.id = p2.id-
优点:利用索引进行高效连接操作,性能优于直接使用子查询。
-
缺点:需要合理设计索引,避免过多的连接操作
-
本文来自博客园,作者:Carvers,转载请注明原文链接:https://www.cnblogs.com/carver/articles/18728289

浙公网安备 33010602011771号