tencent cloud

TDSQL Boundless

SLOW_LOG

Unduh
Mode fokus
Ukuran font
Terakhir diperbarui: 2026-07-09 09:40:19

Feature Introduction

SLOW_LOG is a system table that records Slow SQL queries for the columnar read-only analysis instance, and it resides in the system database libra_system. SQL statements whose execution time exceeds the threshold (300 milliseconds by default) are logged to this table. The system retains Slow SQL execution information for the last 7 days by default, and data beyond this retention period is automatically purged.
By querying this table, you can analyze slow SQL queries in the columnar read-only analysis instance to identify performance bottlenecks and abnormal queries.

Use Limits

When a user queries libra_system.slow_log, the system automatically filters out Slow SQL query records generated by internal users (libra@%) and returns only the query information of business users.
System internal SQL (such as for statistics collection or metadata maintenance) is not logged to this table.
Failed SQL queries (those that result in execution errors) are also logged. You can filter them using the succ field.

Slow Query Threshold

The threshold for determining Slow SQL queries is controlled by the system variable libra_slow_log_threshold.
Term
Description
Type
Default Value
Value Range
Unit
libra_slow_log_threshold
Slow SQL query detection threshold
Integer
300
-1 – 9223372036854775807
Milliseconds
Example of modifying the threshold:
SET GLOBAL libra_slow_log_threshold = 500;
Note:
When the value is set to -1, no Slow SQL queries are logged. The change takes effect immediately without requiring a service restart.

SQL Text Length Limit

The maximum length of the SQL text written to the sql column is controlled by the system variable libra_query_log_max_len. SQL text that exceeds this length is truncated.
Term
Description
Type
Default Value
Value Range
Unit
libra_query_log_max_len
Maximum length of slow SQL query text
Integer
4194304
0 – 1073741824
Bytes
The default value is 4,194,304 bytes, which is equivalent to 4 MB.

Query Example

Query all Slow SQL queries:
SELECT * FROM libra_system.slow_log;
Query Slow SQL queries with an execution time greater than 1 second:
SELECT start_time, user, db, duration, sql
FROM libra_system.slow_log
WHERE duration > 1000
ORDER BY duration DESC
LIMIT 10;
Query Slow SQL queries that failed during a specific time period:
SELECT start_time, user, db, sql, duration
FROM libra_system.slow_log
WHERE event_date = '2026-05-13'
AND succ = 0;

Field Description

Field Name
Type
Nullable
Description
event_date
date
NO
Date when the slow SQL query occurred. Partitioned by date to accelerate time-range filtering.
start_time
text
NO
The start time of the SQL execution, in the format YYYY-MM-DD HH:MM:SS.ffff, accurate to 0.1 milliseconds.
tso
bigint(20) unsigned
NO
The transaction timestamp associated with the SQL, which can serve as a globally ordered identifier for queries.
sql
text
NO
The SQL text information. Its maximum length is controlled by the libra_query_log_max_len parameter (default: 4 MB). Text exceeding this limit will be truncated.
duration
bigint(20) unsigned
NO
Execution time of the SQL statement, in milliseconds.
details
text
NO
Detailed information about the SQL execution. This is a reserved field and is currently an empty string.
conn_id
bigint(20) unsigned
NO
Session ID of the client connection.
user
text
NO
Username of the user who executed the SQL, in the format user@host.
db
text
NO
Name of the database where the SQL was executed.
digest
text
NO
The fingerprint of the normalized SQL. SQL statements with the same pattern share the same Digest, which can be used for aggregated analysis.
succ
tinyint(3) unsigned
NO
Whether the SQL execution succeeded. Values: 0 indicates failure, and 1 indicates success.
host
text
NO
Address of the Libra storage node that actually executed the SQL, in the format IP address:Port.
execution_mode
text
NO
Execution mode of the SQL. Values: no_forward, auto_tp, auto_ap, only_tp, only_ap. For details, see the description below.
normalized_sql
text
NO
Parameterized (normalized) SQL text, which can be used for SQL pattern aggregation.

execution_mode Value Description

Value
Description
no_forward
Automatic routing is disabled, and SQL is executed on Libra.
auto_tp
Automatic routing is enabled, and SQL is routed to TDSQL for execution based on cost estimation.
auto_ap
Automatic routing is enabled, and SQL is routed to Libra for execution based on cost estimation.
only_tp
Force route to TDSQL for execution.
only_ap
Force route to Libra for execution.
Note:
event_date is the partition field of this table, sorted by tso. When querying, prioritize using event_date as a filter condition to significantly improve query performance.

Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan