Skip to content

docs: add a guide for configuring slow query trigger rules - #23767

Open
qiancai wants to merge 15 commits into
pingcap:release-8.5from
qiancai:update-tidb_slow_log_rules
Open

docs: add a guide for configuring slow query trigger rules#23767
qiancai wants to merge 15 commits into
pingcap:release-8.5from
qiancai:update-tidb_slow_log_rules

Conversation

@qiancai

@qiancai qiancai commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

What is changed, added or deleted? (Required)

Add a standalone guide for configuring slow query trigger rules so that users can find the supported fields, syntax constraints, matching behavior, and examples in one place.

The guide distinguishes the supported rule scopes and behavior for TiDB Self-Managed, TiDB Cloud Dedicated, and TiDB Cloud Essential/Premium. It also updates the related system variable documentation, TiDB Cloud performance guide, navigation entries, and cross-references.

Which TiDB version(s) do your changes apply to? (Required)

Tips for choosing the affected version(s):

By default, CHOOSE MASTER ONLY so your changes will be applied to the next TiDB major or minor releases. If your PR involves a product feature behavior change or a compatibility change, CHOOSE THE AFFECTED RELEASE BRANCH(ES) AND MASTER.

For details, see tips for choosing the affected versions.

  • master (the latest development version)
  • v8.5 (TiDB 8.5 versions)
  • v8.4 (TiDB 8.4 versions)
  • v8.3 (TiDB 8.3 versions)
  • v8.2 (TiDB 8.2 versions)
  • v8.1 (TiDB 8.1 versions)
  • v7.5 (TiDB 7.5 versions)
  • v7.1 (TiDB 7.1 versions)
  • v6.5 (TiDB 6.5 versions)

What is the related PR or file link(s)?

  • This PR is translated from:
  • Other reference link(s):

AI agent involvement

  • The changes in this PR were primarily made by an AI agent on behalf of the PR author.

Do your changes match any of the following descriptions?

  • Delete files
  • Change aliases
  • Need modification after applied to another branch
  • Might cause conflicts after applied to another branch

Summary by CodeRabbit

  • Documentation
    • Added guidance for configuring slow-query trigger rules, including supported conditions, scopes, examples, and performance recommendations.
    • Updated slow-query variable documentation with platform availability, scope behavior, and TiDB Cloud Starter limitations.
    • Added links to the new guide in relevant tables of contents and performance documentation.
    • Moved rule-configuration guidance into a dedicated slow-query trigger rules page.

@ti-chi-bot

ti-chi-bot Bot commented Sep 8, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign breezewish for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot Bot added missing-translation-status This PR does not have translation status info. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Sep 8, 2026
@qiancai qiancai added needs-cherry-pick-master Should cherry pick this PR to master branch. requires-version-specific-changes After cherry-picked, the cherry-picked PR requires further changes. labels Sep 8, 2026
@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Team

Run ID: bd8ae494-33d8-485d-9c1d-5139d8192356

📥 Commits

Reviewing files that changed from the base of the PR and between b369893 and 553d9c0.

📒 Files selected for processing (1)
  • config-slow-query-trigger-rules.md

Included review availability: Your plan provides up to 4 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Adds a dedicated guide for tidb_slow_log_rules, updates its system-variable reference, removes duplicated content, and links the guide from slow-query navigation and TiDB Cloud performance documentation.

Changes

Slow Query Trigger Rules

Layer / File(s) Summary
Trigger rule configuration guide
config-slow-query-trigger-rules.md
Adds rule syntax, supported fields, matching behavior, platform-specific fallback behavior, examples, and performance recommendations.
System-variable documentation integration
system-variables.md, identify-slow-queries.md
Adds platform-specific scope and support details for tidb_slow_log_rules, links to the new guide, and removes duplicated configuration content.
Documentation navigation and plan content
TOC.md, TOC-tidb-cloud-essential.md, TOC-tidb-cloud-premium.md, tidb-cloud/tune-performance.md
Adds navigation entries and an essential and premium plan note linking to the trigger-rules guide.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: 🟡 Moderate · up to 553d9

The new guide may direct TiDB Cloud Starter users to configure an unsupported variable, and inconsistent numeric type terminology can make rule syntax unclear. Clarify platform availability and type definitions before merging.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding a guide for configuring slow query trigger rules.
Description check ✅ Passed The description explains the documentation changes, affected TiDB versions, AI involvement, and branch-specific follow-up. The required sections are present and sufficiently complete.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qiancai qiancai added the translation/doing This PR's assignee is translating this PR. label Sep 8, 2026
@ti-chi-bot ti-chi-bot Bot removed the missing-translation-status This PR does not have translation status info. label Sep 8, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Team

Run ID: 25089249-19b3-42b5-a410-c5473dda5827

📥 Commits

Reviewing files that changed from the base of the PR and between 94afa8e and 86ad6df.

📒 Files selected for processing (7)
  • TOC-tidb-cloud-essential.md
  • TOC-tidb-cloud-premium.md
  • TOC.md
  • config-slow-query-trigger-rules.md
  • identify-slow-queries.md
  • system-variables.md
  • tidb-cloud/tune-performance.md
💤 Files with no reviewable changes (1)
  • identify-slow-queries.md

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.

Comment thread config-slow-query-trigger-rules.md Outdated
Comment thread config-slow-query-trigger-rules.md
Comment thread config-slow-query-trigger-rules.md Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Team

Run ID: cdefc522-d06b-4b69-acb2-220c9b2de355

📥 Commits

Reviewing files that changed from the base of the PR and between 86ad6df and b369893.

📒 Files selected for processing (1)
  • config-slow-query-trigger-rules.md

Included review availability: Your plan provides up to 4 included reviews per hour; 1 remains after this review.

Comment thread config-slow-query-trigger-rules.md Outdated
Comment thread config-slow-query-trigger-rules.md Outdated
qiancai and others added 2 commits September 8, 2026 11:02
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@qiancai

qiancai commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author

/cc @XuHuaiyu @zhaoshangzi

@ti-chi-bot
ti-chi-bot Bot requested review from XuHuaiyu and zhaoshangzi September 8, 2026 03:06
Comment thread config-slow-query-trigger-rules.md Outdated

@XuHuaiyu XuHuaiyu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 behavior-consistency findings from checking the documentation against TiDB release-8.5 code.

Comment thread config-slow-query-trigger-rules.md Outdated
For TiDB Self-Managed, the triggering behavior of slow query logs depends on the configuration of `tidb_slow_log_rules`:

- 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).
- If `tidb_slow_log_rules` is set and the configured rules match the current session, the configured rules take precedence, and [`tidb_slow_log_threshold`](/system-variables.md#tidb_slow_log_threshold) will be ignored.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] This wording conflates a rule being applicable to the current session with its conditions matching the current statement. The implementation switches away from tidb_slow_log_threshold whenever the session has any applicable rule (EffectiveFields is non-empty), even if no rule condition matches; it falls back to the threshold only when there are no applicable rules. Please align this summary with lines 172–173, for example: If the current session has any applicable rules, slow query log output is determined by the rule matching results, and tidb_slow_log_threshold is ignored. See https://github.com/pingcap/tidb/blob/ac41d7e3c8fcc7ffdb97311e2996cc9fb178e4c9/pkg/executor/adapter.go#L1785-L1795.

Comment thread config-slow-query-trigger-rules.md Outdated
- 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`: the general upper limit is approximately `1.79e308`. Currently, parsing is done using Go's `ParseFloat`. While `NaN`/`Inf` can be parsed, they might lead to rules that are always true or always false. It is not recommended to use them.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] This is the opposite of the release-8.5 implementation. Although strconv.ParseFloat accepts these spellings, parseFloat64 immediately rejects both NaN and any infinity with threshold value must be finite; the existing tests also assert those errors. Please document NaN, Inf, and -Inf as invalid values rather than values that are merely discouraged. See https://github.com/pingcap/tidb/blob/ac41d7e3c8fcc7ffdb97311e2996cc9fb178e4c9/pkg/sessionctx/variable/slow_log.go#L647-L658.

Comment thread identify-slow-queries.md Outdated

## Related system variables

* [`tidb_slow_log_rules`](/system-variables.md#tidb_slow_log_rules-new-in-v856): see [`tidb_slow_log_rules` recommendations](#recommendations)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] This PR removes the Recommendations heading from this page, so the local #recommendations anchor is now broken. Please point it to the new page: /config-slow-query-trigger-rules.md#recommendations.

Comment thread identify-slow-queries.md Outdated
Comment thread config-slow-query-trigger-rules.md Outdated
Comment thread config-slow-query-trigger-rules.md Outdated
Comment thread identify-slow-queries.md Outdated

@zhaoshangzi zhaoshangzi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ti-chi-bot

ti-chi-bot Bot commented Sep 9, 2026

Copy link
Copy Markdown

@zhaoshangzi: adding LGTM is restricted to approvers and reviewers in OWNERS files.

Details

In response to this:

lgtm

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@XuHuaiyu XuHuaiyu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 findings from re-reviewing this documentation against the current TiDB release-8.5 implementation.

| `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. |
| `Unpacked_bytes_sent_tikv_total` | `int` | bytes | The total amount of uncompressed data sent to TiKV by this statement. |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] These eight Unpacked_bytes_* fields are not supported by the current release-8.5 implementation. The field registry does not contain them, so the parser rejects each one as an unknown slow-log field (registry, validation). The already-merged v8.5 backport, pingcap/tidb#66582, omitted these fields as well. Please remove all eight rows from the v8.5 docs, or land the corresponding release-8.5 code backport first.


| Field name | Type | Unit | Description |
| --- | --- | --- | --- |
| `Conn_ID` | `uint` | count | The connection ID (session ID). For example, you can use `Conn_ID:3` to match logs whose session ID is `3`. This field is supported only in `GLOBAL` rules. |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Please document that Conn_ID is an exception to the general numeric >= matching rule. Global rules are indexed by the configured connection ID and TiDB only loads the entry for the current connection, so Conn_ID: 11 applies exactly to connection 11, not to every connection whose ID is at least 11 (selection logic).

Comment thread system-variables.md
- 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.

### tidb_slow_log_rules <span class="version-mark">New in v8.5.6</span>
### tidb_slow_log_rules <span class="version-mark">New in v8.5.6 and CLOUD.202603.1</span> {#tidb_slow_log_rule}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] The explicit anchor is singular (tidb_slow_log_rule), but this PR links to #tidb_slow_log_rules throughout. This makes those links dead and is reported by the internal-links-anchors check. Please change the anchor to {#tidb_slow_log_rules}.

</CustomContent>
<CustomContent platform="tidb-cloud">

In the [TiDB Cloud console](/tidb-cloud/index.md), 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] /tidb-cloud/index.md does not exist in this repository, so this link fails the internal-link and TOC checks. Please use the actual TiDB Cloud console URL (for example, https://tidbcloud.com/) or an existing docs page.


In the [TiDB Cloud console](/tidb-cloud/index.md), 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] This block targets all TiDB Cloud plans and therefore tells Starter users to modify tidb_slow_log_rules, while the system-variable entry in this PR explicitly says Starter does not support it. Please scope this variable-specific guidance to plan="dedicated,essential,premium" (or otherwise exclude Starter).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-cherry-pick-master Should cherry pick this PR to master branch. requires-version-specific-changes After cherry-picked, the cherry-picked PR requires further changes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. translation/doing This PR's assignee is translating this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants