presto-main/src/main/java/io/prestosql/sql/planner/optimizations/QueryCardinalityUtil.java/CardinalityExtractorPlanVisitor/visitAggregation
class CardinalityExtractorPlanVisitor:        @Override
        public Range<Long> visitAggregation(AggregationNode node, Void context)
        {
            if (node.hasEmptyGroupingSet() && node.getGroupingSetCount() == 1) {
                // only single default aggregation which will produce exactly single row
                return Range.singleton(1L);
            }

            Range<Long> sourceCardinalityRange = node.getSource().accept(this, null);

            long lower;
            if (node.hasDefaultOutput() || sourceCardinalityRange.lowerEndpoint() > 0) {
                lower = 1;
            }
            else {
                lower = 0;
            }

            if (sourceCardinalityRange.hasUpperBound()) {
                long upper = Math.max(lower, sourceCardinalityRange.upperEndpoint());
                return Range.closed(lower, upper);
            }

            return Range.atLeast(lower);
        }