From f55765c17ff3b611dadc7ff5172a7394934ac664 Mon Sep 17 00:00:00 2001 From: Manan Gupta <35839558+GuptaManan100@users.noreply.github.com> Date: Tue, 29 Nov 2022 16:09:41 +0530 Subject: [PATCH] collations: fix coercion semantics according to 8.0.31 changes (#11487) (#11836) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Vicent Marti Signed-off-by: Florent Poinsard Signed-off-by: Manan Gupta Co-authored-by: Vicent Martí <42793+vmg@users.noreply.github.com> Co-authored-by: Florent Poinsard --- 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 227389a52ba..1fe6e21c37b 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 a05d2afad52..c8bf2241989 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() {