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 drop index failed when index contain auto_increment column and more than 2 index contain auto_increment_column #12230

Merged
merged 16 commits into from
Sep 24, 2019

Conversation

crazycs520
Copy link
Contributor

@crazycs520 crazycs520 commented Sep 17, 2019

What problem does this PR solve?

create table t (a int auto_increment,b int, unique index (a));
alter table t add index (a,b);
alter table t drop index a; – should execute successful, mysql will sucess.
(1075, u'Incorrect table definition; there can be only one auto column and it must be defined as a key')

What is changed and how it works?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)

Code changes

  • Has exported function/method change

Side effects

Related changes

  • Need to cherry-pick to the release branch

Release note

  • DDL: Fix the issue that drop index on auto_increment column failed when table has more than 2 indexes that contain auto_increment column.

…nd more than 2 index contain auto_increment_column
@sre-bot
Copy link
Contributor

sre-bot commented Sep 17, 2019

Thanks for your PR.
This PR will be closed by bot because you already had 3 opened PRs, close or merge them before submitting a new one.
#12179 , #12193 , #12213

@codecov
Copy link

codecov bot commented Sep 17, 2019

Codecov Report

Merging #12230 into master will increase coverage by 0.2382%.
The diff coverage is n/a.

@@               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
Copy link
Contributor

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
			}

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, 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 {
Copy link
Contributor

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?

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, 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
}
}
Copy link
Contributor

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 ?

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, Done.

@bb7133 bb7133 added status/LGT2 Indicates that a PR has LGTM 2. needs-cherry-pick-2.1 labels Sep 18, 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 status/LGT1 Indicates that a PR has LGTM 1. and removed status/LGT2 Indicates that a PR has LGTM 2. labels Sep 18, 2019
AilinKid
AilinKid previously approved these changes Sep 18, 2019
Copy link
Contributor

@AilinKid AilinKid left a comment

Choose a reason for hiding this comment

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

LGTM

@AilinKid AilinKid added status/LGT3 The PR has already had 3 LGTM. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Sep 18, 2019
@AilinKid AilinKid dismissed their stale review September 18, 2019 08:31

still need a lgtm

@AilinKid AilinKid added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT3 The PR has already had 3 LGTM. labels Sep 18, 2019
Copy link
Contributor

@tangenta tangenta left a comment

Choose a reason for hiding this comment

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

LGTM

@crazycs520 crazycs520 merged commit 2f70d38 into pingcap:master Sep 24, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Sep 24, 2019

cherry pick to release-2.1 failed

@sre-bot
Copy link
Contributor

sre-bot commented Sep 24, 2019

cherry pick to release-3.0 in PR #12344

@sre-bot
Copy link
Contributor

sre-bot commented Sep 24, 2019

cherry pick to release-3.1 in PR #12345

sre-bot added a commit that referenced this pull request Sep 24, 2019
…nd more than 2 index contain auto_increment_column (#12230) (#12345)
sre-bot added a commit that referenced this pull request Sep 24, 2019
…nd more than 2 index contain auto_increment_column (#12230) (#12344)
@sre-bot
Copy link
Contributor

sre-bot commented Apr 7, 2020

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.

crazycs520 added a commit to crazycs520/tidb that referenced this pull request Apr 9, 2020
…nd more than 2 index contain auto_increment_column (pingcap#12230)

Signed-off-by: crazycs520 <crazycs520@gmail.com>
bb7133 pushed a commit that referenced this pull request Apr 14, 2020
…nd more than 2 index contain auto_increment_column (#12230) (#15861) (#16247)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

6 participants