這篇文章將為大家詳細講解有關MySQL中profiling有什么用,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
MySQL5.0版本之后開放了profiling功能,通過此功能可以查詢某個SQL的詳細執行計劃。
1、開啟profiling
mysql> show variables like '%profil%';
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| have_profiling | YES |
| profiling | ON |
| profiling_history_size | 15 |
+------------------------+-------+
2、執行SQL,進行測試
mysql> select * from xcredit.tb_sync_job_bak;
3、查看profiles
mysql> show profiles;
+----------+------------+------------------------------------------------------------------------------+
| Query_ID | Duration | Query |
+----------+------------+------------------------------------------------------------------------------+
| 1 | 0.00009600 | set global profiling=1 |
| 2 | 0.00218100 | show variables like '%profil%' |
| 3 | 0.04091100 | select * from xcredit.tb_sync_job_bak where lid<1000 group by lid limit 5000 |
| 4 | 0.00019800 | select * from xcredit.tb_sync_job_bak where lid<1000 group by lid |
| 5 | 0.16355550 | select * from xcredit.tb_sync_job_bak where lid<1000 |
| 6 | 0.00230025 | show variables like '%profil%' |
| 7 | 0.00014375 | select * from xcredit.tb_sync_job_bak group by lid%20 order by lid |
| 8 | 0.00013600 | select * from xcredit.tb_sync_job_bak group by lid%20 order by 1 |
| 9 | 0.00013375 | select * from xcredit.tb_sync_job_bak group by lid%20 |
| 10 | 0.26594500 | select * from xcredit.tb_sync_job_bak |
+----------+------------+------------------------------------------------------------------------------+
4、查看執行計劃
mysql> show profile for query 10;
+----------------------+----------+
| Status | Duration |
+----------------------+----------+
| starting | 0.000053 |
| checking permissions | 0.000005 |
| Opening tables | 0.000014 |
| init | 0.000014 |
| System lock | 0.000006 |
| optimizing | 0.000003 |
| statistics | 0.000010 |
| preparing | 0.000009 |
| executing | 0.000001 |
| Sending data | 0.265498 |
| end | 0.000009 |
| query end | 0.000010 |
| closing tables | 0.000008 |
| freeing items | 0.000258 |
| logging slow query | 0.000036 |
| cleaning up | 0.000011 |
+----------------------+----------+
此查詢返回八萬多行數據,返回數據量較大,因此出現sending data。
關于“MySQL中profiling有什么用”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。