[ 
https://issues.apache.org/jira/browse/CALCITE-7702?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Mihai Budiu resolved CALCITE-7702.
----------------------------------
    Fix Version/s: 1.43.0
       Resolution: Fixed

Fixed in 
[https://github.com/apache/calcite/commit/dd067b6f9292eb828c5bb1c6d9c134872d3ffae9]

Thank you for the report and fix [~zzwqqq] 

> 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
>             Fix For: 1.43.0
>
>
> 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)

Reply via email to