[
https://issues.apache.org/jira/browse/CALCITE-7010?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17985169#comment-17985169
]
Mihai Budiu commented on CALCITE-7010:
--------------------------------------
You should probably add an assertion that the two fields compared have the same
type.
You can also probably take advantage of the new feature which allows using
!explain in quidem tests to produce more readable plans for the rewritten
queries.
> 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
> Fix For: 1.41.0
>
>
> 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)