您好我正在使用MySQL,
SHOW PROFILES;
返回一个长列表,例如:
|Query_ID|Duration |Query
>| 9 | 0.00028550 | INSERT INTO Duration(Status,DURATION,Query_ID)|
我正在尝试复制这个,所以我可以将结果插入到表中并添加WHERE
子句。
所以我试过这个
SELECT Query_ID, STATE, FORMAT(DURATION, 6) AS DURATION
FROM INFORMATION_SCHEMA.PROFILING
WHERE QUERY_ID = 9;
但是这会返回一个较低级别的视图(我不想要):
开始0.000053开盘0.000088
与以下内容相同:
SHOW PROFILE;
我将如何重新创建SHOW PROFILES
?
所以我可以这样做:
INSERT INTO Duration(Query_ID,Status,DURATION)
SELECT * FROM SHOW PROFILE
WHERE PROFILE.QUERY_ID = 9;
由于
答案 0 :(得分:1)
按QUERY_ID
分组。要获取状态,您需要STATE
SEQ
的记录的DURATION
;要获得持续时间,只需对组中每条记录的INSERT INTO Duration
(Query_ID, Status, DURATION)
SELECT QUERY_ID, STATE, t.DURATION
FROM INFORMATION_SCHEMA.PROFILING JOIN (
SELECT QUERY_ID, MAX(SEQ) AS SEQ, SUM(DURATION) AS DURATION
FROM INFORMATION_SCHEMA.PROFILING
WHERE QUERY_ID = 9
GROUP BY QUERY_ID -- superfluous in the presence of the above filter
) t USING (QUERY_ID, SEQ)
求和:
{{1}}