mysql 數據庫 分頁查詢優化

舉個栗子:索引

       表名:batch_big_num  it

       列名:id(主鍵),name,age,product_name,product_num效率

1,利用索引select

(1)加一個order by+索引列   能夠提高必定的效率im

select * from batch_big_num order by id limit 100000,10;查詢

(2)利用子查詢
select n1.* from batch_big_num n1 inner join(
select id from batch_big_num order by id limit 10000000, 20
)n2 using(id)join

 

2,已知區間的的狀況:bat

select * from batch_big_num where id between 10000000 and 10000020;

3,分兩次查詢

第一次 查出結果得到一個條件,好比id: select id from batch_big_num limit 20; 

第二次 根據第一次查詢出的結果查詢:

select * from batch_big_num where id>n limit 20;

相關文章
相關標籤/搜索