Class PushAggregationThroughOuterJoin
java.lang.Object
io.trino.sql.planner.iterative.rule.PushAggregationThroughOuterJoin
- All Implemented Interfaces:
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 -
Method Summary
Modifier and TypeMethodDescriptionapply(AggregationNode aggregation, Captures captures, Rule.Context context) Returns a pattern to which plan nodes this rule applies.boolean
-
Constructor Details
-
PushAggregationThroughOuterJoin
public PushAggregationThroughOuterJoin()
-
-
Method Details
-
getPattern
Description copied from interface:RuleReturns a pattern to which plan nodes this rule applies.- Specified by:
getPatternin interfaceRule<AggregationNode>
-
isEnabled
- Specified by:
isEnabledin interfaceRule<AggregationNode>
-
apply
- Specified by:
applyin interfaceRule<AggregationNode>
-