Skip to content
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

MySQL: support remaining constraint parts of CREATE/ALTER TABLE #3827

Merged
merged 7 commits into from
Sep 10, 2022

Conversation

yoichi
Copy link
Contributor

@yoichi yoichi commented Sep 4, 2022

Brief summary of the change made

Continuing from #3826, I implemented all the parts related to constraints in CREATE TABLE and ALTER TABLE, including CHECK constraint support.

https://dev.mysql.com/doc/refman/8.0/en/create-table.html
https://dev.mysql.com/doc/refman/8.0/en/alter-table.html

Are there any other side effects of this change that we should be aware of?

  • It reuses TableConstraintSegment in ALTER TABLE ADD CONSTRAINT, the parse structure of ALTER changes.
  • It reuses IndexOptionsSegment in ALTER TABLE, where (SECONDARY_)ENGINE_ATTRIBUTE is not allowed. I think it is not the linter's job to check for all syntax errors, and I did to avoid maintaining each for CREATE TABLE and ALTER TABLE.

Pull Request checklist

  • Please confirm you have completed any of the necessary steps below.

  • Included test cases to demonstrate any code changes, which may be one or more of the following:

    • .yml rule test cases in test/fixtures/rules/std_rule_cases.
    • .sql/.yml parser test cases in test/fixtures/dialects (note YML files can be auto generated with tox -e generate-fixture-yml).
    • Full autofix test cases in test/fixtures/linter/autofix.
    • Other.
  • Added appropriate documentation for the change.

  • Created GitHub issues for any relevant followup/future enhancements if appropriate.

@codecov
Copy link

codecov bot commented Sep 4, 2022

Codecov Report

Merging #3827 (202b8b2) into main (69785ed) will not change coverage.
The diff coverage is n/a.

@@            Coverage Diff            @@
##              main     #3827   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          179       179           
  Lines        13727     13727           
=========================================
  Hits         13727     13727           
Impacted Files Coverage Δ
src/sqlfluff/dialects/dialect_mysql.py 100.00% <ø> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Ref("BracketedColumnReferenceListGrammar"),
AnySetOf(
Sequence(
"KEY_BLOCK_SIZE",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this deleted? I don't see similar code in TableConstraintSegment.

Ref("BracketedColumnReferenceListGrammar"),
AnySetOf(
Sequence(
"KEY_BLOCK_SIZE",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this deleted? I don't see similar code in TableConstraintSegment.

Copy link
Contributor Author

@yoichi yoichi Sep 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this deleted? I don't see similar code in TableConstraintSegment.

Deleted pattern was "[UNIQUE] [INDEX | KEY] ... [index_option] ...", and it is replaced by the combination of
"[CONSTRAINT] UNIQUE [INDEX | KEY] ... [index_option] ..." (around line 646) and "{INDEX | KEY} ... [index_option] ..." (around line 703) in TableConstraintSegment.

Deleted pattern also includes a pattern in which both UNIQUE and (INDEX or KEY) are absent, and it is not covered by TableConstraintSegment. I think there is no problem by ignoring it since it is a invalid query.

AnySetOf(...) represents "[index_option]..." and is covered by IndexOptionsSegment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With these changes, is it still possible to use KEY_BLOCK_SIZE? (Strangely, there is no .sql file using this.) Could you please add a test case for it to your PR?

You could use one of the examples from this page: https://dev.mysql.com/doc/refman/5.7/en/innodb-compression-usage.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With these changes, is it still possible to use KEY_BLOCK_SIZE? (Strangely, there is no .sql file using this.)

Yes.

Could you please add a test case for it to your PR?

Added in 2512947
Thanks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@barrywhart barrywhart merged commit 1ed4d84 into sqlfluff:main Sep 10, 2022
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.

None yet

3 participants