Skip to content

Commit

Permalink
cherry pick #19576 to release-4.0 (#19831)
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <[email protected]>

Co-authored-by: Kenan Yao <[email protected]>
  • Loading branch information
ti-srebot and eurekaka authored Sep 9, 2020
1 parent fc4fea9 commit f9bc29b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 6 additions & 0 deletions executor/join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1887,6 +1887,12 @@ func (s *testSuiteJoin2) TestNullEmptyAwareSemiJoin(c *C) {
tk.MustQuery("select * from t1 where a not in (select a from t2 where t1.a = t2.a)").Check(testkit.Rows(
"2",
))
tk.MustQuery("select * from t1 where a != all (select a from t2 where t1.a = t2.a)").Check(testkit.Rows(
"2",
))
tk.MustQuery("select * from t1 where a <> all (select a from t2 where t1.a = t2.a)").Check(testkit.Rows(
"2",
))
}

func (s *testSuiteJoin1) TestScalarFuncNullSemiJoin(c *C) {
Expand Down
7 changes: 4 additions & 3 deletions planner/core/expression_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,12 @@ func (er *expressionRewriter) Enter(inNode ast.Node) (ast.Node, bool) {
func (er *expressionRewriter) buildSemiApplyFromEqualSubq(np LogicalPlan, l, r expression.Expression, not bool) {
var condition expression.Expression
if rCol, ok := r.(*expression.Column); ok && (er.asScalar || not) {
rCol.InOperand = true
// If both input columns of `!= all / = any` expression are not null, we can treat the expression
// as normal column equal condition.
if lCol, ok := l.(*expression.Column); ok && mysql.HasNotNullFlag(lCol.GetType().Flag) && mysql.HasNotNullFlag(rCol.GetType().Flag) {
rCol.InOperand = false
if lCol, ok := l.(*expression.Column); !ok || !mysql.HasNotNullFlag(lCol.GetType().Flag) || !mysql.HasNotNullFlag(rCol.GetType().Flag) {
rColCopy := *rCol
rColCopy.InOperand = true
r = &rColCopy
}
}
condition, er.err = er.constructBinaryOpFunction(l, r, ast.EQ)
Expand Down

0 comments on commit f9bc29b

Please sign in to comment.