MySQL 8.4 Release Notes
30.4.4.22 The ps_trace_statement_digest() Procedure
对性能_schema中的所有性能指标进行跟踪,以获取特定语句摘要。
如果您在性能_schema的events_statements_summary_by_digest
表中找到感兴趣的语句,指定该语句的DIGEST
列的MD5值,并指定轮询持续时间和间隔。结果是该digest在该时间间隔内的所有统计数据的报告。
该过程还尝试执行EXPLAIN
以获取该digest在该时间间隔内的最长运行示例。这可能会失败,因为性能_schema截断长的SQL_TEXT
值。因此EXPLAIN
失败,因为解析错误。
该过程在执行时禁用二进制日志记录,通过调整会话值以更改sql_log_bin
系统变量。该操作是受限制的,因此该过程需要足够的权限来设置受限制的会话变量。请参阅第7.1.9.1节,“系统变量权限”。
-
in_digest VARCHAR(32)
: 需要分析的语句摘要标识符。 -
in_runtime INT
: 分析的持续时间(以秒为单位)。 -
in_interval DECIMAL(2,2)
: 分析的间隔(可以是小数)秒(以秒为单位)。 -
in_start_fresh BOOLEAN
: 是否截断性能_schema的events_statements_history_long
和events_stages_history_long
表之前开始。 -
in_auto_enable BOOLEAN
: 是否自动启用所需的消费者。
mysql> CALL sys.ps_trace_statement_digest('891ec6860f98ba46d89dd20b0c03652c', 10, 0.1, TRUE, TRUE);
+--------------------+
| SUMMARY STATISTICS |
+--------------------+
| SUMMARY STATISTICS |
+--------------------+
1 row in set (9.11 sec)
+------------+-----------+-----------+-----------+---------------+------------+------------+
| executions | exec_time | lock_time | rows_sent | rows_examined | tmp_tables | full_scans |
+------------+-----------+-----------+-----------+---------------+------------+------------+
| 21 | 4.11 ms | 2.00 ms | 0 | 21 | 0 | 0 |
+------------+-----------+-----------+-----------+---------------+------------+------------+
1 row in set (9.11 sec)
+------------------------------------------+-------+-----------+
| event_name | count | latency |
+------------------------------------------+-------+-----------+
| stage/sql/statistics | 16 | 546.92 us |
| stage/sql/freeing items | 18 | 520.11 us |
| stage/sql/init | 51 | 466.80 us |
...
| stage/sql/cleaning up | 18 | 11.92 us |
| stage/sql/executing | 16 | 6.95 us |
+------------------------------------------+-------+-----------+
17 rows in set (9.12 sec)
+---------------------------+
| LONGEST RUNNING STATEMENT |
+---------------------------+
| LONGEST RUNNING STATEMENT |
+---------------------------+
1 row in set (9.16 sec)
+-----------+-----------+-----------+-----------+---------------+------------+-----------+
| thread_id | exec_time | lock_time | rows_sent | rows_examined | tmp_tables | full_scan |
+-----------+-----------+-----------+-----------+---------------+------------+-----------+
| 166646 | 618.43 us | 1.00 ms | 0 | 1 | 0 | 0 |
+-----------+-----------+-----------+-----------+---------------+------------+-----------+
1 row in set (9.16 sec)
# Truncated for clarity...
+-----------------------------------------------------------------+
| sql_text |
+-----------------------------------------------------------------+
| select hibeventhe0_.id as id1382_, hibeventhe0_.createdTime ... |
+-----------------------------------------------------------------+
1 row in set (9.17 sec)
+------------------------------------------+-----------+
| event_name | latency |
+------------------------------------------+-----------+
| stage/sql/init | 8.61 us |
| stage/sql/init | 331.07 ns |
...
| stage/sql/freeing items | 30.46 us |
| stage/sql/cleaning up | 662.13 ns |
+------------------------------------------+-----------+
18 rows in set (9.23 sec)
+----+-------------+--------------+-------+---------------+-----------+---------+-------------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------------+-------+---------------+-----------+---------+-------------+------+-------+
| 1 | SIMPLE | hibeventhe0_ | const | fixedTime | fixedTime | 775 | const,const | 1 | NULL |
+----+-------------+--------------+-------+---------------+-----------+---------+-------------+------+-------+
1 row in set (9.27 sec)
Query OK, 0 rows affected (9.28 sec)