-
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 correlated aggregates which should be evaluated in outer query #21431
Conversation
No release note, Please follow https://github.com/pingcap/community/blob/master/contributors/release-note-checker.md |
No release note, Please follow https://github.com/pingcap/community/blob/master/contributors/release-note-checker.md |
This reverts commit a619159.
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.
Rest LGTM
/run-all-tests tidb-test=pr/1124 |
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 |
/run-all-tests |
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
cherry pick to release-4.0 in PR #21877 |
What problem does this PR solve?
Issue Number: close #18350, close #17748
Problem Summary:
What is changed and how it works?
What's Changed:
resolveCorrelatedAggregates
beforebuildAggregation
to collect correlated aggregates from sub-queries.ResultSetNode
to avoid rebuilding plans.correlatedAggMap
for sub-queries to build correct plans.How it Works:
b.resolveCorrelatedAggregates
,count(n.a)
will be recognized as correlated aggregate since columnn.a
is from outer schema (from tablen
instead oft
). Socount(n.a)
is collected and returned to outerbuildSelect
, now the query is like:Inside
b.buildAggregation
, a correlated column forsel_subq_agg_1
will be created and added tob.correlatedAggMap
. Thenb.buildProjection
will build plan for sub-query(select count(n.a) from t) limit 1
.The sub-query will recognize
count(n.a)
as correlated aggregate and skip it the process of building aggregate plan. Then insideb.buildProjection
of the sub-query,count(n.a)
will be rewritten as a correlated column tosel_subq_agg_1
, now the query is like:Related changes
Check List
Tests
Side effects
Release note