<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                #### 分頁算法 ~~~ limit (頁碼-1) * 條數 , 條數 ~~~ #### 測試 ~~~ +----------+------------+--------------------------------------+ | Query_ID | Duration | Query | +----------+------------+--------------------------------------+ | 1 | 0.00049325 | select * from user limit 1000 ,10 | | 2 | 0.03135925 | select * from user limit 100000 ,10 | | 3 | 0.25734325 | select * from user limit 1000000 ,10 | | 4 | 0.77315600 | select * from user limit 3000000 ,10 | +----------+------------+--------------------------------------+ ~~~ 因此:limit offset,N ; 當offset非常大時,效率極低 . 原因是:mysql并不是跳過offset行,然后單取N行。而是取offset+N行,放棄前offset行,返回N行。效率較低,當offset越大是,效率越低。 ![](https://box.kancloud.cn/f168792f638e29332d183fc4cfa9ae21_867x148.png) #### 優化辦法 1. 從業務上去解決:辦法:不允許翻過100頁,以百度為例,一般翻頁到70頁左右,谷歌40頁左右. 2. 不用offset,用條件查詢 , 用條件替代偏移量 . #### 通過 where+order+limit 取代 order+limit 偏移量,長度 ~~~ +----------+------------+------------------------------------------------------------+ | Query_ID | Duration | Query | +----------+------------+------------------------------------------------------------+ | 1 | 0.00030950 | select * from user where id > 2000000 order by id limit 10 | | 2 | 0.00029175 | select * from user where id > 4000000 order by id limit 10 | +----------+------------+------------------------------------------------------------+ ~~~ 并且使用到了索引: ~~~ id: 1 select_type: SIMPLE table: user partitions: NULL type: range possible_keys: PRIMARY key: PRIMARY key_len: 4 ref: NULL rows: 1232052 filtered: 100.00 Extra: Using where 1 row in set, 1 warning (0.00 sec) ~~~ ![](https://box.kancloud.cn/57f8c2d89a1b8a2748fbb0e5d8391bbb_918x172.png) #### 注意 where+order+limit的算法問題 ![](https://box.kancloud.cn/de1d51e4bb170edf0c84daf580985113_701x252.png) 通過where+order+limit實現數據獲取的注意: 1. 排序的字段最好是從1開始,并且是連續自增的,這樣方便where計算并獲得指定的數據信息. 2. 這種方法使用次數較少 , 一般都是從業務上進行解決,就是限制顯示頁數 .
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看