国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

優化SQL的一般步驟

2024-07-21 02:51:28
字體:
來源:轉載
供稿:網友
1,通過show status 命令了解各種SQL的執行頻率    比如Com_select 記錄執行select查詢的操作次數,一次查詢只累加12,定位執行效率較低的SQL語句      1通過慢查詢日志定位,2慢查詢在查詢結束后才記錄,使用show PRocesslist查看3,通過EXPLAIN分析低效SQL的執行計劃    4,通過show  profile 分析SQL(>MySQL5.0.37)    mysql> select @@have_profiling;+------------------+| @@have_profiling |+------------------+| YES              |+------------------+1 row in set (0.00 sec)                 表示支持mysql> select @@profiling;+-------------+| @@profiling | +-------------+|           0 |+-------------+1 row in set (0.00 sec)                默認關閉      可以set profiling=1;開啟mysql> show profiles;+----------+------------+--------------------------------------------+| Query_ID | Duration   | Query                                      |+----------+------------+--------------------------------------------+|        1 | 0.02342575 | select * from br_member where user_id<1000 |+----------+------------+--------------------------------------------+1 row in set (0.00 sec)mysql> show profile for query 1;(這里的1 代表show profiles查出的query_id的值)+----------------------+----------+| Status               | Duration |+----------------------+----------+| starting             | 0.000115 || checking permissions | 0.000013 || Opening tables       | 0.000044 || System lock          | 0.000025 || init                 | 0.000097 || optimizing           | 0.000019 || statistics           | 0.000084 || preparing            | 0.000020 || executing            | 0.000005 || Sending data         | 0.022893 || end                  | 0.000012 || query end            | 0.000006 || closing tables       | 0.000013 || freeing items        | 0.000071 || logging slow query   | 0.000005 || cleaning up          | 0.000004 |+----------------------+----------+16 rows in set (0.00 sec)在獲取到最消耗時間的線程狀態以后,mysql支持進一步選擇all,cpu,block io,context,switch,page faults等明細類型來查看mysql在使用什么資源上耗費了過高的時間,如下選擇查看cpu的消耗時間mysql> show profile cpu for query 1;+----------------------+----------+----------+------------+| Status               | Duration | CPU_user | CPU_system |+----------------------+----------+----------+------------+| starting             | 0.000115 | 0.000000 |   0.000000 || checking permissions | 0.000013 | 0.000000 |   0.000000 || Opening tables       | 0.000044 | 0.000000 |   0.000000 || System lock          | 0.000025 | 0.000000 |   0.000000 || init                 | 0.000097 | 0.000000 |   0.000000 || optimizing           | 0.000019 | 0.000000 |   0.000000 || statistics           | 0.000084 | 0.000000 |   0.000000 || preparing            | 0.000020 | 0.000000 |   0.000000 || executing            | 0.000005 | 0.000000 |   0.000000 || Sending data         | 0.022893 | 0.015600 |   0.000000 || end                  | 0.000012 | 0.000000 |   0.000000 || query end            | 0.000006 | 0.000000 |   0.000000 || closing tables       | 0.000013 | 0.000000 |   0.000000 || freeing items        | 0.000071 | 0.000000 |   0.000000 || logging slow query   | 0.000005 | 0.000000 |   0.000000 || cleaning up          | 0.000004 | 0.000000 |   0.000000 |+----------------------+----------+----------+------------+16 rows in set (0.00 sec)5、通過trace分析優化器如何選擇執行計劃6、確定問題并采取相應的措施

show full processlist 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 文昌市| 乌恰县| 海城市| 榕江县| 霞浦县| 双牌县| 乐陵市| 疏勒县| 宣武区| 镇雄县| 泰顺县| 周宁县| 额尔古纳市| 丹江口市| 盈江县| 博乐市| 天津市| 四会市| 乌拉特前旗| 东港市| 昌都县| 西吉县| 如东县| 梓潼县| 兴安县| 陆良县| 慈溪市| 廊坊市| 深泽县| 兴安盟| 侯马市| 临城县| 曲麻莱县| 宁蒗| 林芝县| 外汇| 沂南县| 饶阳县| 太湖县| 秭归县| 揭阳市|