日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

MySQL高级 - 案例 - 系统性能优化 - 分页优化

發布時間:2024/4/14 数据库 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 MySQL高级 - 案例 - 系统性能优化 - 分页优化 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

優化count

?

創建一張表用來記錄日志表的總數據量:

create table log_counter(logcount bigint not null )engine = innodb default CHARSET = utf8;

在每次插入數據之后,更新該表 :

<update id="updateLogCounter" >update log_counter set logcount = logcount + 1 </update>

在進行分頁查詢時, 獲取總記錄數,從該表中查詢既可。

<select id="countLogFromCounter" resultType="long">select logcount from log_counter limit 1 </select>

優化 limit

在進行分頁時,一般通過創建覆蓋索引,能夠比較好的提高性能。一個非常常見,而又非常頭疼的分頁場景就是 "limit 1000000,10" ,此時MySQL需要搜索出前1000010 條記錄后,僅僅需要返回第 1000001 到 1000010 條記錄,前1000000 記錄會被拋棄,查詢代價非常大。

當點擊比較靠后的頁碼時,就會出現這個問題,查詢效率非常慢。

優化SQL:

select * from operation_log limit 3000000 , 10;

?將上述SQL優化為 :

select * from operation_log t , (select id from operation_log order by id limit 3000000,10) b where t.id = b.id ; <select id="selectListByCondition" parameterType="map" resultType="operationLog">selectid ,operate_class as operateClass ,operate_method as operateMethod,return_class as returnClass,operate_user as operateUser,operate_time as operateTime,param_and_value as paramAndValue,cost_time as costTime,return_value as returnValuefrom operation_log t,(select id from operation_log <where><include refid="oplog_where"/></where>order by id limit #{start},#{rows}) b where t.id = b.id </select>

總結

以上是生活随笔為你收集整理的MySQL高级 - 案例 - 系统性能优化 - 分页优化的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。