-
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) #21877
planner: fix correlated aggregates which should be evaluated in outer query (#21431) #21877
Conversation
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
/run-all-tests |
@dyzsr you're already a collaborator in bot's repo. |
/run-all-tests tidb-test=pr/1147 |
/run-all-tests tidb-test=pr/1147 |
/run-integration-copr-test tidb-test=pr/1147 |
/run-all-tests |
/run-all-tests |
/run-common-test tidb-test=pr/1147 |
/run-integration-common-test tidb-test=pr/1147 |
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 |
/run-all-tests |
/run-mybatis-test |
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
cherry-pick #21431 to release-4.0
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