Php+MySql分頁機制兩種方案的比較測試:

來源:互聯網
上載者:User
mysql|比較|分頁 硬體環境:PIII550,128M,15.2G
軟體環境:Win98+Apache+Php4+MySql

方案一:
  1.第一次查詢時用Select count(1) from tab where condition 取得滿足條件的記錄數$rows
  2.通過前頁數$page,每頁記錄數$rpp取回記錄集
    select * from tab where condition limit ($page-1)*$rpp,$rpp
  3.顯示返回記錄集的所有記錄。
  4.頁面轉移時將$rows傳遞給以後頁面。

方案二:
  1.取回滿足條件的記錄集
    select * from tab where condition
  2.移動指標到($page-1)*$rpp
  3.顯示$rpp條記錄

==============+======+==============================================+======+======+========
    記錄數    | 方案 | 次數   1   2   3   4   5   6   7   8   9   0 | 平均 | 平均 | 效率比
==============+======+==============================================+======+======+========
              |      |第一頁  2 , 1 , 1 , 2 , 1 , 1 , 2 , 2 , 1 , 2 |  1.3 |      |
              |  一  +----------------------------------------------+------+  1.6 |
10000條記錄時 |      |其它頁  2 ,2 , 2 , 3 , 1 , 1 , 2 , 2 , 2 , 2 |  1.9 |      | 4.8125
              +------+----------------------------------------------+------+------+
              |  二  |每一頁  7 , 7 , 7 , 8 , 8 , 8 , 8 , 8 , 8 , 8 |  7.7 |  7.7 |
==============+======+==============================================+======+======+========
              |      |第一頁 25,  2 , 3 , 2 , 21, 16, 9 , 20, 9 , 9 |  1.6 |      |
              |  一  +----------------------------------------------+------+  7.5 |
20000條記錄時 |      |其它頁  6 , 6 , 2 , 2 , 4 , 4 , 4 , 1 , 2 , 2 |  3.3 |      | 6.6533
              +------+----------------------------------------------+------+------+
              |  二  |每一頁 54, 50, 37, 46, 49, 47, 52, 50, 55, 59 | 49.9 | 49.9 |
==============+======+==============================================+======+======+========
              |      |第一頁 34, 35, 24, 21, 21, 21, 22, 22, 21, 21 | 25.2 |      |
              |  一  +----------------------------------------------+------+ 25.95|
30000條記錄時 |      |其它頁 14, 27, 40, 39, 37, 33, 22, 30, 14, 11 | 26.7 |      | 3.3372
              +------+----------------------------------------------+------+------+
              |  二  |每一頁 92, 90, 83, 78, 93, 83, 91, 79, 89, 88 | 86.6 | 86.6 |
==============+======+==============================================+======+======+========

相關文章

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。