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

Allow other options to precede COLLATE in column type defintions #195

Merged
merged 1 commit into from
Sep 29, 2022

Conversation

Hydrocharged
Copy link

@Hydrocharged Hydrocharged commented Sep 28, 2022

Fixes dolthub/dolt#4403

Previously, COLLATE had to immediately follow the column type in a column definition. As per the above issue, this is not a required rule in MySQL. The fix involved moving all collation-related options from the column_type rule to the column_type_options. This caused a conflict in column_type_options, as column_default also has a COLLATE rule. The conflicting rule resolved to the following:

column_type_options DEFAULT value_expression COLLATE ID

For reference, this is the new COLLATE rule in column_type_options:

column_type_options COLLATE ID

Given the MySQL expression DEFAULT "xyz" COLLATE utf8mb4_bin, it could match either rule, which caused the conflict. value_expression is too permissive in this context, and although we filter out invalid expressions in GMS, we need to be more restrictive here in the parser to prevent conflicts. In addition, the above example should put the collation on the column, as it is not possible to add a collation to a default string literal (must use the expression form: DEFAULT ("xyz" COLLATE utf8mb4_bin)).

To fix this, the column_default rule was updated to be vastly more restrictive. This also highlighted some tests in GMS that enforce incorrect behavior, but those have been fixed ahead-of-time, and will be incorporated into the bump PR.

NOTE: For some reason, we had tests allowing the use of utc_timestamp, utc_date, etc. as default values without the need for parentheses. This is not allowed in MySQL, so I am unsure as to why we allowed them in the first place. Perhaps because they're similar to CURRENT_TIMESTAMP, so we just allowed all of them? Regardless, the tests have been removed as they no longer pass (as they should not pass).

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.

LGTM, only real comment is that it seems some of the timestamp default tests got lost

}, {
// test utc_timestamp with and without ()
input: "create table t (\n" +
" time1 timestamp default utc_timestamp,\n" +
Copy link
Member

Choose a reason for hiding this comment

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

Where did the tests for these go?

Copy link
Author

Choose a reason for hiding this comment

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

You didn't read my description sir lol

@@ -2361,89 +2365,116 @@ column_type_options:
{
opt := ColumnType{Null: BoolVal(true), NotNull: BoolVal(false), sawnull: true}
if err := $1.merge(opt); err != nil {
yylex.Error(err.Error())
return 1
yylex.Error(err.Error())
Copy link
Member

Choose a reason for hiding this comment

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

Probably should preserve the default 4 space indents here and below (better corresponds to the golang tab)

Copy link
Author

Choose a reason for hiding this comment

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

All other indents in the file (or at least the majority) use two spaces rather than tabs, so I changed it to be more consistent. Makes sense that we'd use tab instead, but I wanna keep consistency for now.

@Hydrocharged Hydrocharged merged commit c71cf6a into main Sep 29, 2022
@Hydrocharged Hydrocharged deleted the daylon/not-null-collate-ordering branch September 29, 2022 06: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.

Modifying a column is order-sensitive for NOT NULL and COLLATE
2 participants