Class AggregateReduceFunctionsOnGroupKeysRule

All Implemented Interfaces:
TransformationRule

@Enclosing public class AggregateReduceFunctionsOnGroupKeysRule extends RelRule<AggregateReduceFunctionsOnGroupKeysRule.Config> implements TransformationRule
Planner rule that eliminates aggregate functions of GROUP BY keys.

For example, SELECT sal, max(sal) FROM emp GROUP BY sal can be simplified to SELECT sal, sal FROM emp GROUP BY sal.

Currently supports the following aggregate functions when their arguments exist in the aggregate's group set or are deterministic expressions involving only group set columns and constants:

  • MAX
  • MIN
  • AVG
  • ANY_VALUE

Note: This optimization preserves NULL semantics correctly. For aggregate functions like MAX, MIN, and ANY_VALUE, NULL values in the source columns or expressions are handled the same way before and after the transformation: nulls are ignored by the aggregation, and if all grouped values are NULL, the result is NULL.

See Also: