From 487ad076a23d16409c3c271605e569d27f99ce94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicent=20Mart=C3=AD?= <42793+vmg@users.noreply.github.com> Date: Thu, 13 Oct 2022 16:09:13 +0200 Subject: [PATCH] collations: fix coercion semantics according to 8.0.31 changes (#11487) Signed-off-by: Vicent Marti Signed-off-by: Vicent Marti Signed-off-by: Florent Poinsard Co-authored-by: Florent Poinsard Signed-off-by: Manan Gupta --- go/mysql/collations/coercion.go | 7 +++++++ go/mysql/collations/integration/coercion_test.go | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/go/mysql/collations/coercion.go b/go/mysql/collations/coercion.go index 3087975f239..edd1a6289ea 100644 --- a/go/mysql/collations/coercion.go +++ b/go/mysql/collations/coercion.go @@ -208,9 +208,16 @@ func (env *Environment) MergeCollations(left, right TypedCollation, opt Coercion if leftColl == nil || rightColl == nil { return TypedCollation{}, nil, nil, fmt.Errorf("unsupported TypeCollationID: %v / %v", left.Collation, right.Collation) } + leftCS := leftColl.Charset() rightCS := rightColl.Charset() + if left.Coercibility == CoerceExplicit && right.Coercibility == CoerceExplicit { + if left.Collation != right.Collation { + goto cannotCoerce + } + } + if leftCS.Name() == rightCS.Name() { switch { case left.Coercibility < right.Coercibility: diff --git a/go/mysql/collations/integration/coercion_test.go b/go/mysql/collations/integration/coercion_test.go index dbc039d9529..58aae5aa979 100644 --- a/go/mysql/collations/integration/coercion_test.go +++ b/go/mysql/collations/integration/coercion_test.go @@ -135,8 +135,8 @@ func TestComparisonSemantics(t *testing.T) { conn := mysqlconn(t) defer conn.Close() - if strings.HasPrefix(conn.ServerVersion, "8.0.31") { - t.Skipf("Coercion semantics have changed in 8.0.31") + if v, err := conn.ServerVersionAtLeast(8, 0, 31); err != nil || !v { + t.Skipf("The behavior of Coercion Semantics is not correct before 8.0.31") } for _, coll := range collations.Local().AllCollations() {