MYSQL分頁limit速度太慢優化方法

平時工作項目上難免會遇到一些數據量非常大的情況去分頁,上網看了很多資料,整理一下自己的觀點看法。

 

數據量小的時候,我問往往就直接利用limit 直接進行分頁,SQL如下:

 

<pre name="code" class="sql"><span style="color: rgb(68, 68, 68); font-family: Simsun; font-size: 14px; line-height: 26px;">select * from users order by id asc limit </span><span style="color: rgb(68, 68, 68); font-family: Simsun; font-size: 14px; line-height: 26px;">10,10;</span>

 


 


數據量大的時候如下:

 

 

<span style="color: rgb(68, 68, 68); font-family: Simsun; font-size: 14px; line-height: 26px;">select id,name,content from users order by id asc limit 100000,10;</span>

掃描100010行

 

 

 

如果記錄了上次的最大ID,如下

 

<span style="color: rgb(68, 68, 68); font-family: Simsun; font-size: 14px; line-height: 26px;"><span style="color: rgb(68, 68, 68); font-family: Simsun; font-size: 14px; line-height: 26px;">select id,name,content from users where id>100000 order by id asc limit 10;</span></span>

 

掃描10行。

總數據有500萬左右,以下例子

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章