Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression: correct constant propagation for collation #22666

Merged
merged 7 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -6410,6 +6410,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