-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Conversation
/run-all-tests |
Codecov Report
@@ 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 |
/run-all-tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this 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
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 ();") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using tk2
is better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ye~, Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/run-all-tests |
…e again before change to no null (pingcap#10948)
…e again before change to no null (pingcap#10948)
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 tonot 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
Code changes
Side effects
Related changes