tidb icon indicating copy to clipboard operation
tidb copied to clipboard

ddl, model: fix unexpected missing analyze for multi schema change

Open joechenrh opened this issue 1 month ago • 22 comments

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 NeedAnalyze since 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

  1. move a bunch of function, variables related to modify column from ddl to model package.
  2. Replace CtxVars with boolean value, as it's used by MODIFY COLUMN and store a single bool.
  3. 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

joechenrh avatar Nov 07 '25 06:11 joechenrh

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.

tiprow[bot] avatar Nov 07 '25 06:11 tiprow[bot]

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.

codecov[bot] avatar Nov 07 '25 06:11 codecov[bot]

/ok-to-test

joechenrh avatar Nov 07 '25 07:11 joechenrh

[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

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[bot] avatar Nov 24 '25 10:11 ti-chi-bot[bot]

[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.

ti-chi-bot[bot] avatar Nov 24 '25 10:11 ti-chi-bot[bot]

/hold There may be something wrong with this PR.

joechenrh avatar Nov 25 '25 03:11 joechenrh

/unhold It's the expected behavior that the column without index is not analyzed.

joechenrh avatar Dec 08 '25 05:12 joechenrh

/retest

joechenrh avatar Dec 08 '25 05:12 joechenrh

/retest

joechenrh avatar Dec 08 '25 07:12 joechenrh

/retest

joechenrh avatar Dec 08 '25 08:12 joechenrh

/retest

joechenrh avatar Dec 08 '25 11:12 joechenrh

/retest

joechenrh avatar Dec 09 '25 01:12 joechenrh

/retest

joechenrh avatar Dec 09 '25 05:12 joechenrh

/retest

joechenrh avatar Dec 11 '25 03:12 joechenrh

/retest

joechenrh avatar Dec 11 '25 05:12 joechenrh

/retest

joechenrh avatar Dec 11 '25 09:12 joechenrh

/retest

joechenrh avatar Dec 11 '25 10:12 joechenrh

/retest

joechenrh avatar Dec 11 '25 11:12 joechenrh

/retest

joechenrh avatar Dec 11 '25 12:12 joechenrh

/retest

joechenrh avatar Dec 11 '25 13:12 joechenrh

/retest

joechenrh avatar Dec 11 '25 14:12 joechenrh

/retest

joechenrh avatar Dec 12 '25 01:12 joechenrh

/retest

joechenrh avatar Dec 12 '25 04:12 joechenrh

/retest

joechenrh avatar Dec 12 '25 06:12 joechenrh

/retest

hawkingrei avatar Dec 12 '25 07:12 hawkingrei

@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.

tiprow[bot] avatar Dec 12 '25 07:12 tiprow[bot]

In response to a cherrypick label: new pull request created to branch release-8.5: #65005. But this PR has conflicts, please resolve them!

ti-chi-bot avatar Dec 12 '25 07:12 ti-chi-bot