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

Jing Zhang commented on CALCITE-4889:
-------------------------------------

[~vladimirsitnikov], 
I try reproduce this problem by adding this sql in `RelOptRulesTest` and 
`SqlToRelConverterTest`, but it's original RelNode tree is as following:
{code:java}
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], 
SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
  LogicalFilter(condition=[NOT(OR(AND(=($0, 7369), =($7, 20)), AND(=($0, 7499), 
=($7, 30))))])
    LogicalTableScan(table=[[CATALOG, SALES, EMP]])
{code}
Would you please share how to reproduce this problem? Do I need apply some 
rules?


> Double join is created for NOT IN
> ---------------------------------
>
>                 Key: CALCITE-4889
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4889
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.28.0
>            Reporter: Vladimir Sitnikov
>            Priority: Major
>
> The following queries yield several joins in the plan.
> I think double joins are excessive here, especially for the first case where 
> all the values are non-nullable.
> {code}select * from "scott".emp where (empno, deptno) not in ((7369, 20), 
> (7499, 30));{code}
> {noformat}
> select * from "scott".emp where empno not in (null, 7782);
> EnumerableCalc(expr#0..12=[{inputs}], expr#13=[0:BIGINT], expr#14=[=($t8, 
> $t13)], expr#15=[IS NULL($t12)], expr#16=[>=($t9, $t8)], expr#17=[AND($t15, 
> $t16)], expr#18=[OR($t14, $t17)], proj#0..7=[{exprs}], $condition=[$t18])
>   EnumerableMergeJoin(condition=[=($10, $11)], joinType=[left])
>     EnumerableSort(sort0=[$10], dir0=[ASC])
>       EnumerableCalc(expr#0..9=[{inputs}], proj#0..9=[{exprs}], EMPNO0=[$t0])
>         EnumerableNestedLoopJoin(condition=[true], joinType=[inner])
>           EnumerableTableScan(table=[[scott, EMP]])
>           EnumerableAggregate(group=[{}], agg#0=[COUNT()], agg#1=[COUNT($0)])
>             EnumerableValues(tuples=[[{ null }, { 7782 }]])
>     EnumerableSort(sort0=[$0], dir0=[ASC])
>       EnumerableCalc(expr#0=[{inputs}], expr#1=[true], proj#0..1=[{exprs}])
>         EnumerableValues(tuples=[[{ null }, { 7782 }]])
> {noformat}
> {noformat}
> select * from "scott".emp where (empno, deptno) not in ((1, 2), (3, null));
> EnumerableCalc(expr#0..14=[{inputs}], expr#15=[0:BIGINT], expr#16=[=($t8, 
> $t15)], expr#17=[IS NULL($t14)], expr#18=[>=($t9, $t8)], expr#19=[IS NOT 
> NULL($t11)], expr#20=[AND($t17, $t18, $t19)], expr#21=[OR($t16, $t20)], 
> proj#0..7=[{exprs}], $condition=[$t21])
>   EnumerableMergeJoin(condition=[AND(=($10, $12), =($11, $13))], 
> joinType=[left])
>     EnumerableSort(sort0=[$10], sort1=[$11], dir0=[ASC], dir1=[ASC])
>       EnumerableCalc(expr#0..9=[{inputs}], proj#0..9=[{exprs}], EMPNO0=[$t0], 
> DEPTNO0=[$t7])
>         EnumerableNestedLoopJoin(condition=[true], joinType=[inner])
>           EnumerableTableScan(table=[[scott, EMP]])
>           EnumerableAggregate(group=[{}], agg#0=[COUNT()], agg#1=[COUNT($0, 
> $1)])
>             EnumerableValues(tuples=[[{ 1, 2 }, { 3, null }]])
>     EnumerableSort(sort0=[$0], sort1=[$1], dir0=[ASC], dir1=[ASC])
>       EnumerableCalc(expr#0..1=[{inputs}], expr#2=[true], proj#0..2=[{exprs}])
>         EnumerableValues(tuples=[[{ 1, 2 }, { 3, null }]])
> {noformat}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to