[ 
https://issues.apache.org/jira/browse/CALCITE-7010?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17951161#comment-17951161
 ] 

suibianwanwan commented on CALCITE-7010:
----------------------------------------

More discussion at CALCITE-5743.

> The well-known count bug
> ------------------------
>
>                 Key: CALCITE-7010
>                 URL: https://issues.apache.org/jira/browse/CALCITE-7010
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: suibianwanwan
>            Assignee: suibianwanwan
>            Priority: Major
>
> What is the count-bug: [Optimization of Nested SQL Queries 
> Revisited|https://dl.acm.org/doi/pdf/10.1145/38714.38723]
> {quote}The well-known "count-bug" is not specific to the count aggregate, and 
> outer-join does not solve it. The anomaly can occur on any aggregate 
> function; aggregates need modification to distiguish empty set from null 
> values; and optimizing out the outerjoin depends on utilization context
> {quote}
> Test in sub-query.iq:
> {code:java}
> SELECT deptno
> FROM dept d
> WHERE 0 IN (
>     SELECT COUNT(*)
>     FROM emp e
>     WHERE d.deptno = e.deptno
> );
> +--------+
> | DEPTNO |
> +--------+
> |     40 |
> +--------+
> (1 row)
> !ok
> SELECT deptno
> FROM dept d
> WHERE 'Regular' IN (
>     SELECT CASE WHEN SUM(sal) > 10 then 'VIP' else 'Regular' END expr
>     FROM emp e
>     WHERE d.deptno = e.deptno
> );
> +--------+
> | DEPTNO |
> +--------+
> |     40 |
> +--------+
> (1 row)
> !ok
> {code}
> Actual results:
> {code:java}
> +--------+
> | DEPTNO |
> +--------+
> +--------+
> (0 rows)
> +--------+
> | DEPTNO |
> +--------+
> +--------+
> (0 rows)
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to