-
-
Notifications
You must be signed in to change notification settings - Fork 231
implement if [not] exists
logic for DDL around view
s and index
es
#3006
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
Conversation
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.
Looks good, but I think we should match MySQL 9.1's syntax for CREATE IF NOT EXISTS VIEW ...
(even though I slightly prefer the current syntax) just for compatibility sake. Then we should decide if we want CREATE INDEX
to be consistent with CREATE TABLE IF NOT EXISTS
or CREATE IF NOT EXISTS VIEW
.
}, | ||
Assertions: []ScriptTestAssertion{ | ||
{ | ||
Query: "create view if not exists v as select 2;", |
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.
Sorry I didn't notice this while looking at the parser updates... it looks like we are slightly off of MySQL's syntax here... it seems like support for IF NOT EXISTS
was added very recently, in MySQL 9.1. The docs show that that the form should be CREATE IF NOT EXISTS VIEW v AS SELECT 2;
:
https://dev.mysql.com/doc/refman/9.1/en/create-view.html
I haven't tested this with MySQL 9.x, so it could be that the documentation is incorrect. I know that syntax is a little inconsistent with CREATE TABLE IF NOT EXISTS
, too.
ExpectedErr: sql.ErrDuplicateKey, | ||
}, | ||
{ | ||
Query: "create index if not exists idx on t(j)", |
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'm not sure MySQL actually supports this syntax, based on their docs:
https://dev.mysql.com/doc/refman/9.3/en/create-index.html
I tested with MySQL 8.4, but didn't try with MySQL 9.x.
That said, I think it's still useful and I'm not opposed to supporting it, although it will likely be hard for customers to discover if it isn't in the MySQL docs. We should just figure out if we want to be consistent with CREATE TABLE IF NOT EXISTS
or CREATE IF NOT EXISTS VIEW
, which unfortunately seems to be inconsistent in MySQL.
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.
Yeah, I noticed this too.
MariaDB has been doing create view IF NOT EXISTS
, which is consistent with all the other CREATE ... IF NOT EXISTS
queries... it might be possible to do both?
So CREATE [IF NOT EXISTS] VIEW [IF NOT EXISTS] ...
?
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 downloaded MySQL 9.3 and tested it out; their docs are just messed up.
mysql> select version();
+-----------+
| version() |
+-----------+
| 9.3.0 |
+-----------+
1 row in set (0.0003 sec)
mysql> create if not exists view v as select 1;
ERROR: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'if not exists view v as select 1' at line 1
mysql> create view if not exists v as select 1;
Query OK, 0 rows affected (0.0044 sec)
mysql> select * from v;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.0009 sec)
if not exists
logic for create view
queriesif [not] exists
logic for DDL around view
s and index
es
This PR adds support for queries:
create view if not exists ...
create index if not exists ...
alter table ... add index if not exists ...
drop index if exists ...
fixes: dolthub/dolt#9293
companion pr: dolthub/vitess#417