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

parser: add support for ALTER DATABASE syntax #318

Merged
merged 2 commits into from
May 9, 2019

Conversation

bb7133
Copy link
Member

@bb7133 bb7133 commented May 7, 2019

What problem does this PR solve?

Add support for ALTER DATABASE syntax

Related issue: pingcap/tidb#4641

What is changed and how it works?

Modified parser.y

Check List

Tests

  • Unit test
  • Integration test

Code changes

  • Has exported function/method change

Side effects

Related changes

  • Need to update the documentation

ast/ddl.go Outdated Show resolved Hide resolved
parser_test.go Outdated Show resolved Hide resolved
@bb7133 bb7133 force-pushed the bb7133/alter_db branch 4 times, most recently from 111972b to 481ec6a Compare May 8, 2019 07:42
@bb7133
Copy link
Member Author

bb7133 commented May 8, 2019

PTAL @kennytm , thank you!

@bb7133 bb7133 added type/enhancement New feature or request and removed DNM labels May 8, 2019
parser.y Outdated Show resolved Hide resolved
parser.y Outdated Show resolved Hide resolved
@bb7133
Copy link
Member Author

bb7133 commented May 8, 2019

Thank you very much @kennytm

Copy link
Contributor

@kennytm kennytm left a comment

Choose a reason for hiding this comment

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

LGTM

@kennytm kennytm added the status/LGT1 LGT1 label May 8, 2019
@@ -3237,7 +3270,7 @@ Identifier:
identifier | UnReservedKeyword | NotKeywordToken | TiDBKeyword

UnReservedKeyword:
"ACTION" | "ASCII" | "AUTO_INCREMENT" | "AFTER" | "ALWAYS" | "AVG" | "BEGIN" | "BIT" | "BOOL" | "BOOLEAN" | "BTREE" | "BYTE" | "CLEANUP" | "CHARSET"
"ACTION" | "ASCII" | "AUTO_INCREMENT" | "AFTER" | "ALWAYS" | "AVG" | "BEGIN" | "BIT" | "BOOL" | "BOOLEAN" | "BTREE" | "BYTE" | "CLEANUP" | "CHARSET" %prec charsetKwd
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to care about "CHARACTER" "SET"? I am not very clear about this.

Copy link
Contributor

Choose a reason for hiding this comment

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

why we use %prec here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do we need to care about "CHARACTER" "SET"? I am not very clear about this.

@zimulala The reason is CHARACTER is a reserved token but CHARSET is unreserved. For example,

mysql> create database charset;
Query OK, 1 row affected

mysql> create database character;
(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'character' at line 1")

Copy link
Member Author

Choose a reason for hiding this comment

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

why we use %prec here?

@zimulala @winkyao the reason is CHARSET is an unreserved keyword. There's a shift/reduce conflict when parsing AlterDatabseStmt CHARSET, YACC need to decide if charset is treated as CHARACTER SET keyword, or the database name.

BTW, this precedence leads to the following parsing result:

mysql> alter database charset=utf8;
(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=utf8' at line 1")

mysql> alter database character set=utf8;
Query OK, 1 row affected

And it is consistent with MySQL parser.

Copy link
Contributor

@lonng lonng left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@crazycs520 crazycs520 left a comment

Choose a reason for hiding this comment

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

LGTM

@bb7133 bb7133 merged commit 7a8657e into pingcap:master May 9, 2019
bb7133 added a commit to bb7133/parser that referenced this pull request May 15, 2019
tiancaiamao pushed a commit to tiancaiamao/parser that referenced this pull request Apr 27, 2021
lyonzhi pushed a commit to lyonzhi/parser that referenced this pull request Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/LGT1 LGT1 type/enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants