[
https://issues.apache.org/jira/browse/CALCITE-4634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17356653#comment-17356653
]
Julian Hyde commented on CALCITE-4634:
--------------------------------------
But do you think it is better? After your change, the {{Aggregate}} will have
to compute a {{COUNT}} aggregate function, and there is an extra {{Filter}}. So
it's not clear whether it is better or worse.
I'm not arguing that your proposed transformation is invalid. I want to know
whether we will recommend this transformation to users as the default.
There is another possible transformation, also valid: if the metadata indicates
that the input is never empty (via
{{RelMetadataQuery.getMinRowCount(RelNode)}}) then we can safely remove the
last group key. {{RelBuilder.aggregate}} does this already. Then, if there are
no agg calls, we can convert {{Aggregate(empty group key, no agg calls)}} to
{{Values(zero columns, one row)}}. (But we run into CALCITE-4597.)
> Improve AggregateProjectPullUpConstantsRule to remove all constant keys
> -----------------------------------------------------------------------
>
> Key: CALCITE-4634
> URL: https://issues.apache.org/jira/browse/CALCITE-4634
> Project: Calcite
> Issue Type: Improvement
> Components: core
> Affects Versions: 1.16.0
> Reporter: Yingyu
> Priority: Major
>
> Optimizer rule *AggregateProjectPullUpConstantsRule* removes constant keys
> from an Aggregate. However, this rules never removes the last column, because
> Aggregate([]) returns 1 row even if its input is empty.
> An enhancement could be done to AggregateProjectPullUpConstantsRule so that
> it removes all constant keys:
> - Remove all constant keys from an Aggregate
> - (Only)When no key is left from previous step (Aggregate becomes
> Aggregate([])), add a filter to the Aggregate([]) so that it returns empty
> dataset if its input is empty.
> E.g.
> {noformat}
> SELECT 'abc' FROM table_name GROUP BY ('abc')
> {noformat}
> will be translated to:
> {noformat}
> SELECT 'abc' FROM table_name GROUP BY () having count(*)>0
> {noformat}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)