Class PushAggregationThroughOuterJoin
- java.lang.Object
-
- io.trino.sql.planner.iterative.rule.PushAggregationThroughOuterJoin
-
- All Implemented Interfaces:
Rule<AggregationNode>
public class PushAggregationThroughOuterJoin extends Object implements Rule<AggregationNode>
This optimizer pushes aggregations below outer joins when: the aggregation is on top of the outer join, it groups by all columns in the outer table, and the outer rows are guaranteed to be distinct.When the aggregation is pushed down, we still need to perform aggregations on the null values that come out of the absent values in an outer join. We add a cross join with a row of aggregations on null literals, and coalesce the aggregation that results from the left outer join with the result of the aggregation over nulls.
Example:
- Filter ("nationkey" > "avg") - Aggregate(Group by: all columns from the left table, aggregation: avg("n2.nationkey")) - LeftJoin("regionkey" = "regionkey") - AssignUniqueId (nation) - Tablescan (nation) - Tablescan (nation)Is rewritten to:- Filter ("nationkey" > "avg") - project(regionkey, coalesce("avg", "avg_over_null") - CrossJoin - LeftJoin("regionkey" = "regionkey") - AssignUniqueId (nation) - Tablescan (nation) - Aggregate(Group by: regionkey, aggregation: avg(nationkey)) - Tablescan (nation) - Aggregate avg(null_literal) - Values (null_literal)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.trino.sql.planner.iterative.Rule
Rule.Context, Rule.Result
-
-
Constructor Summary
Constructors Constructor Description PushAggregationThroughOuterJoin()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Rule.Resultapply(AggregationNode aggregation, Captures captures, Rule.Context context)Pattern<AggregationNode>getPattern()Returns a pattern to which plan nodes this rule applies.booleanisEnabled(Session session)
-
-
-
Method Detail
-
getPattern
public Pattern<AggregationNode> getPattern()
Description copied from interface:RuleReturns a pattern to which plan nodes this rule applies.- Specified by:
getPatternin interfaceRule<AggregationNode>
-
isEnabled
public boolean isEnabled(Session session)
- Specified by:
isEnabledin interfaceRule<AggregationNode>
-
apply
public Rule.Result apply(AggregationNode aggregation, Captures captures, Rule.Context context)
- Specified by:
applyin interfaceRule<AggregationNode>
-
-