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: fix incorrect result for != all (subq) (#19576) #19831

Merged
merged 3 commits into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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