decdfgfe
V2EX  ›  问与答

关于 Mysql 分页代码优化的问题。

  •  
  •   decdfgfe · Nov 19, 2015 · 1797 views
    This topic created in 3856 days ago, the information mentioned may be changed or developed.
    代码如下
    $sql="select id,second_level,third_level,title,description,update_time,thumb from p_ed2k where second_level='$cid' and third_level='$scid' order by id DESC limit $offset,$perNum";
    分页越到后面越慢, second_level 和 third_level 已经做索引
    1 replies    2015-11-19 09:34:54 +08:00
    tonic
        1
    tonic  
       Nov 19, 2015
    limit 这个东西... 是全部取出来了再分片的.
    所以你可能直接用 where id > xxxx limit count 比较好.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3246 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 45ms · UTC 11:16 · PVG 19:16 · LAX 04:16 · JFK 07:16
    ♥ Do have faith in what you're doing.