Improve MySQL option parsing in index definitions #1997
Merged
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 TABLE
on a table with such an index, it will rewrite theUSING
to come after the column list.This is accomplished by parsing index options generically after the column list, which currently includes
COMMENT
andUSING
. This means these locations will also benefit from future expansion of index option parsing, such asVISIBLE
andWITH PARSER
. The downside to this approach is that to continue to support the standard syntax which requiresUSING
before the column list, there are now two places whereUSING
could be stored in the AST (the distinctindex_type
field or in theindex_options
list). I think this is acceptable to enable broad support and good fidelity.A secondary benefit is also supporting a subset of MySQL's
ALTER
options forCREATE INDEX
: it acceptsALGORITHM
andLOCK
options after the index options.A final, tertiary benefit is rationalizing the code organization by moving
CreateIndex
andCreateTable
fromdml.rs
toddl.rs
.