Skip to content

Commit

Permalink
planner: make a copy of column before modifying its InOperand (#19472)
Browse files Browse the repository at this point in the history
  • Loading branch information
eurekaka authored Aug 26, 2020
1 parent 892c3a0 commit cc661e0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 9 additions & 0 deletions executor/join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1879,6 +1879,15 @@ func (s *testSuiteJoin2) TestNullEmptyAwareSemiJoin(c *C) {
result.Check(results[i].result)
}
}

tk.MustExec("drop table if exists t1, t2")
tk.MustExec("create table t1(a int)")
tk.MustExec("create table t2(a int)")
tk.MustExec("insert into t1 values(1),(2)")
tk.MustExec("insert into t2 values(1),(null)")
tk.MustQuery("select * from t1 where a not in (select a from t2 where t1.a = t2.a)").Check(testkit.Rows(
"2",
))
}

func (s *testSuiteJoin1) TestScalarFuncNullSemiJoin(c *C) {
Expand Down
8 changes: 4 additions & 4 deletions planner/core/expression_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -787,12 +787,12 @@ func (er *expressionRewriter) handleInSubquery(ctx context.Context, v *ast.Patte
// For AntiSemiJoin/LeftOuterSemiJoin/AntiLeftOuterSemiJoin, we cannot treat `in` expression as
// normal column equal condition, so we specially mark the inner operand here.
if v.Not || asScalar {
rCol.InOperand = true
// If both input columns of `in` expression are not null, we can treat the expression
// as normal column equal condition instead.
lCol, ok := lexpr.(*expression.Column)
if ok && mysql.HasNotNullFlag(lCol.GetType().Flag) && mysql.HasNotNullFlag(rCol.GetType().Flag) {
rCol.InOperand = false
if !mysql.HasNotNullFlag(lexpr.GetType().Flag) || !mysql.HasNotNullFlag(rCol.GetType().Flag) {
rColCopy := *rCol
rColCopy.InOperand = true
rexpr = &rColCopy
}
}
} else {
Expand Down

0 comments on commit cc661e0

Please sign in to comment.