使用show profile分析单条查询
来源:互联网 发布:和日本人谈恋爱 知乎 编辑:程序博客网 时间:2024/06/11 14:29
show profile命令是Mysql5.1版本中引入的,默认是禁用的,但可以通过服务器变量在会话级别动态地修改,下面是打开profile:
mysql> set profiling = 1;Query OK, 0 rows affected (0.00 sec)
执行下show profile查看最近执行的查询情况:
mysql> show profiles;+----------+------------+--------------------------+| Query_ID | Duration | Query |+----------+------------+--------------------------+| 1 | 0.00134600 | show tables || 2 | 0.01328775 | select * from AASC || 3 | 0.00020075 | select * from AAASTUDENT || 4 | 0.00029550 | select * from AASTUDENT || 5 | 0.00019100 | select * from AATECHER || 6 | 0.00022300 | select * from AATEACHER |+----------+------------+--------------------------+6 rows in set (0.00 sec)
从上面的结果可以看出,以很高的精度显示了查询时间
细信息查看,按下面的方式执行即可:
mysql> show profile for query 1;+----------------------+----------+| Status | Duration |+----------------------+----------+| starting | 0.000034 || checking permissions | 0.000006 || Opening tables | 0.000012 || System lock | 0.000005 || init | 0.000014 || optimizing | 0.000003 || statistics | 0.000008 || preparing | 0.000005 || executing | 0.000001 || Sending data | 0.000077 || end | 0.000004 || query end | 0.000003 || closing tables | 0.000005 || freeing items | 0.000043 || logging slow query | 0.000003 || cleaning up | 0.000002 |+----------------------+----------+16 rows in set (0.00 sec)
虽然详细,但是很难直接看出性能问题,加入不使用show profile命令,而是直接查询information_schema中对应的表,则可以按需格式化输出:
mysql> set @query_id = 1;Query OK, 0 rows affected (0.00 sec)
SELECT STATE ,sum(duration) AS total_r ,round(100 * sum(duration) / ( SELECT sum(duration) FROM information_schemling WHERE query_id = @query_id ), 2) AS pct_r ,count(*) AS calls ,sum(duration) / count(*) AS "R/Call"FROM information_schema.profilingWHERE query_id = @query_idGROUP BY STATEORDER BY total_r DESC;
+----------------------+----------+-------+-------+--------------+| state | total_r | pct_r | calls | R/Call |+----------------------+----------+-------+-------+--------------+| Sending data | 0.000077 | 34.22 | 1 | 0.0000770000 || freeing items | 0.000043 | 19.11 | 1 | 0.0000430000 || starting | 0.000034 | 15.11 | 1 | 0.0000340000 || init | 0.000014 | 6.22 | 1 | 0.0000140000 || Opening tables | 0.000012 | 5.33 | 1 | 0.0000120000 || statistics | 0.000008 | 3.56 | 1 | 0.0000080000 || checking permissions | 0.000006 | 2.67 | 1 | 0.0000060000 || System lock | 0.000005 | 2.22 | 1 | 0.0000050000 || preparing | 0.000005 | 2.22 | 1 | 0.0000050000 || closing tables | 0.000005 | 2.22 | 1 | 0.0000050000 || end | 0.000004 | 1.78 | 1 | 0.0000040000 || logging slow query | 0.000003 | 1.33 | 1 | 0.0000030000 || query end | 0.000003 | 1.33 | 1 | 0.0000030000 || optimizing | 0.000003 | 1.33 | 1 | 0.0000030000 || cleaning up | 0.000002 | 0.89 | 1 | 0.0000020000 || executing | 0.000001 | 0.44 | 1 | 0.0000010000 |+----------------------+----------+-------+-------+--------------+16 rows in set (0.07 sec)
从上面的查询结果可以看出来,发送数据和释放索引消耗的时间较多,但这属于正常开销,如果以后执行复杂的SQL时,就会很具有分析价值了。
0 0
- 使用show profile分析单条查询
- 单条剖析查询 SHOW PROFILE
- Mysql单条查询性能剖析 show profile
- mysql查询性能分析(show status,show profile,explain)
- MySql 使用SHOW PROFILE 进行SQL 分析
- MySql 使用SHOW PROFILE 进行SQL 分析
- show profile 分析性能
- show profile的使用
- show profile进行sql分析
- Show Profile进行sql分析
- 使用show profiles分析查询语句性能
- show profile sql分析的好工具
- mysql性能分析工具--show profile
- Mysql profile分析查询
- MySQL性能分析语句 show profile/show profiles
- show profile;
- mysql性能分析工具show profile(翻译)
- Medoo Get的使用:查询单条数据
- 总结学习VS2010的dll的创建与调用
- .h、.DLL和.lib关系
- C++ 显式转换
- mybatis基础教程
- Windows下Eclipse和Jcuda 环境搭建使用
- 使用show profile分析单条查询
- 最简单的log4j配置文件
- Django同步数据库不能创建app表
- linux xia shan chu wenjian
- Android开发之ListView实现Item局部刷新
- MyEclipse设置java文件每行字符数
- C++数据结构之图的深度和广度遍历
- Spring中提示元素 'ref' 中不允许出现属性 'local'
- 项目总结