表結構 xxxx(id,title,content,url,status) id為主鍵,自動遞增
普通分頁
select * from xxxx where status = 1 limit 1000,100;
這樣查詢在資料量比較小,同時查詢前面的資料的時候是很快的.但是如果表的數量持續增大(這裡的測試資料有589530條資料),同時需要查詢後面分頁的資料,如:
select * from xxxx where status = 1 limit 235500,500;
執行上面這條語句,就會很慢. 這裡測試結果是 8-9s的樣子
優化分頁
利用id主鍵,如下:
select * from xxxx where id >=(select id from xxxx where status=1 limit 235500,1) and status = 1 limit 500;
上面這條語句的執行結果是 0.24s
效率一下提升40多倍