From eea52f5f20917befe3974be138cf92ed656cec8a Mon Sep 17 00:00:00 2001 From: wjHuang Date: Wed, 24 Feb 2021 19:19:01 +0800 Subject: [PATCH] expression: correct constant propagation for collation (#22666) Signed-off-by: wjhuang2016 --- expression/constant_propagation.go | 3 +-- expression/integration_test.go | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/expression/constant_propagation.go b/expression/constant_propagation.go index d44fa53328..f5e8bca8a3 100644 --- a/expression/constant_propagation.go +++ b/expression/constant_propagation.go @@ -20,7 +20,6 @@ import ( "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" - "github.com/pingcap/tidb/util/collate" "github.com/pingcap/tidb/util/disjointset" "github.com/pingcap/tidb/util/logutil" "go.uber.org/zap" @@ -88,7 +87,7 @@ func validEqualCondHelper(ctx sessionctx.Context, eq *ScalarFunction, colIsLeft if ContainMutableConst(ctx, []Expression{con}) { return nil, nil } - if !collate.CompatibleCollate(col.GetType().Collate, con.GetType().Collate) { + if col.GetType().Collate != con.GetType().Collate { return nil, nil } return col, con diff --git a/expression/integration_test.go b/expression/integration_test.go index 9018f89dbb..b31bafe2a5 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -6412,6 +6412,13 @@ func (s *testIntegrationSerialSuite) TestCollateConstantPropagation(c *C) { tk.MustExec("insert into t1 values ('ß', 's');") tk.MustExec("insert into t2 values ('s', 's')") tk.MustQuery("select * from t1 left join t2 on t1.a = t2.a collate utf8mb4_unicode_ci where t1.a = 's';").Check(testkit.Rows("ß s ")) + tk.MustExec("drop table if exists t1, t2;") + tk.MustExec("create table t1(a char(10) collate utf8mb4_general_ci, index (a));") + tk.MustExec("create table t2(a char(10) collate utf8_bin, index (a));") + tk.MustExec("insert into t1 values ('a');") + tk.MustExec("insert into t2 values ('A');") + tk.MustExec("set names utf8 collate utf8_general_ci;") + tk.MustQuery("select * from t1, t2 where t1.a=t2.a and t1.a= 'a';").Check(testkit.Rows("a A")) } func (s *testIntegrationSuite2) TestIssue17791(c *C) {