Class DecorrelateLeftUnnestWithGlobalAggregation

java.lang.Object
io.trino.sql.planner.iterative.rule.DecorrelateLeftUnnestWithGlobalAggregation
All Implemented Interfaces:
Rule<CorrelatedJoinNode>

public class DecorrelateLeftUnnestWithGlobalAggregation extends Object implements Rule<CorrelatedJoinNode>
This rule finds correlated UnnestNode in CorrelatedJoinNode's subquery and folds them into UnnestNode representing LEFT JOIN UNNEST. This rule transforms plans, where: - UnnestNode in subquery is based only on correlation symbols - UnnestNode in subquery is LEFT without filter - subquery contains global aggregation over the result of unnest Additionally, other global aggregations, grouped aggregations and projections in subquery are supported.

Transforms:

 - CorrelatedJoin (LEFT or INNER) on true, correlation(c1, c2)
      - Input (a, c1, c2)
      - Aggregation
           global grouping
           agg invalid input: '<'- agg1(x)
           - Projection
                x invalid input: '<'- foo(y)
                - Aggregation
                     group by (g)
                     y invalid input: '<'- agg2(u)
                     - Unnest LEFT
                          g invalid input: '<'- unnest(c1)
                          u invalid input: '<'- unnest(c2)
                          replicate: ()
 
Into:
 - Projection (restrict outputs)
      - Aggregation
           group by (a, c1, c2, unique)
           agg invalid input: '<'- agg1(x)
           - Projection
                x invalid input: '<'- foo(y)
                - Aggregation
                     group by (g, a, c1, c2, unique)
                     y invalid input: '<'- agg2(u)
                     - Unnest LEFT
                          g invalid input: '<'- unnest(c1)
                          u invalid input: '<'- unnest(c2)
                          replicate: (a, c1, c2, unique)
                          - AssignUniqueId unique
                               - Input (a, c1, c2)