MySQL中如何使用profile分析SQL執行狀態

來源:互聯網
上載者:User

開啟profile

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)

mysql> set session profiling=1;

Query OK, 0 rows affected (0.00 sec)

mysql> select @@profiling;

+-------------+

| @@profiling |

+-------------+

|           1 |

+-------------+

1 row in set (0.00 sec)

使用profile分析SQL,可以看到執行兩次後,Send data和sending cached result to clien執行效率的變化

mysql> select count(*) from sakila.payment;

+----------+

| count(*) |

+----------+

|    16049 |

+----------+

1 row in set (0.03 sec)

mysql> show profiles;

+----------+------------+-------------------------------------+

| Query_ID | Duration   | Query                               |

+----------+------------+-------------------------------------+

|        1 | 0.00020400 | select @@profiling                  |

|        2 | 0.00008900 | select count(*) from payment        |

|        3 | 0.00006800 | show databaes                       |

|        4 | 0.02102800 | show databases                      |

|        5 | 0.02847600 | select count(*) from sakila.payment |

本欄目更多精彩內容:http://www.bianceng.cn/database/MySQL/

+----------+------------+-------------------------------------+

5 rows in set (0.00 sec)

mysql> show profile for query 5;

+--------------------------------+----------+

| Status                         | Duration |

+--------------------------------+----------+

| starting                       | 0.000030 |

| Waiting for query cache lock   | 0.000005 |

| checking query cache for query | 0.000043 |

| checking permissions           | 0.000007 |

| Opening tables                 | 0.000027 |

| System lock                    | 0.000010 |

| Waiting for query cache lock   | 0.000010 |

| init                           | 0.000000 |

| optimizing                     | 0.023255 |

| statistics                     | 0.000118 |

| preparing                      | 0.000041 |

| executing                      | 0.000033 |

| Sending data                   | 0.003833 |

| end                            | 0.000054 |

| query end                      | 0.000045 |

| closing tables                 | 0.000045 |

| freeing items                  | 0.000072 |

| Waiting for query cache lock   | 0.000033 |

| freeing items                  | 0.000785 |

| Waiting for query cache lock   | 0.000016 |

| freeing items                  | 0.000002 |

| storing result in query cache  | 0.000005 |

| logging slow query             | 0.000003 |

| cleaning up                    | 0.000004 |

+--------------------------------+----------+

24 rows in set (0.00 sec)

mysql> select count(*) from sakila.payment;

+----------+

| count(*) |

+----------+

|    16049 |

+----------+

1 row in set (0.00 sec)

mysql> show profiles;

+----------+------------+-------------------------------------+

| Query_ID | Duration   | Query                               |

+----------+------------+-------------------------------------+

|        1 | 0.00020400 | select @@profiling                  |

|        2 | 0.00008900 | select count(*) from payment        |

|        3 | 0.00006800 | show databaes                       |

|        4 | 0.02102800 | show databases                      |

|        5 | 0.02847600 | select count(*) from sakila.payment |

|        6 | 0.00006900 | select count(*) from sakila.payment |

+----------+------------+-------------------------------------+

6 rows in set (0.00 sec)

mysql> show profile for query 6;

+--------------------------------+----------+

| Status                         | Duration |

+--------------------------------+----------+

| starting                       | 0.000029 |

| Waiting for query cache lock   | 0.000004 |

| checking query cache for query | 0.000007 |

| checking privileges on cached  | 0.000004 |

| checking permissions           | 0.000008 |

| sending cached result to clien | 0.000012 |

| logging slow query             | 0.000002 |

| cleaning up                    | 0.000003 |

+--------------------------------+----------+

8 rows in set (0.00 sec)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.