-
Notifications
You must be signed in to change notification settings - Fork 643
MySQL: CREATE INDEx
: allow USING
clause before ON
#2029
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
base: main
Are you sure you want to change the base?
Changes from all commits
c6a3910
43a114c
bdbd173
2713ea4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7061,19 +7061,24 @@ impl<'a> Parser<'a> { | |
pub fn parse_create_index(&mut self, unique: bool) -> Result<Statement, ParserError> { | ||
let concurrently = self.parse_keyword(Keyword::CONCURRENTLY); | ||
let if_not_exists = self.parse_keywords(&[Keyword::IF, Keyword::NOT, Keyword::EXISTS]); | ||
|
||
let mut using = None; | ||
|
||
let index_name = if if_not_exists || !self.parse_keyword(Keyword::ON) { | ||
let index_name = self.parse_object_name(false)?; | ||
// MySQL allows `USING index_type` either before or after `ON table_name` | ||
using = self.parse_optional_using_then_index_type()?; | ||
self.expect_keyword_is(Keyword::ON)?; | ||
Some(index_name) | ||
} else { | ||
None | ||
}; | ||
|
||
let table_name = self.parse_object_name(false)?; | ||
let using = if self.parse_keyword(Keyword::USING) { | ||
Some(self.parse_index_type()?) | ||
} else { | ||
None | ||
}; | ||
|
||
// MySQL allows having two `USING` clauses. | ||
// In that case, the second clause overwrites the first. | ||
using = self.parse_optional_using_then_index_type()?.or(using); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be something like using = using.or_else(|| self.parse_optional_using_then_index_type()).transpose()?; in that we should only look to parse again if we didn't parse a value already? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As Michael pointed out earlier, MySQL does allow having two "USING" clauses. In that case, the second one overwrites the first. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be worth a comment on this line, because at first glance (or if you haven't tried it on MySQL yourself) it does seem backwards 😛 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I see, double checking do the tests include the scenario where two There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. Added a second test with two |
||
|
||
let columns = self.parse_parenthesized_index_column_list()?; | ||
|
||
|
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.
Not a fan of this
mut
but also not a fan of returning a tuple of (index_name, using) at line 7067.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.
Seems okay IMO.