Add PushPartialAggregationThroughJoinRuleSet#27343
Draft
aaneja wants to merge 3 commits intoprestodb:masterfrom
Draft
Add PushPartialAggregationThroughJoinRuleSet#27343aaneja wants to merge 3 commits intoprestodb:masterfrom
aaneja wants to merge 3 commits intoprestodb:masterfrom
Conversation
Contributor
Reviewer's GuideIntroduces PushPartialAggregationThroughJoinRuleSet to handle pushing partial aggregations (optionally with an intervening projection) through joins, wires it into PlanOptimizers, and adds tests for both the new rule set behavior and projection-spanning cases. Class diagram for PushPartialAggregationThroughJoinRuleSet and related rulesclassDiagram
class PushPartialAggregationThroughJoinRuleSet {
+Set~Rule~ rules()
+PushPartialAggregationThroughJoin withoutProjectionRule()
+PushPartialAggregationWithProjectThroughJoin withProjectionRule()
-static Capture AGGREGATION_NODE
-static Capture JOIN_NODE
-static Capture PROJECT_NODE
-static Pattern WITHOUT_PROJECTION
-static Pattern WITH_PROJECTION
-static boolean isSupportedAggregationNode(AggregationNode aggregationNode)
}
class BaseRule {
<<abstract>>
+boolean isEnabled(Session session)
+Rule.Result applyPushdown(AggregationNode aggregationNode, JoinNode joinNode, Rule.Context context)
-boolean allAggregationsOn(Map aggregations, List variables)
-PlanNode pushPartialToLeftChild(AggregationNode node, JoinNode child, Rule.Context context)
-PlanNode pushPartialToRightChild(AggregationNode node, JoinNode child, Rule.Context context)
-Set getJoinRequiredVariables(JoinNode node)
-List getPushedDownGroupingSet(AggregationNode aggregation, Set availableVariables, Set requiredJoinVariables)
-AggregationNode replaceAggregationSource(AggregationNode aggregation, PlanNode source, List groupingKeys)
-PlanNode pushPartialToJoin(AggregationNode aggregation, JoinNode child, PlanNode leftChild, PlanNode rightChild, Rule.Context context)
}
class PushPartialAggregationThroughJoin {
+Pattern getPattern()
+Rule.Result apply(AggregationNode aggregationNode, Captures captures, Rule.Context context)
}
class PushPartialAggregationWithProjectThroughJoin {
+Pattern getPattern()
+Rule.Result apply(AggregationNode aggregationNode, Captures captures, Rule.Context context)
-PlanNode buildPushedProjection(ProjectNode originalProject, PlanNode joinChild, Rule.Context context)
-JoinNode rebuildJoin(JoinNode original, PlanNode newLeft, PlanNode newRight)
}
class Rule {
<<interface>>
}
class AggregationNode
class JoinNode
class ProjectNode
class PlanNode
PushPartialAggregationThroughJoinRuleSet --> PushPartialAggregationThroughJoin : creates
PushPartialAggregationThroughJoinRuleSet --> PushPartialAggregationWithProjectThroughJoin : creates
BaseRule ..|> Rule
PushPartialAggregationThroughJoin ..|> BaseRule
PushPartialAggregationWithProjectThroughJoin ..|> BaseRule
AggregationNode --> PlanNode
JoinNode --> PlanNode
ProjectNode --> PlanNode
Flow diagram for applying PushPartialAggregationWithProjectThroughJoinflowchart TD
A[Agg_partial_over_Project_over_Join] --> B[Match WITH_PROJECTION pattern]
B --> C{JoinType == INNER?}
C -- No --> Z[Result.empty]
C -- Yes --> D[Compute leftVariables and rightVariables]
D --> E[Iterate project assignments]
E --> F{Any expr uses both left and right vars?}
F -- Yes --> Z
F -- No --> G[Determine allLeft and allRight flags]
G --> H{!allLeft && !allRight?}
H -- Yes --> Z
H -- No --> I{allLeft?}
I -- Yes --> J[Build pushed Project over left child]
I -- No --> K[Build pushed Project over right child]
J --> L[Rebuild Join with new left child]
K --> L[Rebuild Join with new right child]
L --> M[Call applyPushdown on Agg and new Join]
M --> N{All agg inputs from left side?}
N -- Yes --> O[pushPartialToLeftChild]
N -- No --> P{All agg inputs from right side?}
P -- Yes --> Q[pushPartialToRightChild]
P -- No --> Z
O --> R[Build pushed Aggregation over left child]
Q --> S[Build pushed Aggregation over right child]
R --> T[Rebuild Join with pushed Aggregation]
S --> T
T --> U[restrictOutputs to original Agg outputs]
U --> V[Return transformed plan]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
aggregations through exchange
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Apply agg pushdown thru Join for cases where a Project stops the rule application
Co-authored-by: @copilot
Motivation and Context
Impact
Test Plan
Contributor checklist
Release Notes
Please follow release notes guidelines and fill in the release notes below.
If release note is NOT required, use:
Summary by Sourcery
Introduce a ruleset for pushing partial aggregations (optionally with intervening projections) through joins and update optimizers to use it instead of the previous single rule.
Enhancements:
Tests: