來源:http://www.wenlingnet.com/index.php/198/
---------------------------------------------------------------------
當一個表數據有幾百萬的數據時,分頁的時候成了問題
如 select * from table limit 0,10 這個沒有問題 當 limit 200000,10 的時候數據讀取就很慢,可以按照一下方法解決
總數據有500萬左右
以下例子 當時候 select * from wl_tagindex where byname=’f’ order by id limit 300000,10 執行時間是 3.21s
優化后:
select * from ( select id from wl_tagindex where byname='f' order by id limit 300000,10 ) a left join wl_tagindex b on a.id=b.id
執行時間為 0.11s 速度明顯提升
這里需要說明的是 我這里用到的字段是 byname ,id 需要把這兩個字段做復合索引,否則的話效果提升不明顯
具體參考:
http://explainextended.com/2009/10/23/mysql-order-by-limit-performance-late-row-lookups/
http://www.linuxso.com/sql/19286.html