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

*: support IF EXISTS/IF NOT EXISTS for some DDLs #10723

Merged
merged 13 commits into from
Jun 24, 2019

Conversation

csuzhangxc
Copy link
Member

@csuzhangxc csuzhangxc commented Jun 5, 2019

What problem does this PR solve?

update parser to include pingcap/parser#337, and make some IF EXISTS/IF NOT EXISTS clauses work.

What is changed and how it works?

  1. check IF EXISTS for
    1. DROP COLUMN
    2. CHANGE COLUMN
    3. MODIFY COLUMN
    4. DROP INDEX
    5. DROP PARTITION
  2. add IF NOT EXISTS for
    1. ADD COLUMN
    2. ADD INDEX
    3. CREATE INDEX
    4. ADD PARTITION

Check List

Tests

  • Unit test

Code changes

  • Has exported function/method change
  • Has interface methods change

@CLAassistant
Copy link

CLAassistant commented Jun 5, 2019

CLA assistant check
All committers have signed the CLA.

@csuzhangxc
Copy link
Member Author

@winkyao @tiancaiamao PTAL

Copy link
Contributor

@tiancaiamao tiancaiamao left a comment

Choose a reason for hiding this comment

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

Maybe we have to check the EXISTS/NOT EXISTS both in ddl_api.go and ddl.go, in the DDL owner.
If we just check in the ddl_api.go, the information may be stale.

ddl/db_change_test.go Show resolved Hide resolved
ddl/db_test.go Show resolved Hide resolved
@tiancaiamao
Copy link
Contributor

CI fail @csuzhangxc

@csuzhangxc
Copy link
Member Author

Maybe we have to check the EXISTS/NOT EXISTS both in ddl_api.go and ddl.go, in the DDL owner.
If we just check in the ddl_api.go, the information may be stale.

@tiancaiamao DDL owner already checked exists/not exists before this PR, and it will return an error if possible, in this PR, we handled the returned err of doDDLJob. I think it's enough, right?

@csuzhangxc
Copy link
Member Author

CI fail @csuzhangxc

@tiancaiamao I'll fix CI (because tidy failed) after pingcap/parser#337 merged.

ddl/ddl_api.go Show resolved Hide resolved
ddl/ddl_api.go Show resolved Hide resolved
ddl/ddl.go Show resolved Hide resolved
ddl/ddl_api.go Show resolved Hide resolved
ddl/ddl_api.go Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Jun 13, 2019

Codecov Report

Merging #10723 into master will decrease coverage by 0.1042%.
The diff coverage is 88.6075%.

@@               Coverage Diff               @@
##            master     #10723        +/-   ##
===============================================
- Coverage   80.854%   80.7498%   -0.1043%     
===============================================
  Files          420        420                
  Lines        89147      89215        +68     
===============================================
- Hits         72079      72041        -38     
- Misses       11822      11948       +126     
+ Partials      5246       5226        -20

@csuzhangxc
Copy link
Member Author

/run-all-tests

@winkyao winkyao removed the require-LGT3 Indicates that the PR requires three LGTM. label Jun 13, 2019
@tiancaiamao
Copy link
Contributor

LGTM

@tiancaiamao tiancaiamao added status/LGT1 Indicates that a PR has LGTM 1. status/all tests passed labels Jun 13, 2019
@csuzhangxc
Copy link
Member Author

@winkyao @crazycs520 PTAL

@@ -3023,6 +3084,10 @@ func (d *ddl) CreateIndex(ctx sessionctx.Context, ti ast.Ident, unique bool, ind
}

err = d.doDDLJob(ctx, job)
// key exists, but if_not_exists flags is true, so we ignore this error.
if ErrDupKeyName.Equal(err) && ifNotExists {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to report the warning here?

Copy link
Member Author

Choose a reason for hiding this comment

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

done in 0d609e3.

@@ -3132,6 +3202,10 @@ func (d *ddl) DropIndex(ctx sessionctx.Context, ti ast.Ident, indexName model.CI
}

err = d.doDDLJob(ctx, job)
// index not exists, but if_exists flags is true, so we ignore this error.
if ErrCantDropFieldOrKey.Equal(err) && ifExists {
Copy link
Contributor

Choose a reason for hiding this comment

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

report warning here?

Copy link
Member Author

Choose a reason for hiding this comment

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

done in 0d609e3.

ddl/ddl_api.go Show resolved Hide resolved
// CREATE INDEX
sql = "create index idx_b on t1 (b)"
assertErrorCode(c, s.tk, sql, tmysql.ErrDupKeyName)
s.mustExec(c, "create index if not exists idx_b on t1 (b)")
Copy link
Contributor

Choose a reason for hiding this comment

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

Check the result of show warnings?

Copy link
Member Author

Choose a reason for hiding this comment

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

done in 2769cf1.

Copy link
Contributor

@XuHuaiyu XuHuaiyu left a comment

Choose a reason for hiding this comment

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

LGTM

@tiancaiamao
Copy link
Contributor

Please fix conflicts @csuzhangxc

@tiancaiamao
Copy link
Contributor

/run-all-tests

@tiancaiamao
Copy link
Contributor

/run-unit-test

@tiancaiamao tiancaiamao merged commit a935d93 into pingcap:master Jun 24, 2019
@csuzhangxc csuzhangxc deleted the alter-if-exists branch June 24, 2019 11:48
@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
component/parser sig/sql-infra SIG: SQL Infra status/LGT1 Indicates that a PR has LGTM 1. type/new-feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants