-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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 drop index failed when index contain auto_increment column and more than 2 index contain auto_increment_column #12230
Conversation
…nd more than 2 index contain auto_increment_column
Codecov Report
@@ Coverage Diff @@
## master #12230 +/- ##
================================================
+ Coverage 81.0765% 81.3147% +0.2382%
================================================
Files 454 457 +3
Lines 99247 101647 +2400
================================================
+ Hits 80466 82654 +2188
- Misses 12963 13138 +175
- Partials 5818 5855 +37 |
ddl/ddl_api.go
Outdated
continue | ||
} | ||
count++ | ||
break |
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.
I think we can change this code as follows:
if c.Name.L == colName {
count++
break
}
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, Done.
ddl/ddl_api.go
Outdated
@@ -3422,6 +3423,20 @@ func (d *ddl) DropIndex(ctx sessionctx.Context, ti ast.Ident, indexName model.CI | |||
return errors.Trace(err) | |||
} | |||
|
|||
func countOfIndexContainColumn(tblInfo *model.TableInfo, colName string) int { |
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.
Could we put this function to index.go?
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, Done.
cols := t.Cols() | ||
for _, idxCol := range indexInfo.Columns { | ||
if mysql.HasAutoIncrementFlag(cols[idxCol.Offset].Flag) { | ||
if mysql.HasAutoIncrementFlag(cols[idxCol.Offset].Flag) && countOfIndexContainColumn(t.Meta(), idxCol.Name.L) < 2 { | ||
return autoid.ErrWrongAutoKey | ||
} | ||
} |
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.
Could we extract this code(line3400-3405) directly into a function instead of using countOfIndexContainColumn
?
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, Done.
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
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
cherry pick to release-2.1 failed |
cherry pick to release-3.0 in PR #12344 |
cherry pick to release-3.1 in PR #12345 |
It seems that, not for sure, we failed to cherry-pick this commit to release-2.1. Please comment '/run-cherry-picker' to try to trigger the cherry-picker if we did fail to cherry-pick this commit before. @crazycs520 PTAL. |
…nd more than 2 index contain auto_increment_column (pingcap#12230) Signed-off-by: crazycs520 <[email protected]>
What problem does this PR solve?
What is changed and how it works?
Check List
Tests
Code changes
Side effects
Related changes
Release note
drop index
on auto_increment column failed when table has more than 2 indexes that contain auto_increment column.