Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddl: fix ddl modify column from null to not null bug: check null value again before change to no null #10948

Merged
merged 14 commits into from
Jul 3, 2019

Conversation

crazycs520
Copy link
Contributor

@crazycs520 crazycs520 commented Jun 26, 2019

What problem does this PR solve?

Fix bug of modifying column from null to not null.

Origin logic:
null -> check column null value count is 0 -> set prevent-null-flag -> not null.

The problem is after setting prevent-null-flag, but before TiDB wait schema changed, insert null will success. And we should check check column null value count is 0 again before changing to not null.

Current logic:

null -> check column null value count is 0 -> set prevent null flag -> check column null value count is 0 -> not null.

What is changed and how it works?

Check List

Tests

  • Unit test

Code changes

  • Has exported function/method change

Side effects

  • Possible performance regression

Related changes

  • Need to cherry-pick to the release branch

@crazycs520
Copy link
Contributor Author

/run-all-tests

@codecov
Copy link

codecov bot commented Jun 26, 2019

Codecov Report

Merging #10948 into master will decrease coverage by 0.0108%.
The diff coverage is 90.909%.

@@               Coverage Diff                @@
##             master     #10948        +/-   ##
================================================
- Coverage   81.0123%   81.0015%   -0.0109%     
================================================
  Files           419        418         -1     
  Lines         89379      89265       -114     
================================================
- Hits          72408      72306       -102     
+ Misses        11749      11727        -22     
- Partials       5222       5232        +10

@crazycs520
Copy link
Contributor Author

/run-all-tests

@crazycs520 crazycs520 changed the title ddl: fix ddl modify column from null to not null bug ddl: fix ddl modify column from null to not null bug: check null value again before change to no null Jun 26, 2019
Copy link
Contributor

@winkyao winkyao left a comment

Choose a reason for hiding this comment

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

LGTM

ddl/column.go Outdated Show resolved Hide resolved
ddl/db_test.go Outdated Show resolved Hide resolved
ddl/db_test.go Outdated Show resolved Hide resolved
@winkyao winkyao added priority/release-blocker This issue blocks a release. Please solve it ASAP. v3.0 and removed v3.0 labels Jul 2, 2019
Copy link
Member

@bb7133 bb7133 left a comment

Choose a reason for hiding this comment

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

LGTM

@bb7133 bb7133 added the status/LGT2 Indicates that a PR has LGTM 2. label Jul 2, 2019
ddl/column.go Outdated
if !mysql.HasNotNullFlag(oldCol.Flag) && mysql.HasNotNullFlag(newCol.Flag) && !mysql.HasPreventNullInsertFlag(oldCol.Flag) {
// Column from null to not null.
if !mysql.HasNotNullFlag(oldCol.Flag) && mysql.HasNotNullFlag(newCol.Flag) {
noPreventNullFlag := !mysql.HasPreventNullInsertFlag(oldCol.Flag)
// Introduce the `mysql.HasPreventNullInsertFlag` flag to prevent users from inserting or updating null values.
ver, err = modifyColumnFromNull2NotNull(w, t, dbInfo, tblInfo, job, oldCol, newCol)
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that if noPreventNullFlag is false, we only need to do checkForNullValue. In other words, we needn't do updateVersionAndTableInfoWithCheck. Do we change this code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great, Thanks.

ddl/db_test.go Outdated
}
c2 := getModifyColumn()
if mysql.HasPreventNullInsertFlag(c2.Flag) {
_, err := s.tk.Exec("insert into t1 values ();")
Copy link
Contributor

Choose a reason for hiding this comment

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

Using tk2 is better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ye~, Thanks.

Copy link
Contributor

@zimulala zimulala left a comment

Choose a reason for hiding this comment

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

LGTM

@zimulala
Copy link
Contributor

zimulala commented Jul 3, 2019

/run-all-tests

@crazycs520 crazycs520 merged commit 1061d2a into pingcap:master Jul 3, 2019
@crazycs520 crazycs520 deleted the fix-null-to-notnull branch July 3, 2019 02:12
crazycs520 added a commit to crazycs520/tidb that referenced this pull request Nov 18, 2019
crazycs520 added a commit to crazycs520/tidb that referenced this pull request Nov 18, 2019
zimulala pushed a commit that referenced this pull request Nov 19, 2019
@you06 you06 added the sig/sql-infra SIG: SQL Infra label Mar 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority/release-blocker This issue blocks a release. Please solve it ASAP. sig/sql-infra SIG: SQL Infra status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants