-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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 order by sub-query couldn't find outer correlated columns #33640
Conversation
Signed-off-by: AilinKid <[email protected]>
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
/run-unit-test |
Code Coverage Details: https://codecov.io/github/pingcap/tidb/commit/8272b2fb0ec8cb413ae9cc3ccbc44cabcc5d7d0b |
for _, byItem := range sel.OrderBy.Items { | ||
if _, ok := byItem.Expr.(*ast.SubqueryExpr); ok { | ||
// correlated agg will be extracted completely latter. | ||
_, np, err := b.rewrite(ctx, byItem.Expr, p, nil, 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.
If this subquery is or contains a non-correlated scalar subquery, it will be executed in it. Then it would cause the subquery to be executed twice, which may result in a regression.
I think we can add a special option into the rewrite to make it not execute the subquery in this case.
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.
make sense,we will reduce it in later version. it's just a temporary solution
/merge |
This pull request has been accepted and is ready to merge. Commit hash: 97e8065
|
/run-unit-test |
Signed-off-by: ti-srebot <[email protected]>
cherry pick to release-5.0 in PR #33685 |
Signed-off-by: ti-srebot <[email protected]>
cherry pick to release-5.1 in PR #33686 |
Signed-off-by: ti-srebot <[email protected]>
cherry pick to release-5.2 in PR #33687 |
Signed-off-by: ti-srebot <[email protected]>
cherry pick to release-5.3 in PR #33688 |
Signed-off-by: ti-srebot <[email protected]>
cherry pick to release-5.4 in PR #33689 |
Signed-off-by: ti-srebot <[email protected]>
cherry pick to release-6.0 in PR #33690 |
Signed-off-by: AilinKid [email protected]
What problem does this PR solve?
Issue Number: close #26945
Problem Summary:
What is changed and how it works?
fetch the correlated column in order-by subquery out to select fields, building it as an Auxiliary one, which will be stored as p.schema() (passing as outer schema when enter subquery) when we try to build order-by clause. Otherwise it couldn't find that correlated column.
Check List
Tests
Side effects
Documentation
Release note