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

Fix parsing of encryption attribute for create database #10249

Merged

Conversation

dbussink
Copy link
Contributor

The create database statement also allows for an encryption value to be set, so this fixes parsing support for that.

It also renames the CharsetAndCollation to DatabaseOption since CharsetAndCollationAndEncryption seems overdoing things and DatabaseOption more matches how we call this in other places, like a TableOption.

Updates the test to parse unconditional with no magic comments so we don't depend on the version and the comment logic is already tested separately somewhere else, so I think it's better to not mix those here.

Related Issue(s)

Found as part of #10203

Checklist

  • "Backport me!" label has been added if this change should be backported
  • Tests were added or are not required
  • Documentation was added or is not required

@dbussink dbussink added Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: Query Serving release notes labels May 10, 2022
Copy link
Member

@GuptaManan100 GuptaManan100 left a comment

Choose a reason for hiding this comment

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

Changes look good to me!

@github-actions
Copy link
Contributor

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has the correct release notes label. release notes none should only be used for PRs that are so trivial that they need not be included.
  • If a new flag is being introduced, review whether it is really needed. The flag names should be clear and intuitive (as far as possible), and the flag's help should be descriptive.

Bug fixes

  • There should be at least one unit or end-to-end test.
  • The Pull Request description should either include a link to an issue that describes the bug OR an actual description of the bug and how to reproduce, along with a description of the fix.

Non-trivial changes

  • There should be some code comments as to why things are implemented the way they are.

New/Existing features

  • Should be documented, either by modifying the existing documentation or creating new documentation.
  • New features should have a link to a feature request issue or an RFC that documents the use cases, corner cases and test cases.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • vtctl command output order should be stable and awk-able.

Copy link
Member

@GuptaManan100 GuptaManan100 left a comment

Choose a reason for hiding this comment

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

I have looked at the shift-reduce conflict that is being generated because of these changes. Essentially they are coming from ALTER DATABASE command. In this command the database name is optional and if it is not provided, then we use the current database in use.

Since Encryption is a non-reserved keyword, on ALTER DATABASE ENCRYPTION there is a shift-reduce conflict. Reduction would mean that we are assuming we have no database name provided, shifting would mean that we are using ENCRYPTION as the database name.

The full parsing info for it -

ALTER {DATABASE | SCHEMA} [db_name]
    alter_option ...

alter_option: {
    [DEFAULT] CHARACTER SET [=] charset_name
  | [DEFAULT] COLLATE [=] collation_name
  | [DEFAULT] ENCRYPTION [=] {'Y' | 'N'}
  | READ ONLY [=] {DEFAULT | 0 | 1}
}

@GuptaManan100
Copy link
Member

GuptaManan100 commented May 10, 2022

We can remove the shift-reduce conflict using precedence rules (like we did in #10053) , but not doing so is also fine because this is a one-off conflict and we already have 1 in our parser. Adding precedence rules adds more complexity and I am not a fan of it. We should document this however, so that later if we look at the conflicts, we know where it is coming from.

To fix the CI, the expectedOutput in check_make_parser.sh file needs to be fixed

@GuptaManan100
Copy link
Member

GuptaManan100 commented May 10, 2022

Shift-reduce conflicts default to shifting and I can verify MySQL does the same -

mysql [localhost:8026] {msandbox} (rails_app) > alter database encryption = 'y';
ERROR 1064 (42000): 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 '= 'y'' at line 1
mysql [localhost:8026] {msandbox} (rails_app) > alter database encryption encryption = 'y';
ERROR 3503 (42Y07): Database 'encryption' doesn't exist

@dbussink dbussink force-pushed the dbussink/parse-encryption-create-table branch from 4913583 to 6a49045 Compare May 10, 2022 11:59
@dbussink
Copy link
Contributor Author

To fix the CI, the expectedOutput in check_make_parser.sh file needs to be fixed

Applied in 6a49045 and added a comment there as well for this case.

dbussink added 2 commits May 10, 2022 16:21
The create database statement also allows for an encryption value to be
set, so this fixes parsing support for that.

It also renames the `CharsetAndCollation` to `DatabaseOption` since
`CharsetAndCollationAndEncryption` seems overdoing things and
`DatabaseOption` more matches how we call this in other places, like a
`TableOption`.

Updates the test to parse unconditional with no magic comments so we
don't depend on the version and the comment logic is already tested
separately somewhere else, so I think it's better to not mix those here.

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
@dbussink dbussink force-pushed the dbussink/parse-encryption-create-table branch from 6a49045 to b1ad801 Compare May 10, 2022 14:22
@GuptaManan100 GuptaManan100 merged commit 2809ca9 into vitessio:main May 11, 2022
@GuptaManan100 GuptaManan100 deleted the dbussink/parse-encryption-create-table branch May 11, 2022 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Query Serving Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants