sql-statement-drop-stats: fix STATS_META output after DROP STATS - #21887
sql-statement-drop-stats: fix STATS_META output after DROP STATS#21887doc-claw-bot wants to merge 1 commit into
Conversation
|
@doc-claw-bot: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions 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. I understand the commands that are listed here. |
📝 WalkthroughWalkthrough更新 ChangesDROP STATS 文档更新
Estimated code review effort: 1(简单)| ~5 分钟 Merge Risk: 🔵 Low · up to The PR is mergeable with explicit owner follow-up because the updated documentation still conflates TopN with histogram buckets and omits Last_analyze_time from the post-DROP STATS output. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
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. Comment |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 31e0fbac-209e-4c15-abf9-ee785d3ef576
📒 Files selected for processing (1)
sql-statements/sql-statement-drop-stats.md
Included review availability: Your plan includes up to 4 reviews per rolling hour; 3 remain after this review.
| `DROP STATS` 会清除 TopN、bucket 等直方图相关统计信息,但不会删除 | ||
| `STATS_META` 中对应的记录。 |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
不要把 TopN 归入直方图。
TopN 与直方图是两类独立的统计信息。bucket 属于直方图。当前措辞会错误地将 TopN 归类为直方图。官方统计信息文档也将两者分开说明。(docs.pingcap.com)
As per path instructions: 对可以安全替换的连续 Markdown 行提供 committable suggestion。
| `DROP STATS` 会清除 TopN、bucket 等直方图相关统计信息,但不会删除 | |
| `STATS_META` 中对应的记录。 | |
| `DROP STATS` 会清除 TopN、直方图 bucket 等统计信息,但不会删除 | |
| `STATS_META` 中对应的记录。 |
Source: Path instructions
| +---------+------------+----------------+---------------------+--------------+-----------+ | ||
| | Db_name | Table_name | Partition_name | Update_time | Modify_count | Row_count | | ||
| +---------+------------+----------------+---------------------+--------------+-----------+ | ||
| | test | t | | 2020-05-25 20:34:33 | 0 | 0 | | ||
| +---------+------------+----------------+---------------------+--------------+-----------+ | ||
| 1 row in set (0.00 sec) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- changed file context ---'
sed -n '70,110p' sql-statements/sql-statement-drop-stats.md
printf '%s\n' '--- SHOW STATS_META documentation references ---'
rg -n -C 4 'Last_analyze_time|SHOW STATS_META|Update_time|Modify_count|Row_count' sql-statements/sql-statement-show-stats-meta.md sql-statements
printf '%s\n' '--- repository version metadata ---'
rg -n 'TiDB v?[0-9]+\.[0-9]+|version|版本' README.md docs sql-statements 2>/dev/null | head -80 || trueRepository: pingcap/docs-cn
Length of output: 45540
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- branch and diff metadata ---'
git branch --show-current
git diff --stat
git diff -- sql-statements/sql-statement-drop-stats.md
printf '%s\n' '--- current branch version table ---'
sed -n '1,35p' README.md
printf '%s\n' '--- DROP STATS implementation references in tracked files ---'
rg -n -C 5 'LastAnalyzeTime|last_analyze_time|DropStats|DROP STATS|drop stats' --glob '*.{go,sql,md}' . | head -240Repository: pingcap/docs-cn
Length of output: 12274
🌐 Web query:
site:github.com/pingcap/tidb "LastAnalyzeTime" "DROP STATS"
💡 Result:
The terms "LastAnalyzeTime" and "DROP STATS" are primarily associated with the TiDB distributed database system [1][2][3]. In TiDB: 1. DROP STATS: This is a SQL command used to remove collected table statistics from the system [4][5]. It is primarily used to clean up metadata when statistics become outdated, invalid, or are no longer needed [1][6]. The syntax typically takes the form DROP STATS <table_name> [5]. 2. LastAnalyzeTime: This is a field found in the mysql.stats_meta system table that records the timestamp of the last successful ANALYZE operation performed on a table [2][3][7]. It allows administrators to track when statistics were last refreshed [7]. Technical context regarding their interaction: - When DROP STATS is executed, the associated statistics are removed [6]. - Issues have historically been reported where a table's LastAnalyzeTime might persist or appear non-null even after stats have been dropped or if the table has never actually been analyzed [8]. - Developers often manage these behaviors to ensure that metadata consistency is maintained (e.g., ensuring LastAnalyzeTime reflects the actual state of statistical collection) [1][9][3]. For managing extended statistics specifically, newer versions of TiDB have shifted toward using ALTER TABLE... DROP TIDB_STATS to replace older, deprecated syntax, ensuring better consistency across the system [10].
Citations:
- 1: statistics: fix the behavior of DROP STATS after #58596 | tidb-test=pr/2471 tidb#59031
- 2: statistics: init LastAnalyzeVersion with snapshot timestamp tidb#54465
- 3: statistics: add
last_analyze_versionformysql.stats_metatidb#51489 - 4: executor: fix drop global stats tidb#34820
- 5: parser: allow drop stats of multiple tables tidb#38042
- 6: statistics: drop stats should delete topn tidb#18160
- 7: ease of use: The stats_meta data table adds two fields related to statistics collection. tidb#49594
- 8: Table's last analyze time is not null while it is not analyzed in fact tidb#52357
- 9: statistics: fix some problem related to stats async load tidb#57723
- 10: *: support ALTER TABLE ADD / DROP TIDB_STATS tidb#22127
🌐 Web query:
site:docs.pingcap.com/tidb/stable "DROP STATS" "Last_analyze_time"
💡 Result:
There is no SQL command "DROP STATS Last_analyze_time". Based on standard database documentation (specifically TiDB, which utilizes both "DROP STATS" and "Last_analyze_time" terminology), these are two distinct concepts [1][2]. 1. DROP STATS: This is a valid SQL command used to delete the statistics of a specified table or its partitions [1]. The correct syntax for this command is: DROP STATS TableName; [1] 2. Last_analyze_time: This is not a command but a column name returned by the "SHOW STATS_META" statement [2]. It displays the timestamp of the last time a table was analyzed [2]. It appears you may have conflated a command with a metadata field. To manage table statistics, you can either drop them using DROP STATS [1] or view their current metadata, including the last analyze time, using: SHOW STATS_META; [2]
Citations:
- 1: https://docs.pingcap.com/tidb/stable/sql-statement-drop-stats/
- 2: https://docs.pingcap.com/tidb/stable/sql-statement-show-stats-meta/
🏁 Script executed:
#!/bin/bash
set -e
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
curl -fsSL 'https://api.github.com/repos/pingcap/tidb/git/trees/master?recursive=1' \
| jq -r '.tree[] | select(.type=="blob" and (.path|test("\\.(go|sql)$"))) | .path' \
| rg 'statistics|executor|infoschema|parser' > "$tmpdir/paths"
printf '%s\n' '--- candidate source paths ---'
cat "$tmpdir/paths" | rg 'stats|statistics|infoschema' | head -120
printf '%s\n' '--- relevant current source lines ---'
while IFS= read -r path; do
body="$(curl -fsSL "https://raw.githubusercontent.com/pingcap/tidb/master/$path" || true)"
if printf '%s' "$body" | rg -q 'LastAnalyzeTime|last_analyze_time|DropStats'; then
printf '%s\n' "### $path"
printf '%s' "$body" | rg -n -C 5 'LastAnalyzeTime|last_analyze_time|DropStats' | head -160
fi
done < <(rg 'stats|statistics' "$tmpdir/paths" | head -80)Repository: pingcap/docs-cn
Length of output: 5471
🏁 Script executed:
#!/bin/bash
set -e
for path in \
pkg/executor/show_stats.go \
pkg/executor/infoschema_reader.go \
pkg/parser/ast/stats.go \
pkg/statistics/handle/handle.go \
pkg/statistics/handle/storage.go
do
body="$(curl -fsSL "https://raw.githubusercontent.com/pingcap/tidb/master/$path" || true)"
if printf '%s' "$body" | rg -q 'LastAnalyzeTime|last_analyze_time|DropStats|DROP STATS'; then
printf '%s\n' "### $path"
printf '%s' "$body" | rg -n -C 8 'LastAnalyzeTime|last_analyze_time|DropStats|DROP STATS' | head -240
fi
doneRepository: pingcap/docs-cn
Length of output: 2140
🏁 Script executed:
#!/bin/bash
set -e
curl -fsSL 'https://api.github.com/repos/pingcap/tidb/git/trees/master?recursive=1' |
jq -r '.tree[] | select(.type=="blob") | .path' |
rg '(^|/)(stats|statistics|analyze|infoschema|executor)([^/]*)(\.go|\.sql)$|stats_meta|statsmeta' |
head -240Repository: pingcap/docs-cn
Length of output: 4444
🏁 Script executed:
#!/bin/bash
set -e
for path in \
pkg/ddl/executor.go \
pkg/statistics/handle/storage/stats_read_writer.go \
pkg/statistics/analyze.go \
pkg/executor/analyze.go \
pkg/infoschema/infoschema.go
do
body="$(curl -fsSL "https://raw.githubusercontent.com/pingcap/tidb/master/$path")"
printf '%s\n' "### $path"
printf '%s' "$body" |
rg -n -i -C 8 'drop stats|last[_a-z]*analy|stats_meta|statsmeta|analyze_time' |
head -260 || true
doneRepository: pingcap/docs-cn
Length of output: 13338
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- DDL and SHOW-related source paths ---'
curl -fsSL 'https://api.github.com/repos/pingcap/tidb/git/trees/master?recursive=1' |
jq -r '.tree[] | select(.type=="blob") | .path' |
rg '(^|/)(ddl|executor|statistics|infoschema)/.*(stats|ddl|show|meta).*\.go$|(^|/)ddl/.*\.go$' |
head -320Repository: pingcap/docs-cn
Length of output: 10672
🏁 Script executed:
#!/bin/bash
set -e
for path in \
pkg/executor/show_stats.go \
pkg/executor/ddl.go \
pkg/statistics/handle/ddl/ddl.go \
pkg/ddl/stat.go
do
body="$(curl -fsSL "https://raw.githubusercontent.com/pingcap/tidb/master/$path")"
printf '%s\n' "### $path"
printf '%s' "$body" |
rg -n -i -C 12 'last[_a-z]*analy|stats_meta|statsmeta|dropstats|drop stats|delete.*stats|truncate.*stats' |
head -360 || true
doneRepository: pingcap/docs-cn
Length of output: 5981
🏁 Script executed:
#!/bin/bash
set -e
for path in \
pkg/statistics/handle/ddl/ddl.go \
pkg/statistics/handle/storage/stats_read_writer.go \
pkg/executor/ddl.go \
pkg/ddl/stat.go
do
body="$(curl -fsSL "https://raw.githubusercontent.com/pingcap/tidb/master/$path")"
printf '%s\n' "### $path"
printf '%s' "$body" |
rg -n -i -C 10 'delete|remove|clear|reset|pseudo|analy[sz]|lastanaly|stats.*storage|storage.*stats' |
head -420 || true
doneRepository: pingcap/docs-cn
Length of output: 16785
🏁 Script executed:
#!/bin/bash
set -e
curl -sS -D /tmp/tidb-search-headers \
'https://api.github.com/search/code?q=DropStatsStmt+repo%3Apingcap%2Ftidb' \
-o /tmp/tidb-search-body
printf '%s\n' '--- response status ---'
head -1 /tmp/tidb-search-headers
printf '%s\n' '--- response body ---'
cat /tmp/tidb-search-body
rm -f /tmp/tidb-search-headers /tmp/tidb-search-bodyRepository: pingcap/docs-cn
Length of output: 336
🌐 Web query:
site:github.com/pingcap/tidb/issues "DROP STATS" "Last_analyze_time"
💡 Result:
There is no standard SQL command known as DROP STATS. Based on the provided search results, the term Last_analyze_time is a column found in database statistics metadata tables (such as mysql.stats_meta in TiDB), which tracks when a table's statistics were last updated via an ANALYZE operation [1][2]. The search results discuss the behavior, maintenance, and potential bugs regarding statistics collection and metadata, but do not contain any evidence of a command to drop statistics or interact with the Last_analyze_time column using a DROP STATS syntax [3][1][2]. If you are attempting to remove statistics, you should check your specific database management system's documentation for commands like ANALYZE (to update/refresh) or specific administrative procedures for managing or deleting statistics metadata.
Citations:
- 1: query results of information_schema.tables not accurate tidb#55803
- 2: no need to collect stats and healthy of system table tidb#52040
- 3: modify_count is failing to update, can be smaller than expected tidb#65426
🌐 Web query:
site:github.com/pingcap/docs-cn "DROP STATS" "Last_analyze_time"
💡 Result:
The command DROP STATS is a specific SQL statement used in TiDB to delete table statistics [1][2]. There is no standard command or system variable named Last_analyze_time that is used with DROP STATS. It appears the user may be confusing the DROP STATS command with metadata or status monitoring commands [3]. In TiDB, you can view information about statistics and analyze jobs using: 1. SHOW ANALYZE STATUS: To see the status of statistics collection tasks, including start and end times [3]. 2. Information Schema tables: Such as the ANALYZE_STATUS table, which contains metadata about analyze jobs [3]. If the intention is to delete statistics for a table, the correct syntax is: DROP STATS TableName; [2] To delete statistics for specific partitions or global statistics in a partitioned table, you can use: DROP STATS TableName PARTITION PartitionNameList; [2] DROP STATS TableName GLOBAL; [2][4] If you are looking for the last time a table was analyzed, this information is typically found in the system tables (like mysql.stats_meta) or viewed via statistics-related inspection tools provided by the database, rather than through a DROP command.
Citations:
- 1: https://github.com/pingcap/docs-cn/blob/ed496dc3/statistics.md
- 2: https://github.com/pingcap/docs-cn/blob/814ae5553d48560a618c5e3ddad39bd3a85a2bf7/statistics.md
- 3: https://github.com/pingcap/docs-cn/blob/master/sql-statements/sql-statement-show-analyze-status.md
- 4: 291a277
🌐 Web query:
site:docs.pingcap.com "DROP STATS" "Last_analyze_time" "NULL"
💡 Result:
There is no standard SQL command DROP STATS Last_analyze_time NULL. The DROP STATS statement in TiDB is used to delete all statistics for a specified table, not to reset individual metadata fields like Last_analyze_time [1][2][3]. If you are using TiDB and want to remove statistics for a table, the correct syntax is: DROP STATS TableName; [1][3] Regarding the Last_analyze_time field seen in SHOW STATS_META: - This field is system-generated and reflects the last time an ANALYZE operation was performed on the table [4][5][6]. - When no ANALYZE has been performed, or if statistics have been cleared, this value may appear as NULL [7]. - There is no direct command to manually set or "drop" this specific metadata field to NULL while retaining other statistics [1][8]. If your goal is to have Last_analyze_time appear as NULL, executing DROP STATS on the table will typically remove its statistics record entirely [1][3], which effectively removes the Last_analyze_time value along with all other stats data [7].
Citations:
- 1: https://docs.pingcap.com/tidb/stable/sql-statement-drop-stats/
- 2: https://docs.pingcap.com/tidbcloud/sql-statement-drop-stats/
- 3: https://docs.pingcap.com/tidb/v6.5/sql-statement-drop-stats/
- 4: https://docs.pingcap.com/tidb/stable/sql-statement-show-stats-meta/
- 5: https://docs.pingcap.com/zh/tidb/stable/sql-statement-show-stats-meta/
- 6: https://docs.pingcap.com/ja/tidb/stable/sql-statement-show-stats-meta/
- 7: https://docs.pingcap.com/tidb/stable/sql-statement-flush-stats-delta/
- 8: https://docs.pingcap.com/tidb/stable/sql-statement-overview/
🏁 Script executed:
#!/bin/bash
set -e
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
curl -fsSL 'https://codeload.github.com/pingcap/tidb/tar.gz/refs/heads/master' |
tar -xz -C "$tmpdir"
root="$(find "$tmpdir" -mindepth 1 -maxdepth 1 -type d | head -1)"
printf '%s\n' '--- DropStatsStmt references ---'
rg -n -C 10 'DropStatsStmt|dropStats|DROP STATS|DropStats' "$root/pkg" | head -400
printf '%s\n' '--- stats metadata deletion/reset references ---'
rg -n -i -C 10 'last_analyze_time|lastanaly|delete from mysql\.stats_meta|stats_meta.*delete|delete.*stats_meta|truncate.*stats' "$root/pkg" | head -400Repository: pingcap/docs-cn
Length of output: 50371
🏁 Script executed:
#!/bin/bash
set -e
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
curl -fsSL 'https://codeload.github.com/pingcap/tidb/tar.gz/refs/heads/master' |
tar -xz -C "$tmpdir"
root="$(find "$tmpdir" -mindepth 1 -maxdepth 1 -type d | head -1)"
printf '%s\n' '--- executeDropStats ---'
sed -n '3530,3605p' "$root/pkg/executor/simple.go"
printf '%s\n' '--- soft-delete storage logic ---'
sed -n '125,180p' "$root/pkg/statistics/handle/storage/gc.go"
printf '%s\n' '--- stats load reset logic ---'
sed -n '500,550p' "$root/pkg/statistics/handle/storage/read.go"Repository: pingcap/docs-cn
Length of output: 7250
补充 Last_analyze_time 列。
DROP STATS 后,SHOW STATS_META 仍返回七列;未分析统计信息时,Last_analyze_time 为 NULL。
| +---------+------------+----------------+---------------------+--------------+-----------+ | |
| | Db_name | Table_name | Partition_name | Update_time | Modify_count | Row_count | | |
| +---------+------------+----------------+---------------------+--------------+-----------+ | |
| | test | t | | 2020-05-25 20:34:33 | 0 | 0 | | |
| +---------+------------+----------------+---------------------+--------------+-----------+ | |
| 1 row in set (0.00 sec) | |
| +---------+------------+----------------+---------------------+--------------+-----------+---------------------+ | |
| | Db_name | Table_name | Partition_name | Update_time | Modify_count | Row_count | Last_analyze_time | | |
| +---------+------------+----------------+---------------------+--------------+-----------+---------------------+ | |
| | test | t | | 2020-05-25 20:34:33 | 0 | 0 | NULL | | |
| +---------+------------+----------------+---------------------+--------------+-----------+---------------------+ | |
| 1 row in set (0.00 sec) |
Source: Path instructions
What is changed, added or deleted? (Required)
pingcap/docs#23557的修订,说明DROP STATS会清除直方图相关统计信息,但不会删除STATS_META对应行。DROP STATS后,SHOW STATS_META仍会返回 row count 和 modify count。Which TiDB version(s) do your changes apply to? (Required)
What is the related PR or file link(s)?
AI agent involvement
Do your changes match any of the following descriptions?