ddl, model: fix unexpected missing analyze for multi schema change
What problem does this PR solve?
Issue Number: ref https://github.com/pingcap/tidb/issues/63366
Problem Summary:
If the last sub job in the multi schema change doesn't need reorg (i.e., no index involved), the analyze task will be skipped.
Take the following SQL as example, since c2 has no index on it, the state is directly converted to AnalyzeStateSkipped, even if modifying c1 requires reorg.
create table t2(id int, c1 int, c2 int, index i1(c1));
alter table t2 modify column c1 char(16), modify column c2 char(16);
c1: ReorgStageModifyColumnCompleted -> AnalyzeStateSkipped
(NeedAnalyze == false)
c2: ReorgStageModifyColumnCompleted -> AnalyzeStateSkipped
(NeedAnalyze == true & len(changingIdx) == 0)
What changed and how does it work?
The problems is caused by inaccurate value for SubJob.NeedAnalyze. That is, the last job with NeedAnalyze == true is not the last job that does reorg. To fix this:
- Remove
NeedAnalyzesince it's not accurate. - For sub jobs, they are converted into non-revertible state after reorg is finished.
- For multi schema change, the analyze is done in the parent job after all sub jobs are non-revertible.
This PR also do the following things
- move a bunch of function, variables related to modify column from
ddltomodelpackage. - Replace
CtxVarswith boolean value, as it's used byMODIFY COLUMNand store a single bool. - filter out temporary columns from the display information of analyze. Previously, we may get output like:
auto analyze table all indexes, columns a, b, c,_Col$_c_0 with 256 buckets, 100 topn, 1 samplerate
Check List
Tests
- [X] 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
Please refer to Release Notes Language Style Guide to write a quality release note.
None
Hi @joechenrh. Thanks for your PR.
PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.
I understand the commands that are listed here.
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.
Codecov Report
:x: Patch coverage is 81.53153% with 41 lines in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 71.2997%. Comparing base (5215e99) to head (b72d994).
:warning: Report is 157 commits behind head on master.
Additional details and impacted files
@@ Coverage Diff @@
## master #64337 +/- ##
================================================
- Coverage 72.7418% 71.2997% -1.4422%
================================================
Files 1859 1889 +30
Lines 504114 537361 +33247
================================================
+ Hits 366702 383137 +16435
- Misses 115137 129570 +14433
- Partials 22275 24654 +2379
| Flag | Coverage Δ | |
|---|---|---|
| integration | 48.4386% <66.6666%> (?) |
|
| unit | 66.3410% <81.5315%> (-5.9704%) |
:arrow_down: |
Flags with carried forward coverage won't be shown. Click here to find out more.
| Components | Coverage Δ | |
|---|---|---|
| dumpling | 52.8700% <ø> (ø) |
|
| parser | ∅ <ø> (∅) |
|
| br | 56.8378% <ø> (+10.4874%) |
:arrow_up: |
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
/ok-to-test
[APPROVALNOTIFIER] This PR is APPROVED
This pull-request has been approved by: fzzf678, wjhuang2016
The full list of commands accepted by this bot can be found here.
The pull request process is described here
- ~~OWNERS~~ [wjhuang2016]
- ~~pkg/ddl/OWNERS~~ [wjhuang2016]
- ~~pkg/meta/OWNERS~~ [wjhuang2016]
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment
[LGTM Timeline notifier]
Timeline:
2025-11-20 02:12:14.607303954 +0000 UTC m=+150498.256498410: :ballot_box_with_check: agreed by fzzf678.2025-11-24 10:18:55.001040606 +0000 UTC m=+525298.650235063: :ballot_box_with_check: agreed by wjhuang2016.
/hold There may be something wrong with this PR.
/unhold It's the expected behavior that the column without index is not analyzed.
/retest
/retest
/retest
/retest
/retest
/retest
/retest
/retest
/retest
/retest
/retest
/retest
/retest
/retest
/retest
/retest
/retest
/retest
@joechenrh: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:
| Test name | Commit | Details | Required | Rerun command |
|---|---|---|---|---|
| tidb_parser_test | b72d9942204db03afc4700ce8b1c06ad8e53f3ad | link | true | /test tidb_parser_test |
| fast_test_tiprow | b72d9942204db03afc4700ce8b1c06ad8e53f3ad | link | true | /test fast_test_tiprow |
Full PR test history. Your PR dashboard.
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. I understand the commands that are listed here.
In response to a cherrypick label: new pull request created to branch release-8.5: #65005.
But this PR has conflicts, please resolve them!