Skip to content

Commit

Permalink
Small internal cleanups
Browse files Browse the repository at this point in the history
This cleans up some logic around the default collation and coercion. We
now make the MySQL 8 collations the default if there's no version
mismatch instead of what we had with MySQL 5.7.

Additionally we fix a small issue that doesn't really matter in
practice with an unknown collation, but we know have a full type so we
do know it, so let's use it.

Signed-off-by: Dirkjan Bussink <[email protected]>
  • Loading branch information
dbussink committed Jul 23, 2024
1 parent ae7214d commit 27cd8f9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
9 changes: 3 additions & 6 deletions go/mysql/collations/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,9 @@ func fetchCacheEnvironment(version collver) *Environment {
// The version string must be in the format that is sent by the server as the version packet
// when opening a new MySQL connection
func NewEnvironment(serverVersion string) *Environment {
// 5.7 is the oldest version we support today, so use that as
// the default.
// NOTE: this should be changed when we EOL MySQL 5.7 support
var version collver = collverMySQL57
// 8.0 is the oldest fully supported version, so use that as the default.
// All newer MySQL versions including 9 are so far compatible as well.
var version collver = collverMySQL8
serverVersion = strings.TrimSpace(strings.ToLower(serverVersion))
switch {
case strings.HasSuffix(serverVersion, "-ripple"):
Expand All @@ -125,8 +124,6 @@ func NewEnvironment(serverVersion string) *Environment {
version = collverMySQL56
case strings.HasPrefix(serverVersion, "5.7."):
version = collverMySQL57
case strings.HasPrefix(serverVersion, "8."):
version = collverMySQL8
}
return fetchCacheEnvironment(version)
}
Expand Down
2 changes: 1 addition & 1 deletion go/mysql/collations/integration/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func mysqlconn(t *testing.T) *mysql.Conn {
if err != nil {
t.Fatal(err)
}
if !strings.HasPrefix(conn.ServerVersion, "8.") {
if strings.HasPrefix(conn.ServerVersion, "5.7.") {
conn.Close()
t.Skipf("collation integration tests are only supported in MySQL 8.0+")
}
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/evalengine/api_coerce.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

func CoerceTo(value sqltypes.Value, typ Type, sqlmode SQLMode) (sqltypes.Value, error) {
cast, err := valueToEvalCast(value, value.Type(), collations.Unknown, typ.values, sqlmode)
cast, err := valueToEvalCast(value, value.Type(), typ.collation, typ.values, sqlmode)
if err != nil {
return sqltypes.Value{}, err
}
Expand Down

0 comments on commit 27cd8f9

Please sign in to comment.