Loading

关于Mysql的limit深度分页优化这件事

Mysql 的深度分页优化方法如下:

  1. 减少回表查询,条件直接转移到主键索引:
    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;
    • 优点:减少了回表次数,提高了查询效率
    • 缺点:子查询可能产生临时表,影响性能
  2. 使用 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
    • 优点:利用索引进行高效连接操作,性能优于直接使用子查询。
    • 缺点:需要合理设计索引,避免过多的连接操作
posted @ 2025-02-21 09:30  Carvers  阅读(24)  评论(0)    收藏  举报