SetProfiling

在最新版的mysql,5.0.37中加入了一个新的变量:profiling。可以用来查看query执行的细节,方便优化。

使用的方法很简单。

mysql>set profiling=1;
这样会生成一个information_schema.profiling内存表,此表会一直保存到会话结束。之后所有执行的查询都会再此表中记录一些信息。
mysql>select country.name, count(*) as city_num from city, country where city.CountryCode = country.Code group by country.Code;
mysql>set profiling=0;
mysq>show profiles;

+----------+------------+--------------------------------------------------------------------------------------------------------------------------------------------+
| Query_ID | Duration   | Query                                                                                                                                      |
+----------+------------+--------------------------------------------------------------------------------------------------------------------------------------------+
|        0 | 0.00015500 | set profiling=1                                                                                                                            |
|        1 | 0.00463800 | select country.name, count(*) as city_num from city, country where city.CountryCode = country.Code group by country.Code                   |
|        2 | 0.00003100 | set profiling=0                                                                                                                            |
+----------+------------+--------------------------------------------------------------------------------------------------------------------------------------------+
mysql>show profile for query 1;
+--------------------------------+------------+
| Status                         | Duration   |
+--------------------------------+------------+
| checking query cache for query | 0.00000400 |
| Opening tables                 | 0.00007800 |
| System lock                    | 0.00001000 |
| Table lock                     | 0.00000600 |
| init                           | 0.00001800 |
| optimizing                     | 0.00001900 |
| statistics                     | 0.00001600 |
| preparing                      | 0.00002700 |
| Creating tmp table             | 0.00001100 |
| executing                      | 0.00002700 |
| Copying to tmp table           | 0.00000300 |
| Sorting result                 | 0.00403900 |
| Sending data                   | 0.00009700 |
| end                            | 0.00023500 |
| removing tmp table             | 0.00000400 |
| end                            | 0.00001900 |
| query end                      | 0.00000300 |
| storing result in query cache  | 0.00000300 |
| freeing items                  | 0.00000400 |
| closing tables                 | 0.00000700 |
| logging slow query             | 0.00000500 |
| cleaning up                    | 0.00000300 |
+--------------------------------+------------+
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值