Mysql分页查询优化

其实就是Mysql中常见的 select … from … where … order by … limit ..,.. InnoDb中的原理是先查出 offset + limit条数据,再抛弃offset条数据,如果offset过大,sql的效率会很低。

  1. select的时候,尽量不要 select *, 需要什么数据取什么数据

  2. 先获取offset那条数据的主键,如下: select a,b,c from TABLE where id >= (select from product limit 100000, 1) limit 20 或者 select a,b,c from TABLE t_a join (select id from TABLE limit 100000, 20) t_b on t_a.id = t_b.id

其他方法还在研究中

Written on June 18, 2019