tencent cloud

TDSQL Boundless

EVENTS_STATEMENTS_SUMMARY_BY_DIGEST

Download
포커스 모드
폰트 크기
마지막 업데이트 시간: 2026-07-13 17:06:58
The PERFORMANCE_SCHEMA.EVENTS_STATEMENTS_SUMMARY_BY_DIGEST table is used to aggregate and display SQL statement execution statistics by statement digest (DIGEST), enabling users to analyze the execution frequency, latency distribution, resource consumption, and distributed execution characteristics of various SQL statements in TDSQL Boundless clusters.

Function

The events_statements_summary_by_digest table aggregates all SQL statements by the unique key (SCHEMA_NAME, DIGEST). Each row represents the cumulative execution statistics for a specific SQL template, which is a statement fingerprint formed after parameter normalization. The main features of this table are as follows:
It provides basic metrics such as SQL execution frequency, cumulative/minimum/average/maximum latency, lock wait, and error and alarm counts.
It provides execution characteristic metrics such as scanned rows, temporary table creation, full table scans, and sorting operations, which are used to identify inefficient SQL.
It provides three latency percentiles, P95, P99, and P999, for evaluating the tail latency of SQL execution.
The SUM_DISTRIBUTED field is provided to count the number of times such SQL statements are executed in a distributed manner (where a single SQL statement accesses multiple Replication Groups), thereby demonstrating the distributed execution feature of TDSQL Boundless.
It provides a query sample (QUERY_SAMPLE_TEXT), along with its collection timestamp and latency, to facilitate viewing the actual text of representative SQL statements.
Note:
Users can query this table without needing to set the performance_schema system variable to ON. You can clear the statistical data by executing TRUNCATE TABLE performance_schema.events_statements_summary_by_digest.

Field Description

Field Name
Type
Description
SCHEMA_NAME
varchar(64)
Name of the database to which the statement belongs. If the statement does not specify a database name, the value is NULL.
DIGEST
varchar(64)
Hash value of the SQL statement digest, which is the unique identifier for the same statement template.
DIGEST_TEXT
longtext
Normalized SQL statement template text, where constant values are replaced with ?.
COUNT_STAR
bigint unsigned
Total number of executions for the SQL template.
SUM_TIMER_WAIT
bigint unsigned
Total execution time for the SQL template, measured in picoseconds (ps).
MIN_TIMER_WAIT
bigint unsigned
Minimum single-execution time for the SQL template, measured in picoseconds.
AVG_TIMER_WAIT
bigint unsigned
Average single-execution time for the SQL template, measured in picoseconds.
MAX_TIMER_WAIT
bigint unsigned
Maximum single-execution time for the SQL template, measured in picoseconds.
SUM_LOCK_TIME
bigint unsigned
Total lock wait time for the SQL template, measured in picoseconds.
SUM_ERRORS
bigint unsigned
Total number of failed executions for the SQL template.
SUM_WARNINGS
bigint unsigned
Total number of alarms generated by the SQL template.
SUM_ROWS_AFFECTED
bigint unsigned
Total number of rows affected by the SQL template (INSERT, UPDATE, DELETE, and so on).
SUM_ROWS_SENT
bigint unsigned
Total number of rows returned to the client by the SQL template.
SUM_ROWS_EXAMINED
bigint unsigned
Total number of rows scanned by the SQL template.
SUM_CREATED_TMP_DISK_TABLES
bigint unsigned
Total number of on-disk temporary tables created by the SQL template.
SUM_CREATED_TMP_TABLES
bigint unsigned
Total number of temporary tables (including in-memory temporary tables) created by the SQL template.
SUM_SELECT_FULL_JOIN
bigint unsigned
Total number of full table joins triggered due to no index being used by the SQL template.
SUM_SELECT_FULL_RANGE_JOIN
bigint unsigned
Total number of full range joins (range search) triggered by the SQL template.
SUM_SELECT_RANGE
bigint unsigned
Total number of times range scans were used on the first table by the SQL template.
SUM_SELECT_RANGE_CHECK
bigint unsigned
Total number of row-by-row range checks triggered by the SQL template, which usually indicates poor index selection for JOIN operations.
SUM_SELECT_SCAN
bigint unsigned
Total number of full table scans performed on the first table by the SQL template.
SUM_SORT_MERGE_PASSES
bigint unsigned
Total number of merge passes for sorting operations performed by the SQL template.
SUM_SORT_RANGE
bigint unsigned
Total number of sorting operations performed based on range scans by the SQL template.
SUM_SORT_ROWS
bigint unsigned
Total number of rows involved in sorting operations by the SQL template.
SUM_SORT_SCAN
bigint unsigned
Total number of sorting operations performed based on full table scans by the SQL template.
SUM_NO_INDEX_USED
bigint unsigned
Total number of executions where no index was used by the SQL template.
SUM_NO_GOOD_INDEX_USED
bigint unsigned
Total number of executions where no index was used because the optimizer deemed no suitable index was available, for the SQL template.
SUM_DISTRIBUTED
bigint unsigned
Total number of executions performed in distributed mode for the SQL template. An execution is counted as 1 if it involves modifying more than one Replication Group; otherwise, it is counted as 0. This field is a self-developed field of TDSQL Boundless.
FIRST_SEEN
timestamp(6)
Timestamp when the SQL template was first recorded.
LAST_SEEN
timestamp(6)
Timestamp when the SQL template was last recorded.
QUANTILE_95
bigint unsigned
P95 quantile of execution time for the SQL template, measured in picoseconds.
QUANTILE_99
bigint unsigned
P99 quantile of execution time for the SQL template, measured in picoseconds.
QUANTILE_999
bigint unsigned
P999 quantile of execution time for the SQL template, measured in picoseconds.
QUERY_SAMPLE_TEXT
longtext
Representative raw SQL statement text for the template (with parameter values preserved), which can be used to reproduce the execution.
QUERY_SAMPLE_SEEN
timestamp(6)
Timestamp when QUERY_SAMPLE_TEXT was collected.
QUERY_SAMPLE_TIMER_WAIT
bigint unsigned
Execution time of the specific run when QUERY_SAMPLE_TEXT was collected, measured in picoseconds.
Note:
All time-related fields in the table (*_TIMER_WAIT, SUM_LOCK_TIME, QUANTILE_*, QUERY_SAMPLE_TIMER_WAIT) are measured in picoseconds, where 1 second equals 1,000,000,000,000 picoseconds.

Examples

Example 1: Querying SQL Execution Statistics Overview

Query the top 10 SQL templates with the highest number of executions in the current instance:
SELECT SCHEMA_NAME, DIGEST_TEXT, COUNT_STAR,
SUM_TIMER_WAIT / 1000000000 AS SUM_TIMER_MS,
AVG_TIMER_WAIT / 1000000000 AS AVG_TIMER_MS
FROM performance_schema.events_statements_summary_by_digest
ORDER BY COUNT_STAR DESC
LIMIT 10;

Example 2: Viewing Tail Latency of SQL Execution

Query SQL templates with a P99 latency greater than 100 ms to locate slow queries:
SELECT SCHEMA_NAME, DIGEST_TEXT, COUNT_STAR,
QUANTILE_95 / 1000000000 AS P95_MS,
QUANTILE_99 / 1000000000 AS P99_MS,
QUANTILE_999 / 1000000000 AS P999_MS
FROM performance_schema.events_statements_summary_by_digest
WHERE QUANTILE_99 > 100000000000
ORDER BY QUANTILE_99 DESC;

Example 3: Identifying Inefficient SQL

Query SQL templates that perform full table scans or do not use indexes:
SELECT SCHEMA_NAME, DIGEST_TEXT, COUNT_STAR,
SUM_NO_INDEX_USED, SUM_SELECT_SCAN, SUM_ROWS_EXAMINED
FROM performance_schema.events_statements_summary_by_digest
WHERE SUM_NO_INDEX_USED > 0 OR SUM_SELECT_SCAN > 0
ORDER BY SUM_ROWS_EXAMINED DESC;

Example 4: Viewing Distributed Execution Statistics

The SUM_DISTRIBUTED field counts the number of times SQL statements are executed in a distributed manner (involving more than one participating node). The following section demonstrates its behavior through a specific scenario:
CREATE DATABASE db;
CREATE TABLE db.t1 (a INT PRIMARY KEY, b VARCHAR(30));
CREATE TABLE db.t2 (a INT PRIMARY KEY, b VARCHAR(30));

-- Distribute t1 and t2 to different replication groups.
USE performance_schema;
TRUNCATE TABLE events_statements_summary_by_digest;

USE db;
INSERT INTO t1 VALUES (111, 222);
INSERT INTO t2 VALUES (111, 222);
UPDATE t1, t2 SET t1.b = 333, t2.b = 333 WHERE t1.a = 111 AND t2.a = 111;

SELECT DIGEST_TEXT, COUNT_STAR, SUM_DISTRIBUTED
FROM performance_schema.events_statements_summary_by_digest
WHERE SCHEMA_NAME = 'db';
Output results:
DIGEST_TEXT COUNT_STAR SUM_DISTRIBUTED
INSERT INTO `t1` VALUES (...) 1 0
INSERT INTO `t2` VALUES (...) 1 0
UPDATE `t1` , `t2` SET `t1` . `b` = ? , `t2` . `b` = ? WHERE `t1` . `a` = ? AND `t2` . `a` = ? 1 1
Result description:
The SUM_DISTRIBUTED field is 0 because both INSERT statements access only a single table and each statement involves only one participating node.
The SUM_DISTRIBUTED field is 1 because the UPDATE statement simultaneously updates t1 and t4, which reside in different replication groups, involving more than one participating node.

Example 5: Viewing Representative SQL Text

Query the most recent representative execution text and latency for a specific SQL template:
SELECT DIGEST, DIGEST_TEXT, QUERY_SAMPLE_TEXT,
QUERY_SAMPLE_SEEN,
QUERY_SAMPLE_TIMER_WAIT / 1000000000 AS SAMPLE_TIMER_MS
FROM performance_schema.events_statements_summary_by_digest
WHERE DIGEST = '<specified DIGEST value>'\\G

Example 6: Clearing Statistics

To reset statistical data (for example, before a performance stress test), execute the following:
TRUNCATE TABLE performance_schema.events_statements_summary_by_digest;

도움말 및 지원

문제 해결에 도움이 되었나요?

피드백