Skip to content

Commit bcc9f7a

Browse files
MySQL: allow USING clause before ON in CREATE INDEX
MySQL allows specifying the index type `USING index_type` before the `ON` clause in `CREATE INDEX` statements. This PR allows the `CREATE INDEX` parser to accept both positions of the `USING` clause, regardless of the dialect. docs: https://dev.mysql.com/doc/refman/8.4/en/create-index.html
1 parent 54a24e7 commit bcc9f7a

File tree

3 files changed

+5875
-5
lines changed

3 files changed

+5875
-5
lines changed

src/parser/mod.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7061,19 +7061,24 @@ impl<'a> Parser<'a> {
70617061
pub fn parse_create_index(&mut self, unique: bool) -> Result<Statement, ParserError> {
70627062
let concurrently = self.parse_keyword(Keyword::CONCURRENTLY);
70637063
let if_not_exists = self.parse_keywords(&[Keyword::IF, Keyword::NOT, Keyword::EXISTS]);
7064+
7065+
let mut using = None;
7066+
70647067
let index_name = if if_not_exists || !self.parse_keyword(Keyword::ON) {
70657068
let index_name = self.parse_object_name(false)?;
7069+
// MySQL allows `USING index_type` either before or after `ON table_name`
7070+
using = self.parse_optional_using_then_index_type()?;
70667071
self.expect_keyword_is(Keyword::ON)?;
70677072
Some(index_name)
70687073
} else {
70697074
None
70707075
};
7076+
70717077
let table_name = self.parse_object_name(false)?;
7072-
let using = if self.parse_keyword(Keyword::USING) {
7073-
Some(self.parse_index_type()?)
7074-
} else {
7075-
None
7076-
};
7078+
7079+
// MySQL allows having two `USING` clauses.
7080+
// In that case, the second clause overwrites the first.
7081+
using = self.parse_optional_using_then_index_type()?.or(using);
70777082

70787083
let columns = self.parse_parenthesized_index_column_list()?;
70797084

0 commit comments

Comments
 (0)