使用Profiles分析SQL語句執行時間和消耗資源,profilessql

來源:互聯網
上載者:User

使用Profiles分析SQL語句執行時間和消耗資源,profilessql

開啟profiling,預設是沒開啟的.

mysql> set profiling=1;

執行要分析的SQL語句

mysql> select count(1) from wechat_employee,Employee;

顯示profiles表

mysql> show profiles;

查詢結果:

+----------+------------+-----------------------------------------------+| Query_ID | Duration   | Query                                         |+----------+------------+-----------------------------------------------+|        1 | 0.00072975 | select count(1) from wechat_employee,Employee ||        2 | 0.00028450 | set profiling=1                               ||        3 | 0.00324875 | select count(1) from wechat_employee,Employee |+----------+------------+-----------------------------------------------+

查詢詳細資料:

show profile cpu,block io for query 3;

結果:

+--------------------------------+----------+----------+------------+--------------+---------------+| Status                         | Duration | CPU_user | CPU_system | Block_ops_in | Block_ops_out |+--------------------------------+----------+----------+------------+--------------+---------------+| starting                       | 0.000041 | 0.000000 |   0.000000 |            0 |             0 || Waiting for query cache lock   | 0.000073 | 0.000000 |   0.000000 |            0 |             0 || checking query cache for query | 0.000025 | 0.000000 |   0.000000 |            0 |             0 || checking privileges on cached  | 0.000023 | 0.000000 |   0.000000 |            0 |             0 || checking permissions           | 0.000018 | 0.000000 |   0.000000 |            0 |             0 || checking permissions           | 0.000012 | 0.000000 |   0.000000 |            0 |             0 || sending cached result to clien | 0.003009 | 0.000000 |   0.004000 |            0 |             0 || logging slow query             | 0.000032 | 0.000000 |   0.000000 |            0 |             0 || cleaning up                    | 0.000018 | 0.000000 |   0.000000 |            0 |             0 |+--------------------------------+----------+----------+------------+--------------+---------------+9 rows in set (0.00 sec)

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

相關文章

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.