From 84244bc85a29dfab78858539713a1ef3a4bb5bb7 Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Tue, 15 Sep 2026 17:41:59 +0800 Subject: [PATCH] This is an automated cherry-pick of #23767 Signed-off-by: ti-chi-bot --- TOC-tidb-cloud-essential.md | 1 + TOC-tidb-cloud-premium.md | 5 + TOC.md | 1 + config-slow-query-trigger-rules.md | 195 +++++++++++++++++++++++++++++ identify-slow-queries.md | 10 ++ releases/release-8.5.6.md | 6 +- system-variables.md | 40 +++++- tidb-cloud/tune-performance.md | 8 ++ 8 files changed, 261 insertions(+), 5 deletions(-) create mode 100644 config-slow-query-trigger-rules.md diff --git a/TOC-tidb-cloud-essential.md b/TOC-tidb-cloud-essential.md index af55ca425a2e3..e85c87d686d6d 100644 --- a/TOC-tidb-cloud-essential.md +++ b/TOC-tidb-cloud-essential.md @@ -551,6 +551,7 @@ - [Server Status Variables](/status-variables.md) - [Table Filter](/table-filter.md) - [URI Formats of External Storage Services](/external-storage-uri.md) + - [Configure Trigger Rules for Slow Queries](/config-slow-query-trigger-rules.md) - [Troubleshoot Inconsistency Between Data and Indexes](/troubleshoot-data-inconsistency-errors.md) - [Notifications](/tidb-cloud/notifications.md) - [Project API Migration Guide for {{{ .starter }}} and Essential](/tidb-cloud/tidbx-starter-essential-project-api-migration-guide.md) diff --git a/TOC-tidb-cloud-premium.md b/TOC-tidb-cloud-premium.md index e552f51611e89..3244e17d37581 100644 --- a/TOC-tidb-cloud-premium.md +++ b/TOC-tidb-cloud-premium.md @@ -561,6 +561,11 @@ - [Server Status Variables](/status-variables.md) - [Table Filter](/table-filter.md) - [URI Formats of External Storage Services](/external-storage-uri.md) +<<<<<<< HEAD +======= + - [`ANALYZE` Embedded in DDL Statements](/ddl_embedded_analyze.md) + - [Configure Trigger Rules for Slow Queries](/config-slow-query-trigger-rules.md) +>>>>>>> 8876be1aaa (docs: add a guide for configuring slow query trigger rules (#23767)) - [Troubleshoot Inconsistency Between Data and Indexes](/troubleshoot-data-inconsistency-errors.md) - [Notifications](/tidb-cloud/notifications.md) - Support Plan diff --git a/TOC.md b/TOC.md index d440ed29e3a8d..ba56a8609a4e1 100644 --- a/TOC.md +++ b/TOC.md @@ -213,6 +213,7 @@ - Issue Scenarios - Slow Queries - [Identify Slow Queries](/identify-slow-queries.md) + - [Configure Trigger Rules for Slow Queries](/config-slow-query-trigger-rules.md) - [Analyze Slow Queries](/analyze-slow-queries.md) - [TiDB OOM](/troubleshoot-tidb-oom.md) - [Hotspot](/troubleshoot-hot-spot-issues.md) diff --git a/config-slow-query-trigger-rules.md b/config-slow-query-trigger-rules.md new file mode 100644 index 0000000000000..b40d4ce86db7b --- /dev/null +++ b/config-slow-query-trigger-rules.md @@ -0,0 +1,195 @@ +--- +title: Configure Trigger Rules for Slow Queries +summary: Define the trigger rules for slow query logs. +--- + +# Configure Trigger Rules for Slow Queries + + + +This document describes how to use the [`tidb_slow_log_rules`](/system-variables.md#tidb_slow_log_rules) system variable to define the trigger rules for [slow query logs](/identify-slow-queries.md). + +[`tidb_slow_log_rules`](/system-variables.md#tidb_slow_log_rules) supports multi-dimensional metric combinations. It is suitable for "targeted sampling" and "problem reproduction" of slow query logs, enabling you to filter target statements based on specific metric combinations. + +For TiDB Self-Managed, the triggering behavior of slow query logs depends on the configuration of `tidb_slow_log_rules`: + +- If the current session has no applicable `tidb_slow_log_rules` rule (either because this variable is not set or because none of the configured rules apply to the session), slow query logging still relies on [`tidb_slow_log_threshold`](/system-variables.md#tidb_slow_log_threshold) (in milliseconds). +- If the current session has any applicable `tidb_slow_log_rules` rules, slow query logging is determined by the rule matching results, and [`tidb_slow_log_threshold`](/system-variables.md#tidb_slow_log_threshold) is ignored. + + + + +In the [TiDB Cloud console](https://tidbcloud.com/), you can view slow queries on the [**Slow Query**](/tidb-cloud/tune-performance.md#slow-query) tab of the [**Diagnosis**](/tidb-cloud/tune-performance.md#view-the-diagnosis-page) page. + +By default, SQL queries that take more than 300 milliseconds are considered as slow queries. To configure the trigger rules for slow queries, you can modify the [`tidb_slow_log_rules`](/system-variables.md#tidb_slow_log_rules) system variable. + +[`tidb_slow_log_rules`](/system-variables.md#tidb_slow_log_rules) supports multi-dimensional metric combinations. It is suitable for "targeted sampling" and "problem reproduction" of slow queries, enabling you to filter target statements based on specific metric combinations. + + + +## Examples + +- Standard format (`SESSION` scope): + + ```sql + SET SESSION tidb_slow_log_rules = 'Query_time: 0.5, Is_internal: false'; + ``` + +- Invalid `SESSION` rule (`SESSION` scope does not support `Conn_ID`): + + ```sql + SET SESSION tidb_slow_log_rules = 'Conn_ID: 12, Query_time: 0.5, Is_internal: false'; + ``` + + + +- Global rule (applies to all connections): + + ```sql + SET GLOBAL tidb_slow_log_rules = 'Query_time: 0.5, Is_internal: false'; + ``` + +- Global rules for specific connections (applied separately to the two connections `Conn_ID:11` and `Conn_ID:12`): + + ```sql + SET GLOBAL tidb_slow_log_rules = 'Conn_ID: 11, Query_time: 0.5, Is_internal: false; Conn_ID: 12, Query_time: 0.6, Process_time: 0.3, DB: db1'; + ``` + + + + + +- Global rule (applies to all connections): + + ```sql + SET GLOBAL tidb_slow_log_rules = 'Query_time: 0.5, Is_internal: false'; + ``` + +- Global rules for specific connections (applied separately to the two connections `Conn_ID:11` and `Conn_ID:12`): + + ```sql + SET GLOBAL tidb_slow_log_rules = 'Conn_ID: 11, Query_time: 0.5, Is_internal: false; Conn_ID: 12, Query_time: 0.6, Process_time: 0.3, DB: db1'; + ``` + + + +## Unified rule syntax and type constraints + +- Rule capacity and separation: each supported scope can contain a maximum of 10 rules. Rules are separated by `;`. +- Condition format: each condition uses the format `field_name:value`. Multiple conditions within a single rule are separated by `,`. +- Field names are case-insensitive. Underscores and other characters in field names are preserved. + + + +TiDB Self-Managed supports both `SESSION` and `GLOBAL` rules for `tidb_slow_log_rules`. A single session can have up to 20 active rules across the two scopes. `SESSION` rules do not support `Conn_ID`; only `GLOBAL` rules support this field. + + + + + +TiDB Cloud Dedicated supports both `SESSION` and `GLOBAL` rules for `tidb_slow_log_rules`. A single session can have up to 20 active rules across the two scopes. `SESSION` rules do not support `Conn_ID`; only `GLOBAL` rules support this field. + + + + + +TiDB Cloud Essential and TiDB Cloud Premium support only `SESSION` rules for `tidb_slow_log_rules`. Therefore, `Conn_ID`, which is available only in `GLOBAL` rules, is not supported. + + + +- Matching semantics: + - Numeric fields except `Conn_ID` are matched using `>=`. `Conn_ID`, string fields, and boolean fields are matched using equality (`=`). + - Matching for `DB` and `Resource_group` is case-insensitive. + - Explicit operators such as `>`, `<`, and `!=` are not supported. + +Type constraints are as follows: + +- Numeric types (`int64`, `uint64`, `float64`) require values greater than or equal to `0`. Negative values result in a parsing error. + - `int64`: the maximum value is `2^63-1`. + - `uint64`: the maximum value is `2^64-1`. + - `float64`: values must be finite and non-negative. The maximum value is approximately `1.79e308`. `NaN` and infinite values such as `Inf` and `-Inf` are invalid and result in an error. +- `bool`: supports `true`/`false`, `1`/`0`, and `t`/`f` (case-insensitive). +- `string`: currently does not support strings containing the separators `,` (condition separator) or `;` (rule separator), even with quotes (single or double). Escaping is not supported. +- Duplicate fields: if the same field is specified multiple times in a single rule, the last occurrence takes effect. + +## Supported fields + +The fields in the following table follow the general matching and type rules described in [Unified rule syntax and type constraints](#unified-rule-syntax-and-type-constraints), unless otherwise noted. + +| Field name | Type | Unit | Description | +| --- | --- | --- | --- | +| `Conn_ID` | `uint` | count | The connection ID (session ID). This field uses exact matching. For example, `Conn_ID:3` matches only logs whose session ID is `3`. This field is supported only in `GLOBAL` rules. | +| `Session_alias` | `string` | none | The alias of the current session. | +| `DB` | `string` | none | The current database. Matching is case-insensitive. | +| `Exec_retry_count` | `uint` | count | The retry times of this statement. This field is usually for pessimistic transactions in which the statement is retried when the lock fails. | +| `Query_time` | `float` | second | The execution time of a statement. | +| `Parse_time` | `float` | second | The parsing time for the statement. | +| `Compile_time` | `float` | second | The duration of the query optimization. | +| `Rewrite_time` | `float` | second | The time consumed for rewriting the query of this statement. | +| `Optimize_time` | `float` | second | The time consumed for optimizing the execution plan. | +| `Wait_TS` | `float` | second | The waiting time of the statement to get transaction timestamps. | +| `Is_internal` | `bool` | none | Whether a SQL statement is internal to TiDB. `true` indicates that the statement is executed internally in TiDB, and `false` indicates that the statement is executed by the user. | +| `Digest` | `string` | none | The fingerprint of the SQL statement. | +| `Plan_digest` | `string` | none | The digest of the execution plan. | +| `Num_cop_tasks` | `int` | count | The number of Coprocessor tasks sent by this statement. | +| `Mem_max` | `int` | bytes | The maximum memory space used during the execution period of a SQL statement. | +| `Disk_max` | `int` | bytes | The maximum disk space used during the execution period of a SQL statement. | +| `Write_sql_response_total` | `float` | second | The time consumed for sending the results back to the client by this statement. | +| `Succ` | `bool` | none | Whether a statement is executed successfully. | +| `Resource_group` | `string` | none | The resource group that the statement is bound to. Matching is case-insensitive. | +| `KV_total` | `float` | second | The time spent on all the RPC requests to TiKV or TiFlash by this statement. | +| `PD_total` | `float` | second | The time spent on all the RPC requests to PD by this statement. | +| `Process_time` | `float` | second | The total processing time of a SQL statement in TiKV. Because data is sent to TiKV concurrently, this value might exceed `Query_time`. | +| `Backoff_time` | `float` | second | The waiting time before retrying when a statement encounters errors that require a retry. Common errors include lock conflicts, Region splits, and busy TiKV servers. | +| `Total_keys` | `uint` | count | The number of keys that Coprocessor has scanned. | +| `Process_keys` | `uint` | count | The number of keys that Coprocessor has processed. Compared with `Total_keys`, `Process_keys` does not include old versions of MVCC. A large difference between `Process_keys` and `Total_keys` indicates that many old versions exist. | +| `cop_mvcc_read_amplification` | `float` | ratio | The MVCC read amplification ratio, calculated as `Total_keys / Process_keys`. | +| `Prewrite_time` | `float` | second | The duration of the first phase (prewrite) of the two-phase transaction commit. | +| `Commit_time` | `float` | second | The duration of the second phase (commit) of the two-phase transaction commit. | +| `Write_keys` | `uint` | count | The count of keys that the transaction writes to the Write CF in TiKV. | +| `Write_size` | `uint` | bytes | The total size of the keys or values to be written when the transaction commits. | +| `Prewrite_region` | `uint` | count | The number of TiKV Regions involved in the first phase (prewrite) of the two-phase transaction commit. Each Region triggers a remote procedure call. | + +## Effective behavior and matching order + +- Setting `tidb_slow_log_rules` overwrites the existing rules in the specified scope instead of appending new rules. +- Setting `tidb_slow_log_rules` to an empty string clears the rules in the specified scope. +- Multiple rules are combined with `OR`, while multiple field conditions within a single rule are combined with `AND`. +- If you still want to use SQL execution time as a condition for writing slow query logs, use `Query_time` in the rule and note that the unit is seconds. + + + +TiDB Self-Managed supports both `SESSION` and `GLOBAL` rules for `tidb_slow_log_rules`. + +- If the current session has any applicable rules, such as `SESSION` rules, `GLOBAL` rules for the current `Conn_ID`, or generic `GLOBAL` rules without `Conn_ID`, slow query log output is determined by the rule matching results, and `tidb_slow_log_threshold` is ignored. +- If the current session has no applicable rules, for example, when both `SESSION` and `GLOBAL` rules are empty or only `GLOBAL` rules that do not match the current `Conn_ID` are configured, slow query logging still depends on `tidb_slow_log_threshold`. The unit of `tidb_slow_log_threshold` is milliseconds. +- TiDB matches `SESSION` rules first. If none matches, TiDB then matches `GLOBAL` rules for the current `Conn_ID`, followed by generic `GLOBAL` rules without `Conn_ID`. +- `SHOW VARIABLES LIKE 'tidb_slow_log_rules'` and `SELECT @@SESSION.tidb_slow_log_rules` return the `SESSION` rule text, or an empty string if unset. `SELECT @@GLOBAL.tidb_slow_log_rules` returns the `GLOBAL` rule text. + + + + + +TiDB Cloud Dedicated supports both `SESSION` and `GLOBAL` rules for `tidb_slow_log_rules`. + +- If the current session has any applicable rules, such as `SESSION` rules, `GLOBAL` rules for the current `Conn_ID`, or generic `GLOBAL` rules without `Conn_ID`, slow query log output is determined by the rule matching results. +- If the current session has no applicable rules, for example, when both `SESSION` and `GLOBAL` rules are empty or only `GLOBAL` rules that do not match the current `Conn_ID` are configured, the rules for slow query logging fall back to the default one: SQL queries that take more than 300 milliseconds are considered as slow queries. +- TiDB matches `SESSION` rules first. If none matches, TiDB then matches `GLOBAL` rules for the current `Conn_ID`, followed by generic `GLOBAL` rules without `Conn_ID`. +- `SHOW VARIABLES LIKE 'tidb_slow_log_rules'` and `SELECT @@SESSION.tidb_slow_log_rules` return the `SESSION` rule text, or an empty string if unset. `SELECT @@GLOBAL.tidb_slow_log_rules` returns the `GLOBAL` rule text. + + + + + +TiDB Cloud Essential and TiDB Cloud Premium support only `SESSION` rules for `tidb_slow_log_rules`. + +- If the current session has any `SESSION` rules, slow query log output is determined by the rule matching results. +- `SHOW VARIABLES LIKE 'tidb_slow_log_rules'` and `SELECT @@SESSION.tidb_slow_log_rules` return the `SESSION` rule text, or an empty string if unset. + + + +## Recommendations + +- `tidb_slow_log_rules` is designed to replace the single-threshold approach. It supports combinations of multi-dimensional metric conditions, enabling more flexible and fine-grained control over slow query logging. + +- In a well-provisioned test environment with 1 TiDB node (16 CPU cores, 48 GiB memory) and 3 TiKV nodes (each with 16 CPU cores and 48 GiB memory), repeated sysbench tests show that performance impact remains small when multi-dimensional slow query log rules generate millions of slow log entries within 30 minutes. However, when the log volume reaches tens of millions, TPS drops significantly and latency increases noticeably. Therefore, if business workload is high or CPU and memory resources are close to their limits, configure `tidb_slow_log_rules` carefully to avoid log flooding caused by overly broad rules. If you need to limit the log output rate, use [`tidb_slow_log_max_per_sec`](/system-variables.md#tidb_slow_log_max_per_sec) to throttle it and reduce the impact on business performance. diff --git a/identify-slow-queries.md b/identify-slow-queries.md index 59b6340e6889e..1fdf19d148da9 100644 --- a/identify-slow-queries.md +++ b/identify-slow-queries.md @@ -188,6 +188,7 @@ Usage example: SELECT /*+ WRITE_SLOW_LOG */ count(*) FROM t t1, t t2 WHERE t1.a = t2.b; ``` +<<<<<<< HEAD ## Use `tidb_slow_log_rules` [`tidb_slow_log_rules`](/system-variables.md#tidb_slow_log_rules-new-in-v856-and-v900) is used to define trigger rules for slow query logs, supporting multi-dimensional metric combinations. It is suitable for "targeted sampling" and "problem reproduction" of slow logs, enabling you to filter target statements based on specific metric combinations. @@ -314,6 +315,11 @@ Unless otherwise noted, the fields in the following table follow the general mat ## Related system variables * [`tidb_slow_log_rules`](/system-variables.md#tidb_slow_log_rules-new-in-v856-and-v900): see [`tidb_slow_log_rules` recommendations](#recommendations) +======= +## Related system variables + +* [`tidb_slow_log_rules`](/system-variables.md#tidb_slow_log_rules): defines the trigger rules for slow query logs. For more information, see [Configure Trigger Rules for Slow Queries](/config-slow-query-trigger-rules.md). +>>>>>>> 8876be1aaa (docs: add a guide for configuring slow query trigger rules (#23767)) * [`tidb_slow_log_threshold`](/system-variables.md#tidb_slow_log_threshold): sets the threshold for slow query logging. SQL statements whose execution time exceeds this threshold are recorded in the slow query log. The default value is `300ms` (milliseconds). @@ -321,7 +327,11 @@ Unless otherwise noted, the fields in the following table follow the general mat > > Time-related fields in `tidb_slow_log_rules`, such as `Query_time` and `Process_time`, use seconds as the unit and can include decimals, while [`tidb_slow_log_threshold`](/system-variables.md#tidb_slow_log_threshold) uses milliseconds. +<<<<<<< HEAD * [`tidb_slow_log_max_per_sec`](/system-variables.md#tidb_slow_log_max_per_sec-new-in-v856-and-v900): sets the maximum number of slow query log entries that can be written per second. The default value is `0`. This variable is introduced in v9.0.0. +======= +* [`tidb_slow_log_max_per_sec`](/system-variables.md#tidb_slow_log_max_per_sec): sets the maximum number of slow query log entries that can be written per second. The default value is `0`. This variable is introduced in v8.5.6. +>>>>>>> 8876be1aaa (docs: add a guide for configuring slow query trigger rules (#23767)) * A value of `0` means there is no limit on the number of slow query log entries written per second. * A value greater than `0` means TiDB writes at most the specified number of slow query log entries per second. Any excess log entries are discarded and not written to the slow query log file. * It is recommended to set this variable after enabling `tidb_slow_log_rules` to prevent rule-based slow query logging from being triggered too frequently. diff --git a/releases/release-8.5.6.md b/releases/release-8.5.6.md index 0eabd2f5f9f4f..9f9c0464763e1 100644 --- a/releases/release-8.5.6.md +++ b/releases/release-8.5.6.md @@ -39,7 +39,7 @@ Quick access: [Quick start](https://docs.pingcap.com/tidb/v8.5/quick-start-with- Before v8.5.6, the main way to identify slow queries in TiDB is to set the [`tidb_slow_log_threshold`](https://docs.pingcap.com/tidb/v8.5/system-variables#tidb_slow_log_threshold) system variable. This mechanism provides only coarse-grained control over slow query log triggering because it applies globally at the instance level and does not support fine-grained control at the session or SQL level. In addition, it supports only one trigger condition, execution time (`Query_time`), which cannot meet the need to capture slow query logs more precisely in complex scenarios. - Starting from v8.5.6, TiDB enhances slow query log control. You can use the [`tidb_slow_log_rules`](https://docs.pingcap.com/tidb/v8.5/system-variables#tidb_slow_log_rules-new-in-v856) system variable to define multi-dimensional slow query log output rules at the instance, session, and SQL levels, based on conditions such as `Query_time`, `Digest`, `Mem_max`, and `KV_total`. You can use [`tidb_slow_log_max_per_sec`](https://docs.pingcap.com/tidb/v8.5/system-variables#tidb_slow_log_max_per_sec-new-in-v856) to limit the number of log entries written per second, and use the [`WRITE_SLOW_LOG`](https://docs.pingcap.com/tidb/v8.5/optimizer-hints) hint to force slow query logging for specific SQL statements. This enables more flexible and fine-grained control over slow query logs. + Starting from v8.5.6, TiDB enhances slow query log control. You can use the [`tidb_slow_log_rules`](https://docs.pingcap.com/tidb/v8.5/system-variables#tidb_slow_log_rules) system variable to define multi-dimensional slow query log output rules at the instance, session, and SQL levels, based on conditions such as `Query_time`, `Digest`, `Mem_max`, and `KV_total`. You can use [`tidb_slow_log_max_per_sec`](https://docs.pingcap.com/tidb/v8.5/system-variables#tidb_slow_log_max_per_sec) to limit the number of log entries written per second, and use the [`WRITE_SLOW_LOG`](https://docs.pingcap.com/tidb/v8.5/optimizer-hints) hint to force slow query logging for specific SQL statements. This enables more flexible and fine-grained control over slow query logs. For more information, see [documentation](https://docs.pingcap.com/tidb/v8.5/identify-slow-queries). @@ -98,8 +98,8 @@ For TiDB clusters newly deployed in v8.5.5 (that is, not upgraded from versions | [`tidb_foreign_key_check_in_shared_lock`](https://docs.pingcap.com/tidb/v8.5/system-variables#tidb_foreign_key_check_in_shared_lock-new-in-v856) | Newly added | Controls whether foreign key checks in pessimistic transactions use shared locks instead of exclusive locks on rows in the parent table. The default value is `OFF`, which means TiDB uses exclusive locks by default. | | [`tidb_max_dist_task_nodes`](https://docs.pingcap.com/tidb/v8.5/system-variables#tidb_max_dist_task_nodes-new-in-v856) | Newly added | Defines the maximum number of TiDB nodes that the Distributed eXecution Framework (DXF) tasks can use. The default value is `-1`, which indicates that automatic mode is enabled. In automatic mode, TiDB dynamically calculates the value as `min(3, tikv_nodes / 3)`, where `tikv_nodes` represents the number of TiKV nodes in the cluster. | | [`tidb_opt_join_reorder_through_sel`](https://docs.pingcap.com/tidb/v8.5/system-variables#tidb_opt_join_reorder_through_sel-new-in-v856) | Newly added | Improves join reorder optimization for certain multi-table join queries. If you set it to `ON` and safety conditions are met, the optimizer evaluates `Selection` conditions between consecutive join operators together with join order candidates. During join tree reconstruction, the optimizer pushes these conditions down to more appropriate positions whenever possible, allowing more tables to participate in join order optimization. | -| [`tidb_slow_log_max_per_sec`](https://docs.pingcap.com/tidb/v8.5/system-variables#tidb_slow_log_max_per_sec-new-in-v856) | Newly added | Controls the maximum number of slow query log entries that can be written per TiDB node per second. | -| [`tidb_slow_log_rules`](https://docs.pingcap.com/tidb/v8.5/system-variables#tidb_slow_log_rules-new-in-v856) | Newly added | Defines the triggering rules for slow query logs. It supports combining multi-dimensional metrics to provide more flexible and fine-grained logging. | +| [`tidb_slow_log_max_per_sec`](https://docs.pingcap.com/tidb/v8.5/system-variables#tidb_slow_log_max_per_sec) | Newly added | Controls the maximum number of slow query log entries that can be written per TiDB node per second. | +| [`tidb_slow_log_rules`](https://docs.pingcap.com/tidb/v8.5/system-variables#tidb_slow_log_rules) | Newly added | Defines the triggering rules for slow query logs. It supports combining multi-dimensional metrics to provide more flexible and fine-grained logging. | ### Configuration parameters diff --git a/system-variables.md b/system-variables.md index ce7bf4e26cb5e..abbd380ec7bf1 100644 --- a/system-variables.md +++ b/system-variables.md @@ -6106,7 +6106,15 @@ Query OK, 0 rows affected, 1 warning (0.00 sec) > > If the character check is skipped, TiDB might fail to detect invalid UTF-8 characters written by the application, cause decoding errors when `ANALYZE` is executed, and introduce other unknown encoding issues. If your application cannot guarantee the validity of the written string, it is not recommended to skip the character check. +<<<<<<< HEAD ### tidb_slow_log_max_per_sec New in v8.5.6 and v9.0.0 +======= +### tidb_slow_log_max_per_sec New in v8.5.6 and CLOUD.202603.1 {#tidb_slow_log_max_per_sec} + +>**Note:** +> +> This variable is read-only for TiDB Cloud. +>>>>>>> 8876be1aaa (docs: add a guide for configuring slow query trigger rules (#23767)) - Scope: GLOBAL - Persists to cluster: Yes @@ -6117,21 +6125,49 @@ Query OK, 0 rows affected, 1 warning (0.00 sec) - This variable controls the maximum number of slow query log entries that can be written per TiDB node per second. - A value of `0` means there is no limit on the number of slow query log entries written per second. - A value greater than `0` means TiDB writes at most the specified number of slow query log entries per second. Any excess log entries are discarded and not written to the slow query log file. +<<<<<<< HEAD - This variable is often used with [`tidb_slow_log_rules`](#tidb_slow_log_rules-new-in-v856-and-v900) to prevent excessive slow query logs from being generated under high-workload conditions. ### tidb_slow_log_rules New in v8.5.6 and v9.0.0 +======= +- This variable is often used with [`tidb_slow_log_rules`](#tidb_slow_log_rules) to prevent excessive slow query logs from being generated under high-workload conditions. -- Scope: SESSION | GLOBAL +### tidb_slow_log_rules New in v8.5.6 and CLOUD.202603.1 {#tidb_slow_log_rules} +>>>>>>> 8876be1aaa (docs: add a guide for configuring slow query trigger rules (#23767)) + +>**Note:** +> +> This variable is not supported on TiDB Cloud Starter. + +- Scope + - TiDB Self-Managed and TiDB Cloud Dedicated: SESSION | GLOBAL + - TiDB Cloud Essential and Premium: SESSION - Persists to cluster: Yes - Applies to hint [SET_VAR](/optimizer-hints.md#set_varvar_namevar_value): No - Default value: "" - Type: String - This variable defines the triggering rules for slow query logs. It supports combining multi-dimensional metrics to provide more flexible and fine-grained logging. -- For more information about how to use this system variable, see [Use `tidb_slow_log_rules`](/identify-slow-queries.md#use-tidb_slow_log_rules). +- For more information about how to use this system variable, see [Configure Trigger Rules for Slow Queries](/config-slow-query-trigger-rules.md). + + > **Tip:** > +<<<<<<< HEAD > After enabling `tidb_slow_log_rules`, it is recommended to also configure [`tidb_slow_log_max_per_sec`](#tidb_slow_log_max_per_sec-new-in-v856-and-v900) to limit the slow query log output rate and prevent rule-based slow query logging from being triggered too frequently. +======= +> - When enabling `tidb_slow_log_rules` in a production environment, it is recommended to also configure [`tidb_slow_log_max_per_sec`](#tidb_slow_log_max_per_sec) to avoid excessively frequent slow query log printing. +> - It is recommended to start with stricter conditions and gradually relax them based on troubleshooting needs. For more information on performance impact, see [Recommendations](/config-slow-query-trigger-rules.md#recommendations). + + + + +> **Tip:** +> +> It is recommended to start with stricter conditions and gradually relax them based on troubleshooting needs. For more information on performance impact, see [Recommendations](/config-slow-query-trigger-rules.md#recommendations). + + +>>>>>>> 8876be1aaa (docs: add a guide for configuring slow query trigger rules (#23767)) ### tidb_slow_log_threshold diff --git a/tidb-cloud/tune-performance.md b/tidb-cloud/tune-performance.md index e2efc706f3ab5..2dc6da536464d 100644 --- a/tidb-cloud/tune-performance.md +++ b/tidb-cloud/tune-performance.md @@ -46,6 +46,14 @@ TiDB Cloud provides [Slow Query](#slow-query) and [SQL Statement](#sql-statement By default, SQL queries that take more than 300 milliseconds are considered as slow queries. + + +> **Note:** +> +> You can also configure trigger rules for slow queries to filter target statements based on specific metric combinations. For more information, see [Configure Trigger Rules for Slow Queries](/config-slow-query-trigger-rules.md). + + + To view slow queries in a {{{ .starter }}} instance{{{ .essential }}} instance{{{ .premium }}} instance{{{ .dedicated }}} cluster, perform the following steps: