[
https://issues.apache.org/jira/browse/CALCITE-7702?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18103166#comment-18103166
]
Julian Hyde commented on CALCITE-7702:
--------------------------------------
I acknowledge that there are pitfalls when creating an Aggregate with an empty
group key on a potentially-empty input.
But please explain why your example query would trigger this problem. I don't
quite see how the rule could convert an Aggregate with no group keys to an
Aggregate above a join with one group key. I recall the join key being promoted
to the group key, but in your example the join key is empty.
In the spec you say "known to be non-empty" but in the implementation checks
"not the empty relation" and in the test you pass an empty relation. You should
use RelMdMinRowCount, and test with relations that can and cannot be proved to
be non-empty.
> JoinAggregateTransposeRule produces a non-equivalent plan when the aggregate
> with empty input and empty group set
> -----------------------------------------------------------------------------------------------------------------
>
> Key: CALCITE-7702
> URL: https://issues.apache.org/jira/browse/CALCITE-7702
> Project: Calcite
> Issue Type: Bug
> Reporter: zzwqqq
> Assignee: zzwqqq
> Priority: Major
> Labels: pull-request-available
>
> JoinAggregateTransposeRule produces a non-equivalent plan when the aggregate
> with empty input empty group set
> For example, using the SCOTT schema:
> {code:sql}
> select g.emp_count, d.deptno
> from (select count(*) as emp_count from emp where false) g
> join (select deptno from dept where deptno = 10) d on true;
> {code}
> The query returns:
> {code:java}
> emp_count | deptno
> -----------+--------
> 0 | 10
> (1 row)
> {code}
> The rewritten plan has the same behavior as follow,and returns no rows:
> {code:sql}
> select count(*) as emp_count, d.deptno
> from (select * from emp where false) e
> join (select deptno from dept where deptno = 10) d on true
> group by d.deptno;
> {code}
> COUNT without GROUP BY returns one row for empty input. After the aggregate
> is pulled above the join, DEPTNO becomes a group key. An aggregate with a
> group key returns no rows for empty input.
> The rule should not apply in this case unless the aggregate input is known to
> be non-empty.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)