mysql查詢語句最佳化工具

來源:互聯網
上載者:User

標籤:查詢語句最佳化工具

650) this.width=650;" src="http://s1.51cto.com/wyfs02/M01/8A/7C/wKioL1gyjJygqpqXAAKNg5HRZs4455.png-wh_500x0-wm_3-wmp_4-s_1737671810.png" title="Capture.PNG" alt="wKioL1gyjJygqpqXAAKNg5HRZs4455.png-wh_50" />

把這個profiling功能開啟,可以查看sql查詢語句的整個過程中各種資源的消耗情況。

mysql> show profiles;
+----------+------------+---------------------------------+
| Query_ID | Duration   | Query                           |
+----------+------------+---------------------------------+
|        1 | 0.00049600 | show variables like "profiling" |
|        2 | 0.02267400 | show databases                  |
|        3 | 0.04235200 | SELECT DATABASE()               |
|        4 | 0.00012825 | SELECT DATABASE()               |
|        5 | 0.00025125 | show databases                  |
|        6 | 0.00145125 | show tables                     |
|        7 | 0.04207925 | show tables                     |
|        8 | 0.03485225 | select count(*) from host_item  |
+----------+------------+---------------------------------+


mysql> show profile cpu, block io  for query 8;
+----------------------+----------+----------+------------+--------------+---------------+
| Status               | Duration | CPU_user | CPU_system | Block_ops_in | Block_ops_out |
+----------------------+----------+----------+------------+--------------+---------------+
| starting             | 0.000634 | 0.000000 |   0.000000 |            0 |             0 |
| checking permissions | 0.000013 | 0.000000 |   0.000000 |            0 |             0 |
| Opening tables       | 0.000051 | 0.000000 |   0.000000 |            0 |             0 |
| System lock          | 0.000014 | 0.000000 |   0.000000 |            0 |             0 |
| init                 | 0.000015 | 0.000000 |   0.000000 |            0 |             0 |
| optimizing           | 0.033657 | 0.000000 |   0.000000 |           40 |             0 |
| statistics           | 0.000029 | 0.000000 |   0.000000 |            0 |             0 |
| preparing            | 0.000012 | 0.000000 |   0.000000 |            0 |             0 |
| executing            | 0.000006 | 0.000000 |   0.000000 |            0 |             0 |
| Sending data         | 0.000313 | 0.000000 |   0.000000 |            0 |             0 |
| end                  | 0.000008 | 0.000000 |   0.000000 |            0 |             0 |
| query end            | 0.000008 | 0.000000 |   0.000000 |            0 |             0 |
| closing tables       | 0.000047 | 0.000000 |   0.000000 |            0 |             0 |
| freeing items        | 0.000042 | 0.000000 |   0.000000 |            0 |             0 |
| logging slow query   | 0.000003 | 0.000000 |   0.000000 |            0 |             0 |
| cleaning up          | 0.000003 | 0.000000 |   0.000000 |            0 |             0 |
+----------------------+----------+----------+------------+--------------+---------------


show profile後面可以跟參數:all或者cpu,block io,page faults等。


也可以在information_schema.profiling資料庫表中直接查詢:

select state,sum(duration) as total_r,round(100*sum(duration)/(select sum(duration) from information_schema.profiling where [email protected]_id),2) as pct_r,count(*) as calls,sum(duration)/count(*) as "r/call" from information_schema.profiling where [email protected]_id group by state order by total_r desc;


最後,關閉set profiling=0該功能。



本文出自 “Victor的奮鬥曆程” 部落格,請務必保留此出處http://victor2016.blog.51cto.com/6768693/1875012

mysql查詢語句最佳化工具

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.