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: avoid constant propagate for the hybrid types (#20258) #20297

Merged
merged 3 commits into from
Oct 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 6 additions & 1 deletion expression/constant_propagation.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ func (s *propConstSolver) propagateColumnEQ() {
if fun, ok := s.conditions[i].(*ScalarFunction); ok && fun.FuncName.L == ast.EQ {
lCol, lOk := fun.GetArgs()[0].(*Column)
rCol, rOk := fun.GetArgs()[1].(*Column)
if lOk && rOk && lCol.GetType().Collate == rCol.GetType().Collate {
// TODO: Enable hybrid types in ConstantPropagate.
if lOk && rOk && lCol.GetType().Collate == rCol.GetType().Collate && !lCol.GetType().Hybrid() && !rCol.GetType().Hybrid() {
lID := s.getColID(lCol)
rID := s.getColID(rCol)
s.unionSet.Union(lID, rID)
Expand Down Expand Up @@ -301,6 +302,10 @@ func (s *propConstSolver) pickNewEQConds(visited []bool) (retMapper map[int]*Con
}
continue
}
// TODO: Enable hybrid types in ConstantPropagate.
if col.GetType().Hybrid() {
continue
}
visited[i] = true
updated, foreverFalse := s.tryToUpdateEQList(col, con)
if foreverFalse {
Expand Down
19 changes: 19 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7077,3 +7077,22 @@ func (s *testIntegrationSuite) TestIssue17476(c *C) {
tk.MustQuery(`SELECT count(*) FROM (table_float JOIN table_int_float_varchar AS tmp3 ON (tmp3.col_varchar_6 AND NULL) IS NULL);`).Check(testkit.Rows("154"))
tk.MustQuery(`SELECT * FROM (table_int_float_varchar AS tmp3) WHERE (col_varchar_6 AND NULL) IS NULL AND col_int_6=0;`).Check(testkit.Rows("13 0 -0.1 <nil>"))
}

func (s *testIntegrationSuite) TestIssue20180(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t;")
tk.MustExec("drop table if exists t1;")
tk.MustExec("create table t(a enum('a', 'b'), b tinyint);")
tk.MustExec("create table t1(c varchar(20));")
tk.MustExec("insert into t values('b', 0);")
tk.MustExec("insert into t1 values('b');")
tk.MustQuery("select * from t, t1 where t.a= t1.c;").Check(testkit.Rows("b 0 b"))
tk.MustQuery("select * from t, t1 where t.b= t1.c;").Check(testkit.Rows("b 0 b"))
tk.MustQuery("select * from t, t1 where t.a = t1.c and t.b= t1.c;").Check(testkit.Rows("b 0 b"))

tk.MustExec("drop table if exists t;")
tk.MustExec("create table t(a enum('a','b'));")
tk.MustExec("insert into t values('b');")
tk.MustQuery("select * from t where a > 1 and a = \"b\";").Check(testkit.Rows("b"))
}