Class DecorrelateInnerUnnestWithGlobalAggregation

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

public class DecorrelateInnerUnnestWithGlobalAggregation 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 INNER 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 <- agg1(x)
           - Projection
                x <- foo(y)
                - Aggregation
                     group by (g)
                     y <- agg2(u)
                     - Unnest INNER
                          g <- unnest(c1)
                          u <- unnest(c2)
                          replicate: ()
 
Into:

 - Projection (restrict outputs)
      - Aggregation
           group by (a, c1, c2, unique)
           agg <- agg1(x) mask(mask_symbol)
           - Projection
                x <- foo(y)
                - Aggregation
                     group by (g, a, c1, c2, unique, mask_symbol)
                     y <- agg2(u)
                     - Projection
                          mask_symbol <- ordinality IS NOT NULL
                          - Unnest LEFT with ordinality
                               g <- unnest(c1)
                               u <- unnest(c2)
                               replicate: (a, c1, c2, unique)
                               - AssignUniqueId unique
                                    - Input (a, c1, c2)