-
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 a bug that caused OrderBy correlated subquery can't find the outer schema #29663
Conversation
[REVIEW NOTIFICATION] This pull request has not been approved. 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. |
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.
emm, leave me some time to re-think a little(
The changing scope is larger than the SORT.
@rebelice: PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
@winoros any update to this issue? |
We apologize for the delay of the fix as some complication were found during the PR review. We're working on the fix revision and will provide the final fix soon. |
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.
Duplicated
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.
After I go through the codes.
What you should modify is havingWindowAndOrderbyExprResolver
.
For example, select a from t order by b
. The b
doesn't appear in the select fields. But we can also execute the SQL successfully. This is because this visitor detects the b
in order by item and rewrite it to select a from (select a, b from t order by b)
.
func (b *PlanBuilder) resolveHavingAndOrderBy(sel *ast.SelectStmt, p LogicalPlan) (
map[*ast.AggregateFuncExpr]int, map[*ast.AggregateFuncExpr]int, error) {
extractor := &havingWindowAndOrderbyExprResolver{
p: p,
selectFields: sel.Fields.Fields,
aggMapper: make(map[*ast.AggregateFuncExpr]int),
colMapper: b.colMapper,
outerSchemas: b.outerSchemas,
outerNames: b.outerNames,
}
stepping into group by, order by and having.
sel.Fields.Fields = extractor.selectFields
return ...
}
So we just need to modify the behavior when the extractor goes into the order by clause. This changes would be more stable.
resolved by #26945 |
What problem does this PR solve?
Issue Number: close #26945
Problem Summary:
What is changed and how it works?
Before this PR, when we build OrderBy correlated subquery, we will find the outer column from
outerSchemas
andouterNames
. But theouterSchemas
andouterNames
will be pruned byBuildSelect
. We may not find columns in some cases.Here we use
allSchemas
andallNames
instead ofouterSchemas
andouterNames
. BecauseallSchemas
andallNames
will not be pruned.Check List
Tests
Side effects
Documentation
Release note