Class PushFilterThroughBoolOrAggregation

java.lang.Object
io.trino.sql.planner.iterative.rule.PushFilterThroughBoolOrAggregation

public class PushFilterThroughBoolOrAggregation extends Object
Push down aggregation's bool_or based on filter predicate.

This rule transforms plans with a FilterNode above an AggregationNode. The AggregationNode must be grouped and contain a single aggregation assignment with `bool_or()` function.

If the filter predicate is `false` for the aggregation's result value `false` or `null`, then the aggregation can removed from the aggregation node, and applied as a filter below the AggregationNode. After such transformation, any group such that no rows of that group pass the filter, is removed by the pushed down FilterNode, and so it is not processed by the AggregationNode. Before the transformation, the group would be processed by the AggregationNode, and return `false` or `null`, which would then be filtered out by the root FilterNode.

After the symbol pushdown, it is checked whether the root FilterNode is still needed, based on the fact that the aggregation never returns `false` or `null`.

Transforms:

 
 - filter (aggr_bool AND predicate)
   - aggregation
     group by a
     aggr_bool <- bool_or(s)
       - source (a, s)
       
 
into:
 
 - filter (predicate)
   - project (aggr_bool=true)
     - aggregation
       group by a
         - filter (s)
           - source (a, s)