Skip to content

Add MySQL Index Parsing Support for ALTER TABLE Statements #2215

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

Merged
merged 5 commits into from
Apr 4, 2025

Conversation

minleejae
Copy link
Contributor

Summary

This pull request introduces support for parsing MySQL index options in ALTER TABLE statements. The new functionality allows the parser to handle various index types and options, enhancing the flexibility and robustness of the SQL parsing capabilities.

Changes

  • Implemented parsing logic for ALTER TABLE statements that add indexes, including INDEX, KEY, FULLTEXT, and SPATIAL indexes.
  • Added support for parsing index options such as KEY_BLOCK_SIZE, WITH PARSER, COMMENT, and visibility options (VISIBLE and INVISIBLE).
  • Updated the Alter and AlterExpression classes to accommodate the new index options.
  • Enhanced the Index class to store additional index options and attributes.

MySQL Syntax

ALTER TABLE tbl_name
  | ADD {INDEX | KEY} [index_name]
        [index_type] (key_part,...) [index_option] ...

  | ADD {FULLTEXT | SPATIAL} [INDEX | KEY] [index_name]
        (key_part,...) [index_option] ...

index_option: {
    KEY_BLOCK_SIZE [=] value
  | index_type
  | WITH PARSER parser_name
  | COMMENT 'string'
  | {VISIBLE | INVISIBLE}
}

There are some functions related to index comments that are no longer needed due to these changes. I plan to refactor and remove these unnecessary functions in a future update.

Thanks!

@manticore-projects manticore-projects merged commit 090bb60 into JSQLParser:master Apr 4, 2025
2 of 4 checks passed
@manticore-projects
Copy link
Contributor

Good work as always! Thanks and cheers!

@manticore-projects
Copy link
Contributor

You have introduced some ambiguities:

Warning: Choice conflict in (...)* construct at line 7661, column 5.
         Expansion nested within construct and expansion following construct
         have common prefixes, one of which is: "WITH"
         Consider using a lookahead of 2 or more for nested expansion.
Warning: Choice conflict involving two expansions at
         line 7860, column 17 and line 7888, column 17 respectively.
         A common prefix is: "SPATIAL" "COMMENT"
         Consider using a lookahead of 3 or more for earlier expansion.
Warning: Choice conflict in [...] construct at line 7862, column 19.
         Expansion nested within construct and expansion following construct
         have common prefixes, one of which is: "INDEX"
         Consider using a lookahead of 2 or more for nested expansion.
Warning: Choice conflict in [...] construct at line 8363, column 9.
         Expansion nested within construct and expansion following construct
         have common prefixes, one of which is: "WITH"
         Consider using a lookahead of 2 or more for nested expansion.

Please resolved those, thanks!

@minleejae
Copy link
Contributor Author

Hi, @manticore-projects
Thanks for the feedback!
I'll address the conflicts by adjusting the lookahead and submit a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants