From 0df73e2f691dddd699e5aa3eea1cac72d24cfe71 Mon Sep 17 00:00:00 2001 From: Shenghui Wu <793703860@qq.com> Date: Wed, 14 Apr 2021 17:37:52 +0800 Subject: [PATCH] cherry pick #23989 to release-5.0 Signed-off-by: ti-srebot --- expression/constant_propagation.go | 6 +++--- expression/integration_test.go | 33 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/expression/constant_propagation.go b/expression/constant_propagation.go index f5e8bca8a30fd..7c521d7ea37ae 100644 --- a/expression/constant_propagation.go +++ b/expression/constant_propagation.go @@ -532,6 +532,9 @@ func (s *propOuterJoinConstSolver) deriveConds(outerCol, innerCol *Column, schem // 'expression(..., outerCol, ...)' does not reference columns outside children schemas of join node. // Derived new expressions must be appended into join condition, not filter condition. func (s *propOuterJoinConstSolver) propagateColumnEQ() { + if s.nullSensitive { + return + } visited := make([]bool, 2*len(s.joinConds)+len(s.filterConds)) s.unionSet = disjointset.NewIntSet(len(s.columns)) var outerCol, innerCol *Column @@ -552,9 +555,6 @@ func (s *propOuterJoinConstSolver) propagateColumnEQ() { // `select *, t1.a in (select t2.b from t t2) from t t1` // rows with t2.b is null would impact whether LeftOuterSemiJoin should output 0 or null if there // is no row satisfying t2.b = t1.a - if s.nullSensitive { - continue - } childCol := s.innerSchema.RetrieveColumn(innerCol) if !mysql.HasNotNullFlag(childCol.RetType.Flag) { notNullExpr := BuildNotNullExpr(s.ctx, childCol) diff --git a/expression/integration_test.go b/expression/integration_test.go index c554524ab8b99..3f5dc8fc99a46 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -9070,3 +9070,36 @@ func (s *testIntegrationSuite) TestVitessHashMatchesVitessShards(c *C) { tk.MustQuery("select customer_id, id, hex(expected_shard), hex(computed_shard) from t where expected_shard <> computed_shard"). Check(testkit.Rows()) } +<<<<<<< HEAD +======= + +func (s *testIntegrationSuite) TestIssue23925(c *C) { + defer s.cleanEnv(c) + tk := testkit.NewTestKit(c, s.store) + + tk.MustExec("use test;") + tk.MustExec("drop table if exists t;") + tk.MustExec("create table t(a int primary key, b set('Alice','Bob') DEFAULT NULL);") + tk.MustExec("insert into t value(1,'Bob');") + tk.MustQuery("select max(b) + 0 from t group by a;").Check(testkit.Rows("2")) + + tk.MustExec("drop table if exists t;") + tk.MustExec("create table t(a int, b set('Alice','Bob') DEFAULT NULL);") + tk.MustExec("insert into t value(1,'Bob');") + tk.MustQuery("select max(b) + 0 from t group by a;").Check(testkit.Rows("2")) +} + +func (s *testIntegrationSuite) TestIssue23889(c *C) { + defer s.cleanEnv(c) + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("drop table if exists test_decimal,test_t;") + tk.MustExec("create table test_decimal(col_decimal decimal(10,0));") + tk.MustExec("insert into test_decimal values(null),(8);") + tk.MustExec("create table test_t(a int(11), b decimal(32,0));") + tk.MustExec("insert into test_t values(1,4),(2,4),(5,4),(7,4),(9,4);") + + tk.MustQuery("SELECT ( test_decimal . `col_decimal` , test_decimal . `col_decimal` ) IN ( select * from test_t ) as field1 FROM test_decimal;").Check( + testkit.Rows("", "0")) +} +>>>>>>> 07d2b840d... expression: don't propagateColumnEQ joinCondition when nullSensitive (#23989)