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

ANSI_QUOTES support for go-mysql-server #1915

Merged
merged 25 commits into from Aug 16, 2023
Merged

ANSI_QUOTES support for go-mysql-server #1915

merged 25 commits into from Aug 16, 2023

Conversation

fulghum
Copy link
Contributor

@fulghum fulghum commented Aug 1, 2023

Now that our parser has support for parsing in ANSI_QUOTES mode and treating double quotes as identifier quotes, this PR starts using that support when we parse queries. The main changes in this PR are:

  • a new SqlMode type to make it easier to load SQL_MODE and inspect enabled modes.
  • tracks SQL_MODE when a procedure/trigger/view is created.
  • passes ParserOptions to the parser, to enable parsing in ANSI_QUOTES mode.
  • connects the Vitess error logger to GMS' error log, so that errors in Vitess aren't swallowed (currently if a statement in a ComPrepare message doesn't parse, GMS doesn't log anything).

Dolt has a similar, corresponding PR: dolthub/dolt#6465

Related to: dolthub/dolt#6305

@fulghum fulghum marked this pull request as ready for review August 7, 2023 21:26
@fulghum fulghum requested a review from zachmu August 8, 2023 00:25
Copy link
Member

@zachmu zachmu left a comment

Choose a reason for hiding this comment

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

Looks great, nice work!

enginetest/queries/ansi_quotes_queries.go Outdated Show resolved Hide resolved
},
{
Query: `show create table view1;`,
Expected: []sql.Row{{"view1", "CREATE VIEW `view1` AS select public_keys.\"public\", public_keys.\"count\" from public_keys", "utf8mb4", "utf8mb4_0900_bin"}},
Copy link
Member

Choose a reason for hiding this comment

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

Does this vary from the MySQL behavior?

Copy link
Contributor Author

@fulghum fulghum Aug 8, 2023

Choose a reason for hiding this comment

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

Good question... this is slightly different than MySQL's behavior – MySQL will normalize the view definition for the SQL_MODE the session is in. So.... if ANSI_QUOTES is enabled, then double quotes will be shown around identifiers, otherwise backtick quotes will be shown in the returned definition.

I'll add some skipped tests and document this as a gap in the current support. I'd vote to leave this as a follow-up, but let me know if you think it's higher priority than that.

I also tested procedures, triggers, and events, and this normalization seems to be unique to views. Procedures, triggers, and events do not get changed to match the session's current ANSI_QUOTES setting, which sorta makes sense given that show create table feels slightly higher level than show routines, etc (which seem to just directly return information_schema rows).

enginetest/queries/ansi_quotes_queries.go Show resolved Hide resolved
sql/sql_mode_test.go Outdated Show resolved Hide resolved
@fulghum fulghum merged commit c11b504 into main Aug 16, 2023
6 checks passed
@Hydrocharged Hydrocharged deleted the fulghum/ansi_quotes branch August 24, 2023 00:17
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

2 participants