1
2
|
#开启profile
set
profiling=1;
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#要查询的SQL
SET
@query_id = 1;
SELECT
#执行步骤
STATE,
#每个步骤总时间
SUM
(DURATION)
AS
Total_R,
#每个步骤占用总时间比例
ROUND(
100 *
SUM
(DURATION) /
(
SELECT
SUM
(DURATION)
FROM
INFORMATION_SCHEMA.PROFILING
WHERE
QUERY_ID = @query_id),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
;
|
1
2
3
4
|
show status
like
"com_insert"
;
show status
like
"com_delete"
;
show status
like
"com_update"
;
show status
like
"com_select"
;
|