Skip to content

statistics: add docs for the FLUSH STATS_DELTA statement#21819

Open
qiancai wants to merge 8 commits into
pingcap:masterfrom
qiancai:add-flush-stats-delta-doc-23258
Open

statistics: add docs for the FLUSH STATS_DELTA statement#21819
qiancai wants to merge 8 commits into
pingcap:masterfrom
qiancai:add-flush-stats-delta-doc-23258

Conversation

@qiancai

@qiancai qiancai commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

What is changed, added or deleted? (Required)

Add documentation for the FLUSH STATS_DELTA statement introduced in v8.5.7 and v9.0.0 (pingcap/tidb#65668), which persists the pending statistics delta buffered in TiDB memory to the mysql.stats_meta system table immediately.

  • Add a new page: sql-statements/sql-statement-flush-stats-delta.md (synopsis, options, examples, privileges).
  • Add the statement to TOC.md and sql-statements/sql-statement-overview.md.
  • Cross-link the statement from the "Automatic update" section in statistics.md.

All examples and behavior descriptions (target scopes, CLUSTER broadcast, privilege requirements, and warnings) are verified against a TiDB v8.5.7 TiUP playground with two TiDB instances.

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)
  • v9.0 (TiDB 9.0 versions)
  • v8.5 (TiDB 8.5 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)?

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

  • 文档更新
    • 新增 FLUSH STATS_DELTA 语句文档,补充语法、Targets、可选 CLUSTER 行为、去重规则、分区表处理、告警与跳过情形、所需 SELECT 权限、示例及兼容性说明。
    • 在 SQL 语句总览与统计信息管理相关文档中新增该语句条目,并完善目录与发布说明链接;说明从指定版本起支持通过该语句将待持久化的统计信息立即生效。

@qiancai qiancai added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. translation/from-docs This PR is translated from a PR in pingcap/docs. v9.0-beta.3 This PR/issue applies to TiDB v9.0-beta.3. labels Jul 17, 2026
@ti-chi-bot ti-chi-bot Bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jul 17, 2026
Synced from: pingcap/docs#23258
Target PR: pingcap#21819
AI Provider: azure

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

Auto-sync completed successfully

Source PR: pingcap/docs#23258
Target PR: #21819

Chinese documentation has been updated based on English documentation changes.

@ti-chi-bot

ti-chi-bot Bot commented Jul 17, 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 kissmydb 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 size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jul 17, 2026
@coderabbitai

coderabbitai Bot commented Jul 17, 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
📝 Walkthrough

Walkthrough

新增 FLUSH STATS_DELTA 中文文档,说明语法、目标、集群行为、示例、权限和兼容性,并更新 SQL 索引、统计信息说明、目录及发行说明。

Changes

FLUSH STATS_DELTA 文档

Layer / File(s) Summary
语句行为与语法
sql-statements/sql-statement-flush-stats-delta.md
说明统计信息 delta 的立即持久化、目标、CLUSTER、去重、分区表及不存在对象的处理。
使用方式与权限说明
sql-statements/sql-statement-flush-stats-delta.md
补充单表、通配和集群示例,说明 SELECT 权限、MySQL 兼容性及相关参考。
文档导航与统计信息说明
sql-statements/sql-statement-overview.md, statistics.md, TOC.md, releases/release-8.5.7.md
更新 SQL 和目录索引、统计信息持久化说明及发行说明链接。

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

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed 标题简洁且准确概括了新增 FLUSH STATS_DELTA 文档这一主要变更。
Description check ✅ Passed 描述覆盖了变更内容、适用版本和相关链接,但未填写 AI agent involvement 等模板项。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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
🧪 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.

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@sql-statements/sql-statement-flush-stats-delta.md`:
- Line 10: Correct the shared automatic-update links: in
sql-statements/sql-statement-flush-stats-delta.md lines 10-10, change the label
from 自动修改 to 自动更新 and target /statistics.md#自动更新; in statistics.md lines 19-19,
update the self-reference target to /statistics.md#自动更新.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e78484c2-a88f-4f97-be6c-40836ad12543

📥 Commits

Reviewing files that changed from the base of the PR and between bae0ddc and a98cd8f.

📒 Files selected for processing (5)
  • TOC.md
  • releases/release-8.5.7.md
  • sql-statements/sql-statement-flush-stats-delta.md
  • sql-statements/sql-statement-overview.md
  • statistics.md

Comment thread sql-statements/sql-statement-flush-stats-delta.md Outdated
Comment thread sql-statements/sql-statement-flush-stats-delta.md Outdated
Comment thread releases/release-8.5.7.md Outdated
Comment thread sql-statements/sql-statement-overview.md Outdated
Comment thread releases/release-8.5.7.md Outdated
@qiancai

qiancai commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator Author

/cc @0xPoe

@ti-chi-bot
ti-chi-bot Bot requested a review from 0xPoe July 23, 2026 10:36

@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: Pro Plus

Run ID: 87b103ec-0e2f-4287-819d-0eb2bf9bfbed

📥 Commits

Reviewing files that changed from the base of the PR and between a98cd8f and c97b9c8.

📒 Files selected for processing (1)
  • sql-statements/sql-statement-flush-stats-delta.md

Query OK, 0 rows affected (0.01 sec)
```

此时,TiDB 已将该表的行数变化持久化到 `mysql.stats_meta` 系统表。你可以使用 `SHOW STATS_META` 查看已持久化的值。注意,`SHOW STATS_META` 会从你当前连接的 TiDB 节点内存中读取统计信息。该 TiDB 节点会在 [`stats-lease`](/tidb-configuration-file.md#stats-lease)(默认 `3s`)周期内加载已持久化的值,因此刷新后的值可能会在短暂延迟后才显示在输出中:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

补充 stats-lease=0 的边界行为

当前表述暗示刷新后的值最多延迟一个 stats-lease 周期即可显示,但当 stats-lease=0 时不会自动加载更新的统计信息;用户执行 FLUSH STATS_DELTA 后仍可能看到旧值,需要显式执行 REFRESH STATS。(docs.pingcap.com)

As per path instructions,Markdown 文档中的可安全连续修复应提供精确替换文本。

建议直接替换
-注意,`SHOW STATS_META` 会从你当前连接的 TiDB 节点内存中读取统计信息。该 TiDB 节点会在 [`stats-lease`](/tidb-configuration-file.md#stats-lease)(默认 `3s`)周期内加载已持久化的值,因此刷新后的值可能会在短暂延迟后才显示在输出中:
+注意,`SHOW STATS_META` 会从你当前连接的 TiDB 节点内存中读取统计信息。该 TiDB 节点会在 [`stats-lease`](/tidb-configuration-file.md#stats-lease)(默认 `3s`)周期内加载已持久化的值;当 `stats-lease` 设置为 `0` 时不会自动加载。此时,如需让内存中的统计信息反映刚持久化的值,请执行 [`REFRESH STATS`](/sql-statements/sql-statement-refresh-stats.md)。因此,刷新后的值可能会在短暂延迟后显示,或在 `stats-lease=0` 时不会自动显示:
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
此时,TiDB 已将该表的行数变化持久化到 `mysql.stats_meta` 系统表。你可以使用 `SHOW STATS_META` 查看已持久化的值。注意,`SHOW STATS_META` 会从你当前连接的 TiDB 节点内存中读取统计信息。该 TiDB 节点会在 [`stats-lease`](/tidb-configuration-file.md#stats-lease)(默认 `3s`)周期内加载已持久化的值,因此刷新后的值可能会在短暂延迟后才显示在输出中
此时,TiDB 已将该表的行数变化持久化到 `mysql.stats_meta` 系统表。你可以使用 `SHOW STATS_META` 查看已持久化的值。注意,`SHOW STATS_META` 会从你当前连接的 TiDB 节点内存中读取统计信息。该 TiDB 节点会在 [`stats-lease`](/tidb-configuration-file.md#stats-lease)(默认 `3s`)周期内加载已持久化的值;当 `stats-lease` 设置为 `0` 时不会自动加载。此时,如需让内存中的统计信息反映刚持久化的值,请执行 [`REFRESH STATS`](/sql-statements/sql-statement-refresh-stats.md)。因此,刷新后的值可能会在短暂延迟后显示,或在 `stats-lease=0` 时不会自动显示

Source: Path instructions

Comment thread sql-statements/sql-statement-flush-stats-delta.md Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. translation/from-docs This PR is translated from a PR in pingcap/docs. v9.0-beta.3 This PR/issue applies to TiDB v9.0-beta.3.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant