[
https://issues.apache.org/jira/browse/CALCITE-7702?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18103203#comment-18103203
]
zzwqqq commented on CALCITE-7702:
---------------------------------
[~julianhyde] Thanks for taking a look. ON TRUE has no join keys, but
JoinAggregateTransposeRule adds all fields from the right input to the new
group set. In this case, the right input only contains DEPTNO, so DEPTNO
becomes a group key after the transformation.
I kept RelMetadataQuery.isEmpty because it already uses MinRowCount. It returns
false only when the minimum row count is greater than zero. Therefore,
Boolean.FALSE.equals(...) requires the input to be proved non-empty.
I added planner tests for an aggregate with an empty group set when its input
is:
- empty;
- potentially empty;
- 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)