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

suibianwanwan edited comment on CALCITE-7010 at 6/22/25 5:27 PM:
-----------------------------------------------------------------

>From the plan, I don't understand why it's DEPTNO = DNAME, unless the original 
>plan was wrong.
{code:java}
            LogicalJoin(condition=[IS NOT DISTINCT FROM($0, $1)], 
joinType=[left]), id = 504
              LogicalAggregate(group=[{0}]), id = 496
                LogicalTableScan(table=[[schema, dept]]), id = 389
              LogicalAggregate(group=[{0}], EXPR$0=[COUNT()]), id = 502
                LogicalProject(deptno=[$8]), id = 500
                  LogicalFilter(condition=[IS NOT NULL($8)]), id = 498
                    LogicalTableScan(table=[[schema, emp]]), id = 391 {code}
On the left side of the join, \{0} corresponds to the *deptno* in the dept 
table, as can be seen from *requiredColumns=[\{0}]* .

On the right side of the join, *$8* refers to the *deptno* in the emp table, 
which corresponds to *LogicalFilter(condition=[=($8, $cor0.deptno)]), id = 420*

 

Edit: Yes, the plan here seems fine (we were editing the comments 
simultaneously, so I didn't see it).

 


was (Author: JIRAUSER301334):
>From the plan, I don't understand why it's DEPTNO = DNAME, unless the original 
>plan was wrong.

 
{code:java}
            LogicalJoin(condition=[IS NOT DISTINCT FROM($0, $1)], 
joinType=[left]), id = 504
              LogicalAggregate(group=[{0}]), id = 496
                LogicalTableScan(table=[[schema, dept]]), id = 389
              LogicalAggregate(group=[{0}], EXPR$0=[COUNT()]), id = 502
                LogicalProject(deptno=[$8]), id = 500
                  LogicalFilter(condition=[IS NOT NULL($8)]), id = 498
                    LogicalTableScan(table=[[schema, emp]]), id = 391 {code}
On the left side of the join, \{0} corresponds to the *deptno* in the dept 
table, as can be seen from *requiredColumns=[\\{0}]* .

On the right side of the join, *$8* refers to the *deptno* in the emp table, 
which corresponds to *LogicalFilter(condition=[=($8, $cor0.deptno)]), id = 420*

 

 

Edit: Yes, the plan here seems fine (we were editing the comments 
simultaneously, so I didn't see it).

 

> 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)

Reply via email to