Skip to content

planner,executor,variable: warn and deprecate analyze v1 usage#66584

Merged
ti-chi-bot[bot] merged 7 commits intopingcap:release-8.5from
0xPoe:poe-patch-v85-stats-v1
Mar 2, 2026
Merged

planner,executor,variable: warn and deprecate analyze v1 usage#66584
ti-chi-bot[bot] merged 7 commits intopingcap:release-8.5from
0xPoe:poe-patch-v85-stats-v1

Conversation

@0xPoe
Copy link
Copy Markdown
Member

@0xPoe 0xPoe commented Feb 27, 2026

What problem does this PR solve?

Issue Number: ref #63579

Problem Summary:
tidb_analyze_version=1 deprecation was not clearly surfaced when running ANALYZE.

What changed and how does it work?

  • Add a deprecation warning when setting tidb_analyze_version=1.
  • Add a deprecation warning when ANALYZE runs with effective analyze version 1.
  • Add/update tests for both warning paths.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

ANALYZE now emits a deprecation warning when running with tidb_analyze_version=1.

Summary by CodeRabbit

  • New Features
    • ANALYZE now emits a deprecation warning when tidb_analyze_version=1 is used across table, partition, index, and composite analyze paths; migrate to version 2+.
    • Setting tidb_analyze_version to "1" now triggers the same deprecation warning at validation time.
  • Tests
    • Test suite updated to expect and validate the new deprecation warnings and warning handling.

@ti-chi-bot ti-chi-bot bot added do-not-merge/cherry-pick-not-approved release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. sig/planner SIG: Planner labels Feb 27, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 27, 2026

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

Emit a deprecation warning whenever ANALYZE runs with tidb_analyze_version=1: planner now emits the warning during analyze plan construction, the TiDBAnalyzeVersion sysvar Validation warns on "1", and tests across executor, varsutil, planner, and statistics are updated to expect the additional deprecation warning.

Changes

Cohort / File(s) Summary
Plan builder
pkg/planner/core/planbuilder.go
Add appendAnalyzeV1DeprecationWarning and call it in analyze plan-building paths so ANALYZE v1 emits a deprecation warning.
System variable
pkg/sessionctx/variable/sysvar.go
Add Validation callback to TiDBAnalyzeVersion that appends a deprecation warning when the normalized value is "1".
Executor & integration tests
pkg/executor/test/analyzetest/analyze_test.go, pkg/statistics/integration_test.go, tests/integrationtest/r/planner/core/indexmerge_path.result
Update test expectations and recorded results to include the new deprecation warning emitted when using analyze version 1.
Planner tests
pkg/planner/core/casetest/index/index_test.go, pkg/planner/core/indexmerge_path_test.go
Expect an additional deprecation warning (Warning 1681) in various ANALYZE table/index test cases.
Vars util tests
pkg/sessionctx/variable/varsutil_test.go
Add test path asserting the sysvar emits the deprecation warning when set to "1" and adjust warning handling.
Lock stats tests
pkg/statistics/handle/handletest/lockstats/lock_table_stats_test.go
Include the deprecation warning in expected warnings after analyzing multiple tables with analyze v1.

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

component/statistics, size/L, ok-to-test

Suggested reviewers

  • hawkingrei
  • henrybw

Poem

🐰 I sniffed a warning in the stats' soft rain,
Old version one will hop off the plain.
Planner whispers, sysvar taps the bell,
Tests wake up and note the tell,
Thump-thump, I celebrate the change!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: warning and deprecating analyze v1 usage across planner, executor, and variable modules.
Description check ✅ Passed The description is comprehensive, including issue reference, clear problem statement, explanation of changes, and completed checklist with appropriate test and documentation selections.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
pkg/sessionctx/variable/varsutil_test.go (1)

426-436: Guard warning-slice indexing with an explicit length assertion.

At Line 426 and Line 435, GetWarnings()[0] is read directly. Add require.Len(...) first for clearer failures.

💡 Suggested tweak
 err = v.SetSystemVar(TiDBAnalyzeVersion, "1")
 require.NoError(t, err)
+require.Len(t, v.StmtCtx.GetWarnings(), 1)
 warn := v.StmtCtx.GetWarnings()[0]
 require.Error(t, warn.Err)
 require.Equal(t, "[variable:1287]'tidb_analyze_version=1' is deprecated and will be removed in a future release. Please use tidb_analyze_version=2 instead", warn.Err.Error())
@@
 err = v.SetSystemVar(TiDBAnalyzeVersion, "4")
 require.NoError(t, err) // converts to max value
+require.Len(t, v.StmtCtx.GetWarnings(), 1)
 warn = v.StmtCtx.GetWarnings()[0]
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/sessionctx/variable/varsutil_test.go` around lines 426 - 436, The test
reads v.StmtCtx.GetWarnings()[0] without checking length; add explicit length
assertions before each indexing to avoid panics: call require.Len(t,
v.StmtCtx.GetWarnings(), 1) (or require.Greater/NotEmpty as appropriate)
immediately before the first warn := v.StmtCtx.GetWarnings()[0] and again before
the second warn := v.StmtCtx.GetWarnings()[0] after
SetSystemVar(TiDBAnalyzeVersion, "4"); keep existing checks
(require.Error/Equal) unchanged and ensure TruncateWarnings(0) still verifies
zero length with require.Len(..., 0).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@pkg/sessionctx/variable/varsutil_test.go`:
- Around line 426-436: The test reads v.StmtCtx.GetWarnings()[0] without
checking length; add explicit length assertions before each indexing to avoid
panics: call require.Len(t, v.StmtCtx.GetWarnings(), 1) (or
require.Greater/NotEmpty as appropriate) immediately before the first warn :=
v.StmtCtx.GetWarnings()[0] and again before the second warn :=
v.StmtCtx.GetWarnings()[0] after SetSystemVar(TiDBAnalyzeVersion, "4"); keep
existing checks (require.Error/Equal) unchanged and ensure TruncateWarnings(0)
still verifies zero length with require.Len(..., 0).

ℹ️ Review info

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c6bccde and 564ae2e.

📒 Files selected for processing (4)
  • pkg/executor/test/analyzetest/analyze_test.go
  • pkg/planner/core/planbuilder.go
  • pkg/sessionctx/variable/sysvar.go
  • pkg/sessionctx/variable/varsutil_test.go

Signed-off-by: 0xPoe <techregister@pm.me>
Signed-off-by: 0xPoe <techregister@pm.me>
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (release-8.5@c6bccde). Learn more about missing BASE report.

Additional details and impacted files
@@               Coverage Diff                @@
##             release-8.5     #66584   +/-   ##
================================================
  Coverage               ?   54.9992%           
================================================
  Files                  ?       1818           
  Lines                  ?     652289           
  Branches               ?          0           
================================================
  Hits                   ?     358754           
  Misses                 ?     267021           
  Partials               ?      26514           
Flag Coverage Δ
integration 38.3848% <100.0000%> (?)
unit 65.0163% <100.0000%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 52.9278% <0.0000%> (?)
parser ∅ <0.0000%> (?)
br 55.4872% <0.0000%> (?)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Signed-off-by: 0xPoe <techregister@pm.me>
Signed-off-by: 0xPoe <techregister@pm.me>
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

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 the current code and only fix it if needed.

Inline comments:
In `@pkg/statistics/handle/handletest/lockstats/lock_table_stats_test.go`:
- Around line 216-219: The assertions that check SQL warnings in the tests that
call setupTestEnvironmentWithTableT() must include the deprecation warning 1681
in addition to the skip-analyze warning 1105; locate the tk.MustQuery("show
warnings").Check(...) calls in lock_table_stats_test.go that follow analyze
table invocations (those using setupTestEnvironmentWithTableT()) and update
their expected rows to include both "Warning 1681 ANALYZE with
tidb_analyze_version=1 is deprecated..." and "Warning 1105 skip analyze locked
tables: ..." in the same order as the other test block (matching the Check used
in the block that already includes both warnings).

ℹ️ Review info

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 69c1cdb and 873c5f2.

📒 Files selected for processing (1)
  • pkg/statistics/handle/handletest/lockstats/lock_table_stats_test.go

Comment on lines 216 to 219
tk.MustQuery("show warnings").Check(testkit.Rows(
"Warning 1681 ANALYZE with tidb_analyze_version=1 is deprecated and will be removed in a future release.",
"Warning 1105 skip analyze locked tables: test.t1, test.t2",
))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find all warning assertions in the test file to check for inconsistencies
rg -n "show warnings.*Check" pkg/statistics/handle/handletest/lockstats/lock_table_stats_test.go -A 3

Repository: pingcap/tidb

Length of output: 1044


🏁 Script executed:

#!/bin/bash
# Check the setup and analyze calls in the first two test functions
sed -n '45,60p' pkg/statistics/handle/handletest/lockstats/lock_table_stats_test.go
sed -n '95,115p' pkg/statistics/handle/handletest/lockstats/lock_table_stats_test.go
# Also check the test function that has the new warning (to see its setup)
sed -n '168,225p' pkg/statistics/handle/handletest/lockstats/lock_table_stats_test.go

Repository: pingcap/tidb

Length of output: 3667


🏁 Script executed:

#!/bin/bash
# Find the setupTestEnvironmentWithTableT function definition
rg -n "func setupTestEnvironmentWithTableT" pkg/statistics/handle/handletest/lockstats/lock_table_stats_test.go -A 30

Repository: pingcap/tidb

Length of output: 699


Other tests using tidb_analyze_version=1 should also expect the deprecation warning.

Tests at lines 54-56 and 104-106 both:

  • Use setupTestEnvironmentWithTableT() which sets @@tidb_analyze_version = 1 (line 372)
  • Execute analyze table commands on locked tables
  • Check the resulting warnings

These tests currently only expect Warning 1105 (skip analyze locked tables), but since they analyze with version 1, they should also expect Warning 1681 (deprecation warning) to match the expectation at lines 216-219. Update these assertions to include the deprecation warning.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/statistics/handle/handletest/lockstats/lock_table_stats_test.go` around
lines 216 - 219, The assertions that check SQL warnings in the tests that call
setupTestEnvironmentWithTableT() must include the deprecation warning 1681 in
addition to the skip-analyze warning 1105; locate the tk.MustQuery("show
warnings").Check(...) calls in lock_table_stats_test.go that follow analyze
table invocations (those using setupTestEnvironmentWithTableT()) and update
their expected rows to include both "Warning 1681 ANALYZE with
tidb_analyze_version=1 is deprecated..." and "Warning 1105 skip analyze locked
tables: ..." in the same order as the other test block (matching the Check used
in the block that already includes both warnings).

@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 27, 2026
@0xPoe
Copy link
Copy Markdown
Member Author

0xPoe commented Feb 27, 2026

/retest

Copy link
Copy Markdown
Member Author

@0xPoe 0xPoe left a comment

Choose a reason for hiding this comment

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

🔢 Self-check (PR reviewed by myself and ready for feedback)

  • Code compiles successfully

  • Unit tests added

  • No AI-generated elegant nonsense in PR.

  • Bazel files updated

  • Comments added where necessary

  • PR title and description updated

  • Documentation PR created (or confirmed not needed)

  • PR size is reasonable

/cc @terry1purcell @qw4990

@ti-chi-bot ti-chi-bot bot requested review from qw4990 and terry1purcell February 27, 2026 19:28
Copy link
Copy Markdown
Contributor

@fixdb fixdb left a comment

Choose a reason for hiding this comment

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

+1

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Feb 27, 2026
@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Feb 27, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot bot commented Feb 27, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-02-27 19:36:07.950335098 +0000 UTC m=+38391.869501182: ☑️ agreed by fixdb.
  • 2026-02-27 21:17:29.494065795 +0000 UTC m=+44473.413231867: ☑️ agreed by terry1purcell.

Copy link
Copy Markdown

@yudongusa yudongusa left a comment

Choose a reason for hiding this comment

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

please open a document PR

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot bot commented Feb 27, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fixdb, terry1purcell, yudongusa

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

The pull request process is described 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 the approved label Feb 27, 2026
@ti-chi-bot ti-chi-bot bot added cherry-pick-approved Cherry pick PR approved by release team. and removed do-not-merge/cherry-pick-not-approved labels Mar 2, 2026
@0xPoe
Copy link
Copy Markdown
Member Author

0xPoe commented Mar 2, 2026

/retest

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

Labels

approved cherry-pick-approved Cherry pick PR approved by release team. lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/planner SIG: Planner size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants