You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "suibianwanwan (Jira)" <ji...@apache.org> on 2025/06/21 16:19:00 UTC
[jira] [Commented] (CALCITE-7010) The well-known count bug
[ https://issues.apache.org/jira/browse/CALCITE-7010?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17985109#comment-17985109 ]
suibianwanwan commented on CALCITE-7010:
----------------------------------------
Fixed in [https://github.com/apache/calcite/commit/fd57e660f2dd76af0f68b36a09be6c0a9cd9ca0e|https://github.com/apache/calcite/commit/fd57e660f2dd76af0f68b36a09be6c0a9cd9ca0e]
Thank you for the review [~mbudiu] [~zwhtx]
> 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
> Labels: pull-request-available
>
> 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)