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

planner: make a copy of column before modifying its InOperand (#19472) #19477

Merged
merged 1 commit into from
Aug 26, 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
9 changes: 9 additions & 0 deletions executor/join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1878,6 +1878,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