-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
mysql: use UTF8mb4 as consistent connection charset #9558
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vmg
added
Type: Enhancement
Logical improvement (somewhere between a bug and feature)
Component: Query Serving
release notes
labels
Jan 25, 2022
vmg
requested review from
deepthi,
frouioui,
harshit-gangal,
shlomi-noach and
systay
as code owners
January 25, 2022 16:05
Signed-off-by: Vicent Marti <vmg@strn.cat>
vmg
force-pushed
the
mysql-conn-charset
branch
from
January 25, 2022 17:35
778f8f9
to
8b26ffe
Compare
frouioui
reviewed
Jan 25, 2022
Signed-off-by: Vicent Marti <vmg@strn.cat>
Signed-off-by: Vicent Marti <vmg@strn.cat>
Signed-off-by: Vicent Marti <vmg@strn.cat>
Signed-off-by: Vicent Marti <vmg@strn.cat>
Signed-off-by: Vicent Marti <vmg@strn.cat>
vmg
force-pushed
the
mysql-conn-charset
branch
from
January 26, 2022 13:54
ea23dc8
to
28ba199
Compare
frouioui
reviewed
Jan 26, 2022
Signed-off-by: Vicent Marti <vmg@strn.cat>
edit: moved to the PR body |
Signed-off-by: Vicent Marti <vmg@strn.cat>
@frouioui green and ready for re-review |
frouioui
approved these changes
Jan 27, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! Looking good to me 🚀
Signed-off-by: Vicent Marti <vmg@strn.cat>
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)
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.
Description
OK, after a lot of testing I have what I believe is a working solution for the weird collation behavior we've been seeing in Vitess clusters. What I figured out is that the workaround that we implemented in our MySQL connection code to support collations >255 was not really working. As a reminder, when connecting to a MySQL server, a handshake is performed between client and server to agree on a "connection charset" (as defined in the MySQL documentation). Now, two critical facts about this: the wire protocol only has 1 byte for this charset, so it's not possible to use charsets higher than 255; and what the documentation calls "charset" is in fact the ID of a full collation, that can very well go above 255.
This PR hence does the following things:
It removes the
db_collation
flag that @frouioui and I introduced a couple months ago. Since this flag never made it to any Vitess releases, there's no deprecation notice needed. As a result of this investigation, we now understand that setting a "charset" and a "collation" for a connection is redundant, as the charset is actually a collation ID. The workaround we had to enforce a custom collation, which was doing it via SQL once the connection was open, is not giving reliable results: we were performing aSET collation_connection
call, but the semantics of this change are weird and it appears to only apply to some string comparisons in SQL. It's not a wholistic change like what we'd get by passing a charset via the handshake when connecting.It adds support for passing collation names to the
db_charset
flag as long as those collations have a collation ID <=255, so that it fits in the handshake packet. This is a non-breaking change that matches the behavior of the commandline flags tomysql
(the MySQL CLI client). You can pass a charset name like we were doing before, such asutf8mb4
, but you can also pass a full collation likeutf8m4_general_ci
. Vitess will error out if you attempt to pass a collation that resolves to an ID > 255. Fortunately, all the collation IDs for the default collations for all charsets in all MySQL versions are <=255.It reliably changes the default charset used for Vitess clusters based on the underlying MySQL server version. Vitess clusters based on MySQL 5.x will use
utf8mb4_general_ci
by default (unless configured otherwise with thedb_charset
flag). Vitess clusters based on MySQL 8+ will useutf8mb4_0900_ai_ci
. To note:utf8mb4_0900_ai_ci
is the default charset for a MySQL 8.0 deployment, and Vitess will not match that behavior. However,utf8mb4_general_ci
is not the default charset for a MySQL 5.7 deployment: that'd beutf8_general_ci
. We believe this is a terrible default, particularly sinceutf8
is a deprecated charset in MySQL, so we want to enforce all users to useutf8mb4
charsets even in 5.7 to prevent them from shooting themselves in the foot.Related Issue(s)
Checklist
Deployment Notes