[
https://issues.apache.org/jira/browse/CALCITE-5425?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17725375#comment-17725375
]
Dan Zou commented on CALCITE-5425:
----------------------------------
I add a test in agg.iq `select count(*) from "scott".emp having false` and the
result is an empty set, which is as we expected. I found the reason is that we
have handled `having` expressions that are always false(see [1] and [2]), and
the whole aggregate will be convert to an empty 'values'. After I comment out
this code, I could reproduce this case that the filter will be pushed down
through the aggregate. I think this is still worth optimizing in
'FilterAggregateTransposeRule', but I am not sure how to add a UT to ensure the
right behavior. Do you have any suggestions?
* [1]
https://github.com/apache/calcite/blob/9c33d7aeefe082bf5f7be617ef231e1285418a6c/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java#L3552
* [2]
https://github.com/apache/calcite/blob/9c33d7aeefe082bf5f7be617ef231e1285418a6c/core/src/main/java/org/apache/calcite/tools/RelBuilder.java#L1755
> Should not pushdown filter through aggregate with an empty groupset
> -------------------------------------------------------------------
>
> Key: CALCITE-5425
> URL: https://issues.apache.org/jira/browse/CALCITE-5425
> Project: Calcite
> Issue Type: Bug
> Components: core
> Reporter: Steve Carlin
> Assignee: Dan Zou
> Priority: Major
>
> If we are given a query
> SELECT count(x) FROM tbl HAVING false;
> This query should produce an empty set.
> We should not allow a filter to pass through this aggregate. When the
> aggregate has no group by, there is always one implied group (for the whole
> dataset). So if we apply the filter before the aggregate, the implied group
> will still be created. This is not what we want, since the filter should
> produce an empty set.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)