<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>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                分頁算法: limit (頁碼-1)*長度,長度; 開啟profile機制,獲取查詢時間 查看是否開啟profiling功能 ~~~ SHOW VARIABLES LIKE '%pro%'; 或者 SELECT @@profiling; ~~~ 開啟 ~~~ SET profiling=1; ~~~ # 問題 show profiles; +----------+------------+---------------------------------------+ | Query_ID | Duration | Query | +----------+------------+---------------------------------------+ | 1 | 0.00018700 | select * from yaboo limit 1,10 | | 2 | 0.00050400 | select * from yaboo limit 1000,10 | | 3 | 0.00344900 | select * from yaboo limit 10000,10 | | 4 | 0.04172900 | select * from yaboo limit 100000,10 | | 5 | 0.29384700 | select * from yaboo limit 1000000,10 | | 6 | 2.88306300 | select * from yaboo limit 10000000,10 | +----------+------------+---------------------------------------+ 因此:limit offset,N 當offset非常大時,效率極低 # 原因 mysql并不是跳過offset行,然后單取N行。而是取offset+N行,放棄前offset行,返回N行。效率較低,當offset越大是,效率越低 ![](https://box.kancloud.cn/16d1606a47bf10189663e0fbe61081fa_908x131.jpg) # 辦法 優化辦法: (1)從業務上去解決: 辦法:不允許翻過100頁, 以百度為例,一般翻頁到70頁左右,谷歌40頁左右。 (2)不用offset,用條件查詢: 通過 `where+order+limit` 取代` order+limit` 偏移量,長度 ~~~ select from user order by id limit 偏移量,長度 select from user where id >偏移量 order by id limit 長度 ~~~ +----------+------------+------------------------------------------------+ | Query_ID | Duration | Query | +----------+------------+------------------------------------------------+ | 1 | 0.00018700 | select * from yaboo limit 1,10 | | 2 | 0.00050400 | select * from yaboo limit 1000,10 | | 3 | 0.00344900 | select * from yaboo limit 10000,10 | | 4 | 0.04172900 | select * from yaboo limit 100000,10 | | 5 | 0.29384700 | select * from yaboo limit 1000000,10 | | 6 | 2.88306300 | select * from yaboo limit 10000000,10 | | 8 | 0.00632600 | select * from yaboo where id>10000000 order by id limit 10 | +----------+------------+------------------------------------------------+ where+order+limit獲得相同結果的數據情況下,有索引可以使用,為什么呢? 因為如下圖,where+order+limit值獲得指定區域的有限的記錄條數,比較少,因此可以使用索引 ![](https://box.kancloud.cn/1d087533f6039e08ab2ec45679520962_918x150.jpg) # 注意: where+order+limit的問題 通過where+order+limit實現數據獲取的注意: ① 排序的字段最好是**從1開始**,并且是**連續自增**的,這樣方便where計算并獲得指定的數據信息 ② 一般使用次數較少 --- ![](https://box.kancloud.cn/39d20eba594039b13c6071f4081946af_1360x246.jpg) ![](https://box.kancloud.cn/68da43f5a5bc2af86da2ca35b0ffea10_2428x293.jpg) ![](https://box.kancloud.cn/3366bd98972127d64bffef29b59b8e66_2332x318.jpg) 避免數據量多掃描過多
                  <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>

                              哎呀哎呀视频在线观看