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

Support MySQL table option {INDEX | KEY} to the CREATE TABLE, restrict to MySql and generic dialects #665

Merged
merged 1 commit into from Oct 19, 2022
Merged

Support MySQL table option {INDEX | KEY} to the CREATE TABLE, restrict to MySql and generic dialects #665

merged 1 commit into from Oct 19, 2022

Conversation

AugustoFKL
Copy link
Contributor

Breaking changes:

  • Now HASH and BTREE are KEYWORDS, and using them as names can result in errors.
  • Now 'KEY' and 'INDEX' column names start the parsing of a table constraint if unquoted for the Generic dialect. This results in possible conflicts if canonical results are compared for all dialects if a column is named 'key' without quotes.

Theoretically, the behavior should be the same as CREATE INDEX, but we cannot make that assumption, so the parse is (almost) identical to the input. MySQL seems to be the only one to support this syntax. (1)

Now we can support statements like:

CREATE TABLE (id INT, INDEX (id));

CREATE TABLE (id INT, KEY index_name USING BTREE (id))

The supported syntax implemented here is:

CREATE TABLE (..., {KEY | INDEX} [index_name] [USING {BTREE | HASH}] (<key_part>, ...))

<index_name>: Single identifier
<key_part>: Single identifier

[1] : https://dev.mysql.com/doc/refman/8.0/en/create-table.html

… (partial).

Theoretically the behavior should be the same as CREATE INDEX, but we
cannot make that assumption, so the parse is (almost) identical as the
input.

Breaking changes:
- Now HASH and BTREE are KEYWORDS, and using them as names can result in
  errors.
- Now 'KEY' and 'INDEX' column names start the parsing of a table constraint if unquoted for the Generic dialect. This results in possible conficts if canonical results are compared for all dialects if a column is named 'key' without quotes.
@coveralls
Copy link

Pull Request Test Coverage Report for Build 3216094339

  • 88 of 91 (96.7%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.08%) to 85.866%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/parser.rs 62 63 98.41%
src/ast/ddl.rs 15 17 88.24%
Totals Coverage Status
Change from base Build 3209998484: 0.08%
Covered Lines: 10559
Relevant Lines: 12297

💛 - Coveralls

Copy link
Collaborator

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you @AugustoFKL

///
/// [1]: https://dev.mysql.com/doc/refman/8.0/en/create-table.html
Index {
/// Whether this index starts with KEY (true) or INDEX (false), to maintain the same syntax.
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@alamb alamb merged commit 2aba3f8 into sqlparser-rs:main Oct 19, 2022
@alamb alamb changed the title Adding MySQL table option {INDEX | KEY} to the CREATE TABLE, restrict to MySql and generic dialects Support MySQL table option {INDEX | KEY} to the CREATE TABLE, restrict to MySql and generic dialects Oct 19, 2022
@AugustoFKL AugustoFKL deleted the add-mysql-index-to-create-table branch November 5, 2022 23:11
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