MySQL5.0版本之后开放了profiling功能,通过此功能可以查询某个SQL的详细执行计划。
1、开启profiling
mysql> show variables like '%profil%';
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| have_profiling | YES |
| profiling | ON |
| profiling_history_size | 15 |
+------------------------+-------+
2、执行SQL,进行测试
mysql> select * from xcredit.tb_sync_job_bak;
3、查看profiles
mysql> show profiles;
+----------+------------+------------------------------------------------------------------------------+
| Query_ID | Duration | Query |
+----------+------------+------------------------------------------------------------------------------+
| 1 | 0.00009600 | set global profiling=1 |
| 2 | 0.00218100 | show variables like '%profil%' |
| 3 | 0.04091100 | select * from xcredit.tb_sync_job_bak where lid<1000 group by lid limit 5000 |
| 4 | 0.00019800 | select * from xcredit.tb_sync_job_bak where lid<1000 group by lid |
| 5 | 0.16355550 | select * from xcredit.tb_sync_job_bak where lid<1000 |
| 6 | 0.00230025 | show variables like '%profil%' |
| 7 | 0.00014375 | select * from xcredit.tb_sync_job_bak group by lid%20 order by lid |
| 8 | 0.00013600 | select * from xcredit.tb_sync_job_bak group by lid%20 order by 1 |
| 9 | 0.00013375 | select * from xcredit.tb_sync_job_bak group by lid%20 |
| 10 | 0.26594500 | select * from xcredit.tb_sync_job_bak |
+----------+------------+------------------------------------------------------------------------------+
4、查看执行计划
mysql> show profile for query 10;
+----------------------+----------+
| Status | Duration |
+----------------------+----------+
| starting | 0.000053 |
| checking permissions | 0.000005 |
| Opening tables | 0.000014 |
| init | 0.000014 |
| System lock | 0.000006 |
| optimizing | 0.000003 |
| statistics | 0.000010 |
| preparing | 0.000009 |
| executing | 0.000001 |
| Sending data | 0.265498 |
| end | 0.000009 |
| query end | 0.000010 |
| closing tables | 0.000008 |
| freeing items | 0.000258 |
| logging slow query | 0.000036 |
| cleaning up | 0.000011 |
+----------------------+----------+
此查询返回八万多行数据,返回数据量较大,因此出现sending data。
MySQL之profiling
原创
©著作权归作者所有:来自51CTO博客作者那海蓝蓝的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:MySQL杀会话常用方法
下一篇:观察MySQL进程状态
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
MySQL及MySQL Workbench下载与安装
安装MySQLworkbench以及环境配置的详细教程
mysql MySQL MySQLworkbench -
Elastic Universal Profiling
Universal Profiling 是Es提供的一种分析工具,可以根据官方描述,它基本上对业务是零侵入,运行成本极低的一个工具。
大数据 Universal Elastic 应用程序