Improve MySQL option parsing in index definitions#1997
Merged
iffyio merged 5 commits intoapache:mainfrom Aug 8, 2025
Merged
Conversation
The column list in `CREATE INDEX` now matches the style used elsewhere, e.g. in `TableConstraint`, which is to use spaces after commas. ```sql -- before: CREATE INDEX idx_name ON table_name (column1,column2,column3); -- after: CREATE INDEX idx_name ON table_name (column1, column2, column3); ``` When `CreateIndex` was added, there was no explanation for the lack of spaces, so I assume it was just author preference. But standard style in all documentation I've seen is to use spaces after commas (including [MSSQL]'s documentation of `INCLUDE`, which copied the no-spaces style when added). [MSSQL]: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-index-transact-sql?view=sql-server-ver17#i-create-an-index-with-included-non-key-columns
It's a bit disruptive and pointless to move things around for no reason other than code organization, but imports look a lot cleaner after this (and for future use of `IndexOptions` within `CreateIndex`). Plus it's, you know, correct.
For MySQL, the preferred position to put `USING BTREE` is after the column list rather than before; before is still supported but considered [deprecated]: > The preferred position is after the column list. Expect support for use of the option before the column list to be removed in a future MySQL release. [deprecated]: https://dev.mysql.com/doc/refman/8.4/en/alter-table.html We already parse this correctly for `ALTER TABLE` statements to add keys, and in table-level constraint parsing for `CREATE TABLE`. We can just reuse the same parsing to support the newer style for `CREATE INDEX` statements as well.
ayman-sigma
pushed a commit
to sigmacomputing/sqlparser-rs
that referenced
this pull request
Feb 3, 2026
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 improves the situation for defining indexes using
CREATE INDEX,ALTER TABLE, andCREATE TABLE, by parsing more MySQL options after the column list. (It doesn't really affect key definitions written as options on column definitions.)The main benefit is supporting MySQL's preferred syntax for
USING { BTREE | HASH }, whic is to place it after the column list, instead of before:By "preferred", I mean that MySQL, accepts both forms, but (1) the documentation states the former is deprecated, and (2) if you run
SHOW CREATE TABLEon a table with such an index, it will rewrite theUSINGto come after the column list.This is accomplished by parsing index options generically after the column list, which currently includes
COMMENTandUSING. This means these locations will also benefit from future expansion of index option parsing, such asVISIBLEandWITH PARSER. The downside to this approach is that to continue to support the standard syntax which requiresUSINGbefore the column list, there are now two places whereUSINGcould be stored in the AST (the distinctindex_typefield or in theindex_optionslist). I think this is acceptable to enable broad support and good fidelity.A secondary benefit is also supporting a subset of MySQL's
ALTERoptions forCREATE INDEX: it acceptsALGORITHMandLOCKoptions after the index options.A final, tertiary benefit is rationalizing the code organization by moving
CreateIndexandCreateTablefromdml.rstoddl.rs.