mysql sql 语句执行分解

MySQL 5.0.37版本加入了MySQL Query Profiler工具。
http://dev.mysql.com/tech-resources/articles/using-new-query-profiler.html

简单的实例
mysql> set profiling=1;
Query OK, 0 rows affected (0.04 sec)

mysql> show profiles;
Empty set (0.00 sec)

mysql> SELECT COUNT(nickname), gender FROM users GROUP BY gender;
+-----------------+--------+
| COUNT(nickname) | gender |
+-----------------+--------+
|          106773 |      0 |
|          106462 |      1 |
+-----------------+--------+
2 rows in set (0.88 sec)

mysql> show profiles;
+----------+------------+-----------------------------------------------------------+
| Query_ID | Duration   | Query                                                     |
+----------+------------+-----------------------------------------------------------+
|        1 | 0.88324700 | SELECT COUNT(nickname), gender FROM users GROUP BY gender |
+----------+------------+-----------------------------------------------------------+
1 row in set (0.03 sec)

mysql> show profile for query 1;
+----------------------+-----------+
| Status               | Duration  |
+----------------------+-----------+
| (initialization)     | 0.0000699 |
| Opening tables       | 0.000039  |
| System lock          | 0.000008  |
| Table lock           | 0.000014  |
| init                 | 0.000043  |
| optimizing           | 0.000396  |
| statistics           | 0.000024  |
| preparing            | 0.000079  |
| Creating tmp table   | 0.000118  |
| executing            | 0.000008  |
| Copying to tmp table | 0.871251  |
| Sorting result       | 0.000063  |
| Sending data         | 0.009601  |
| end                  | 0.000017  |
| removing tmp table   | 0.000028  |
| end                  | 0.000009  |
| query end            | 0.000006  |
| freeing items        | 0.000015  |
| closing tables       | 0.001449  |
| logging slow query   | 0.000009  |
+----------------------+-----------+
20 rows in set (0.02 sec)

mysql> show profile cpu for query 1;
+----------------------+-----------+-----------+------------+
| Status               | Duration  | CPU_user  | CPU_system |
+----------------------+-----------+-----------+------------+
| (initialization)     | 0.0000699 | 0         | 0          |
| Opening tables       | 0.000039  | 0         | 0          |
| System lock          | 0.000008  | 0         | 0          |
| Table lock           | 0.000014  | 0         | 0          |
| init                 | 0.000043  | 0         | 0.001      |
| optimizing           | 0.000396  | 0         | 0          |
| statistics           | 0.000024  | 0         | 0          |
| preparing            | 0.000079  | 0         | 0          |
| Creating tmp table   | 0.000118  | 0         | 0          |
| executing            | 0.000008  | 0         | 0          |
| Copying to tmp table | 0.871251  | 0.59391   | 0.253961   |
| Sorting result       | 0.000063  | 0         | 0          |
| Sending data         | 0.009601  | 0.001     | 0.003      |
| end                  | 0.000017  | 0         | 0          |
| removing tmp table   | 0.000028  | 0         | 0          |
| end                  | 0.000009  | 0         | 0          |
| query end            | 0.000006  | 0         | 0          |
| freeing items        | 0.000015  | 0         | 0          |
| closing tables       | 0.001449  | 0.0009990 | 0.001      |
| logging slow query   | 0.000009  | 0         | 0          |
+----------------------+-----------+-----------+------------+
20 rows in set (0.00 sec)

mysql> set profiling=0;
Query OK, 0 rows affected (0.00 sec)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值