Improve handling of charset and collate in column options.
#2178
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
dolthub/vitess#293 should be merged before this.
This PR does two main things:
Parse and validate the
collateoption, even on binary columns.Currently the
collateoption is ignored on columns of binary type, an we just assume binary collation because it's the only one allowed. This is usually correct but causes some problems.CREATE TABLE t (pk varbinary(10) collate utf8mb4_0900_bin);shouldn't parse, because it's attempting to use an illege collation for columnpk. However, we currently ignore the option and parse it anyway.CREATE TABLE t (pk varbinary(10)) collate utf8mb4_0900_bin;on the other hand, needs to succeed. Binary columns do not inherit the default collation of the table.Reject the charset option except on columns that allow it.
According to MySQL, only text, sets, and enums are allowed to have character sets. Attempting to specify a character set for any other column type is an error. Before this PR, we were simply ignoring the character set where it didn't make sense.
A good way to think of it is that
varbinaryis like a shorthand forvarchar charset binary. In fact, you're even allowed to writeCREATE TABLE t (pk varchar(10) collate binary);and MySQL will generate avarbinary(10)column. Since the column already has a specified char set, it doesn't default to the table charset/collation. And you can't supply an explicit charset to the column because it already has one implicitly.