exit early when IF NOT EXISTS and table exists#2387
Merged
Conversation
fulghum
approved these changes
Mar 12, 2024
Contributor
fulghum
left a comment
There was a problem hiding this comment.
Looks good! Just one question on the error message change.
| if data.indexes[name] != nil { | ||
| // TODO: extract a standard error type for this | ||
| return nil, fmt.Errorf("Error: index already exists") | ||
| return nil, sql.ErrDuplicateKey.New(name) |
Contributor
There was a problem hiding this comment.
Looks like the error message changed; was "index already exists" not accurate or are we just trying to match MySQL's message closer? If the latter... the error message I got from MySQL when I tried to create a new index using an existing index name was:
`foo` already exists as an index for this table
Contributor
Author
There was a problem hiding this comment.
this is the output I got from mysql
mysql> create table t (i int, index (i));
Query OK, 0 rows affected (0.0254 sec)
mysql> create index i on t(i);
ERROR: 1061: Duplicate key name 'i'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses various issues related to
CREATE TABLE IF NOT EXISTS ...queries.Before, we simply ignored the table exists error, and continued creating indexes, foreign keys, and checks.
This led to errors when attempting to create indexes/foreign keys/checks that already exists.
Additionally, it would errorneously create indexes/foreng keys/checks that did exist.
The correct behavior is to do nothing if
IF NOT EXISTSis specified and the table exists.Also this contains some refactors and simplifications.
fixes dolthub/dolt#7602