Skip to content

Commit

Permalink
expression: correct constant propagation for collation (#22666)
Browse files Browse the repository at this point in the history
Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
  • Loading branch information
wjhuang2016 committed Feb 24, 2021
1 parent e360454 commit eea52f5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 1 addition & 2 deletions expression/constant_propagation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <nil> <nil>"))
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) {
Expand Down

0 comments on commit eea52f5

Please sign in to comment.