Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1300807
  • 博文数量: 127
  • 博客积分: 2286
  • 博客等级: 大尉
  • 技术积分: 1943
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-10 10:37
文章分类

全部博文(127)

文章存档

2018年(1)

2015年(2)

2014年(1)

2013年(30)

2012年(88)

2011年(5)

分类: Mysql/postgreSQL

2012-08-23 15:21:44

sql profile使用的典型5步骤
set profiling=1;
查询


set profiling=0;

show profiles;
show profile for query 1;

今天遇到一个超复杂的语句,sql profile近80万行,怎么看??
只能直接查询,给一些统计信息:


set @query_id = 1;
SELECT SUM(DURATION) into @query_time
FROM INFORMATION_SCHEMA.PROFILING
WHERE QUERY_ID = @query_id;

SELECT STATE, SUM(DURATION) AS Total_R,
ROUND(
100 * SUM(DURATION) /@query_time, 2) AS Pct_R,
COUNT(*) AS Calls,
SUM(DURATION) / COUNT(*) AS "R/Call"
FROM INFORMATION_SCHEMA.PROFILING
WHERE QUERY_ID = @query_id
GROUP BY STATE
ORDER BY Total_R DESC;

+----------------------+-----------+-------+--------+--------------+
| STATE | Total_R | Pct_R | Calls | R/Call |
+----------------------+-----------+-------+--------+--------------+
| Sending data | 10.894872 | 78.96 | 390823 | 0.0000278767 |
| executing | 2.899547 | 21.01 | 390823 | 0.0000074191 |
| statistics | 0.000634 | 0.00 | 8 | 0.0000792500 |
| Opening tables | 0.000554 | 0.00 | 1 | 0.0005540000 |
| Sorting result | 0.000448 | 0.00 | 1 | 0.0004480000 |
| Creating tmp table | 0.000342 | 0.00 | 1 | 0.0003420000 |
| init | 0.000289 | 0.00 | 1 | 0.0002890000 |
| freeing items | 0.000287 | 0.00 | 1 | 0.0002870000 |
| starting | 0.000279 | 0.00 | 1 | 0.0002790000 |
| removing tmp table | 0.000266 | 0.00 | 1 | 0.0002660000 |
| optimizing | 0.000198 | 0.00 | 8 | 0.0000247500 |
| preparing | 0.000189 | 0.00 | 8 | 0.0000236250 |
| Copying to tmp table | 0.000108 | 0.00 | 1 | 0.0001080000 |
| logging slow query | 0.000099 | 0.00 | 2 | 0.0000495000 |
| end | 0.000032 | 0.00 | 2 | 0.0000160000 |
| Table lock | 0.000022 | 0.00 | 1 | 0.0000220000 |
| cleaning up | 0.000018 | 0.00 | 1 | 0.0000180000 |
| System lock | 0.000012 | 0.00 | 1 | 0.0000120000 |
| query end | 0.000010 | 0.00 | 1 | 0.0000100000 |
+----------------------+-----------+-------+--------+--------------+
阅读(2412) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~