-
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
*: support IF EXISTS/IF NOT EXISTS for some DDLs #10723
Conversation
@winkyao @tiancaiamao PTAL |
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.
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.
CI fail @csuzhangxc |
@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 |
@tiancaiamao I'll fix CI (because tidy failed) after pingcap/parser#337 merged. |
Codecov Report
@@ 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 |
…ists # Conflicts: # go.mod # go.sum
/run-all-tests |
LGTM |
@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 { |
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.
Do we need to report the warning here?
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.
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 { |
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.
report warning here?
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.
done in 0d609e3.
// 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)") |
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.
Check the result of show warnings
?
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.
done in 2769cf1.
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
Please fix conflicts @csuzhangxc |
/run-all-tests |
/run-unit-test |
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?
IF EXISTS
forDROP COLUMN
CHANGE COLUMN
MODIFY COLUMN
DROP INDEX
DROP PARTITION
IF NOT EXISTS
forADD COLUMN
ADD INDEX
CREATE INDEX
ADD PARTITION
Check List
Tests
Code changes