Skip to content

Commit f56b240

Browse files
Auto-sync: Update English docs from Chinese PR
Synced from: pingcap/docs-cn#21337 Target PR: pingcap#22567 AI Provider: gemini Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 26ea8a8 commit f56b240

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

identify-slow-queries.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,30 @@ Usage example:
188188
SELECT /*+ WRITE_SLOW_LOG */ count(*) FROM t t1, t t2 WHERE t1.a = t2.b;
189189
```
190190

191+
## `tidb_slow_log_rules` Usage
192+
[`tidb_slow_log_rules`](/system-variables.md#tidb_slow_log_rules-introduced-in-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, allowing you to filter target statements based on specific metric combinations.
193+
The triggering behavior of slow query logs depends on the configuration of `tidb_slow_log_rules`:
194+
- If `tidb_slow_log_rules` is not set, slow query log triggering still relies on [`tidb_slow_log_threshold`](/system-variables.md#tidb_slow_log_threshold) (in milliseconds).
195+
- If `tidb_slow_log_rules` is set, the configured rules take precedence, and [`tidb_slow_log_threshold`](/system-variables.md#tidb_slow_log_threshold) will be ignored.
196+
197+
- Rule Capacity and Separation: `SESSION` and `GLOBAL` each support a maximum of 10 rules. A single session can have up to 20 active rules. Rules are separated by `;`.
198+
- Field and Scope: Field names are case-insensitive (underscores and other characters should be preserved). `Conn_ID` is not supported for `SESSION` rules; only `GLOBAL` supports `Conn_ID`.
199+
- String and boolean fields are matched using equality (`=`).
200+
- `DB` and `Resource_group` matching is case-insensitive.
201+
- Numeric types (`int64`, `uint64`, `float64`) uniformly require `>= 0`. Negative values will result in a parsing error.
202+
- `int64`: Maximum value is `2^63-1`.
203+
- `uint64`: Maximum value is `2^64-1`.
204+
- `float64`: The general upper limit is approximately `1.79e308`. Currently, parsing is done using Go's `ParseFloat`. While `NaN`/`Inf` can be parsed, they may lead to rules that are always true or always false, so their use is not recommended.
205+
- `bool`: Supports `true`/`false`, `1`/`0`, and `t`/`f` (case-insensitive).
206+
- `string`: Currently does not support strings containing the separators `,` (condition separator) or `;` (rule separator), even with quotes (single or double). Escaping is not supported.
207+
208+
- Standard format (SESSION scope):
209+
SET SESSION tidb_slow_log_rules = 'Query_time: 0.5, Is_internal: false';
210+
- Incorrect format (SESSION scope does not support `Conn_ID`):
211+
SET SESSION tidb_slow_log_rules = 'Conn_ID: 12, Query_time: 0.5, Is_internal: false';
212+
SET GLOBAL tidb_slow_log_rules = 'Query_time: 0.5, Is_internal: false';
213+
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';
214+
191215
## Related system variables
192216

193217
* [`tidb_slow_log_threshold`](/system-variables.md#tidb_slow_log_threshold): sets the threshold for the slow query log. The SQL statement whose execution time exceeds this threshold is recorded in the slow query log. The default value is 300 ms.

system-variables.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5889,10 +5889,12 @@ Query OK, 0 rows affected, 1 warning (0.00 sec)
58895889
- Default value: ""
58905890
- Type: String
58915891
- This variable defines the triggering rules for slow query logs. It supports combining multi-dimensional metrics to provide more flexible and fine-grained logging.
5892+
- For detailed usage of this system variable, please refer to [`tidb_slow_log_rules` Usage Guide](/identify-slow-queries.md#tidb_slow_log_rules-usage-guide).
58925893
58935894
> **Tip:**
58945895
>
5895-
> 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-v900) to limit the slow query log output rate and prevent rule-based slow query logging from being triggered too frequently.
5896+
> - 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-new-in-v900) to avoid excessively frequent slow query log printing.
5897+
> - It is recommended to start with stricter conditions and gradually relax them based on troubleshooting needs. For more information on performance impact, please refer to [Usage Recommendations](/identify-slow-queries.md#usage-recommendations).
58965898
58975899
### tidb_slow_log_threshold
58985900

0 commit comments

Comments
 (0)