mysql 大資料分頁查詢

2021-09-30 16:40:24 字數 860 閱讀 5431

1. 測試 limit start, count 分頁語句

select * from product limit 10, 20 0.016秒

select * from product limit 100, 20 0.016秒

select * from product limit 1000, 20 0.047秒

select * from product limit 10000, 20 0.094秒

select * from product limit 400000, 20 3.229秒

select * from product limit 866613, 20 37.44秒

2. limit分頁效能優化

select * from product where id >= (select id from product limit 866613, 1) limit 20; 0.2秒

另一種寫法

select * from product a join (select id from product limit 866613, 20) b on a.id = b.id; 查詢時間也很短

3. 復合索引優化方法

資料表collect (id, title, info, vtype),vtype新增索引。

select id from collect where vtype=1 limit 90000,10; 8-9秒

新增復合索引(vtype,id),where第一位,主鍵第2位。

select id from collect where vtype=1 limit 90000,10; 0.04秒

mysql大資料量分頁查詢優化

參考文章 mysql的分頁查詢十分簡單,但是當資料量大的時候一般的分頁就吃不消了。傳統分頁查詢 select c1,c2,cn from table limit n,m mysql的limit工作原理就是先讀取前面n條記錄,然後拋棄前n條,讀後面m條想要的,所以n越大,偏移量越大,效能就越差。1 盡...

mysql大資料量分頁查詢優化

參考文章 mysql的分頁查詢十分簡單,但是當資料量大的時候一般的分頁就吃不消了。傳統分頁查詢 select c1,c2,cn from table limit n,m mysql的limit工作原理就是先讀取前面n條記錄,然後拋棄前n條,讀後面m條想要的,所以n越大,偏移量越大,效能就越差。1 盡...

mysql大資料量分頁查詢優化總結

mysql的分頁查詢十分簡單,但是當資料量大的時候一般的分頁就吃不消了。傳統分頁查詢 select c1,c2,cn from table limit n,m mysql的limit工作原理就是先讀取前面n條記錄,然後拋棄前n條,讀後面m條想要的,所以n越大,偏移量越大,效能就越差。1 limit語...