diff --git a/expression/constant_propagation.go b/expression/constant_propagation.go index 264bb0dd5494a..f236ad722b3d0 100644 --- a/expression/constant_propagation.go +++ b/expression/constant_propagation.go @@ -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) @@ -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 { diff --git a/expression/integration_test.go b/expression/integration_test.go index 2f183607a47ce..69b62de08e757 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -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 ")) } + +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")) +}