-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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 the fail when we compare multi fields in the subquery #21699
Conversation
/cc @lzmhhh123 |
/cc @winoros |
/run-all-tests |
/label sig/planner, type/bug-fix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -538,6 +539,7 @@ func (er *expressionRewriter) handleCompareSubquery(ctx context.Context, v *ast. | |||
} else if v.Op == opcode.NE { | |||
if v.All { | |||
// `a != all(subq)` will be rewriten as `a not in (subq)`. | |||
er.asScalar = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test case does not cover this?
/run-all-tests |
@XuHuaiyu Update.PTAL! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/merge |
Your auto merge job has been accepted, waiting for:
|
/run-all-tests |
Signed-off-by: ti-srebot <[email protected]>
cherry pick to release-4.0 in PR #21808 |
What problem does this PR solve?
Issue Number: close #13551 close #21674
Problem Summary:
When we use
(SELECT c1, c2 FROM t2 LIMIT 1) = ANY (SELECT c1, c2 FROM t1)
in thewhere
statement, theexpressionRewrite.ctxStack
will store the result value ofSELECT c1, c2 FROM t2 LIMIT 1
. So in issue#21674, when the value of c1 is zero, the plan will be convert totableDual
.What is changed and how it works?
So, we should set
expressionRewrite.asScalar = true
likehandleInSubquery
function. It will use the parent expression's last column from the schema to represents whether the condition is matched(https://github.com/pingcap/tidb/blob/master/planner/core/expression_rewriter.go#L558-L561).Related changes
pingcap/docs
/pingcap/docs-cn
:Check List
Tests
Release note