Class PushFilterThroughCountAggregation

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

public class PushFilterThroughCountAggregation extends Object
Push down aggregation's mask 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 `count()` function and a mask.

If the filter predicate is `false` for the aggregation's result value `0`, then the aggregation's mask can removed from the aggregation, 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 `0`, which would then be filtered out by the root FilterNode.

After the mask pushdown, it is checked whether the root FilterNode is still needed, based on the fact that the aggregation never returns `0`.

Transforms:

 
 - filter (count > 0 AND predicate)
     - aggregation
       group by a
       count <- count() mask: m
         - source (a, m)
       
 
into:
 
 - filter (predicate)
     - aggregation
       group by a
       count <- count()
         - filter (m)
             - source (a, m)
       
 
  • Constructor Details

    • PushFilterThroughCountAggregation

      public PushFilterThroughCountAggregation(PlannerContext plannerContext)
  • Method Details

    • rules

      public Set<Rule<?>> rules()