[ 
https://issues.apache.org/jira/browse/CALCITE-1511?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Julian Hyde updated CALCITE-1511:
---------------------------------
    Description: 
When planning a query with more than one EXISTS in the same WHERE clause, 
Calcite throws in the {{RelDecorrelator.allLessThan}} method.

Calcite hits an assertion for following query (planning is done by calling 
{{SubQueryRemoveRule}} followed by {{decorrelateQuery}}):

{code}  select * from emp
where EXISTS (select * from emp e where emp.deptno = e.deptno)
AND NOT EXISTS (select * from emp ee where ee.job = emp.job AND ee.sal=34) 
{code}

Assertion
{noformat} Caused by: java.lang.AssertionError: out of range; value: 3, limit: 
3 {noformat}

This assertion is hit in {{RelDecorrelator's allLessThan}} which is called 
while registering newly de-correlated {{LogicalAggregate}}.

Plan just before {{SubQueryRemoveRule}}:
{noformat}
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], 
SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
  LogicalFilter(condition=[AND(EXISTS({
LogicalFilter(condition=[=($cor0.DEPTNO, $7)])
  LogicalTableScan(table=[[CATALOG, SALES, EMP]])
}), NOT(EXISTS({
LogicalFilter(condition=[AND(=($2, $cor0.JOB), =($5, 34))])
  LogicalTableScan(table=[[CATALOG, SALES, EMP]])
})))], variablesSet=[[$cor0]])
    LogicalTableScan(table=[[CATALOG, SALES, EMP]])
{noformat}

Plan just after {{SubQueryRemoveRule}}:
{noformat}
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], 
SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
  LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], 
SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
    LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], 
SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], i=[$9])
      LogicalFilter(condition=[AND(OR(IS NULL($12), =($10, 0)), OR(>=($11, 
$10), =($10, 0)))])
        LogicalJoin(condition=[true], joinType=[left])
          LogicalJoin(condition=[true], joinType=[inner])
            LogicalCorrelate(correlation=[$cor0], joinType=[INNER], 
requiredColumns=[{7}])
              LogicalTableScan(table=[[CATALOG, SALES, EMP]])
              LogicalAggregate(group=[{0}])
                LogicalProject(i=[true])
                  LogicalFilter(condition=[=($cor0.DEPTNO, $7)])
                    LogicalTableScan(table=[[CATALOG, SALES, EMP]])
            LogicalAggregate(group=[{}], c=[COUNT()], ck=[COUNT($0, $1, $2, $3, 
$4, $5, $6, $7, $8)])
              LogicalFilter(condition=[AND(=($2, $cor0.JOB), =($5, 34))])
                LogicalTableScan(table=[[CATALOG, SALES, EMP]])
          LogicalAggregate(group=[{0}])
            LogicalProject(i=[true])
              LogicalFilter(condition=[AND(=($2, $cor0.JOB), =($5, 34))])
                LogicalTableScan(table=[[CATALOG, SALES, EMP]])
{noformat}


  was:
Calcite hits an assertion for following query (planning is done by calling 
SubQueryRemoveRule followed by decorrelateQuery )

{code}  select * from emp where EXISTS (select * from emp e where emp.deptno = 
e.deptno) AND NOT EXISTS (select * from emp ee where ee.job = emp.job AND 
ee.sal=34) {code}

Assertion
{noformat} Caused by: java.lang.AssertionError: out of range; value: 3, limit: 
3 {noformat}

This assertion is hit in {noformat} RelDecorrelator's allLessThan {noformat} 
which is called while registering newly de-correlated LogicalAggregate. 

Plan just before SubqueryRemoveRule
{noformat}
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], 
SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
  LogicalFilter(condition=[AND(EXISTS({
LogicalFilter(condition=[=($cor0.DEPTNO, $7)])
  LogicalTableScan(table=[[CATALOG, SALES, EMP]])
}), NOT(EXISTS({
LogicalFilter(condition=[AND(=($2, $cor0.JOB), =($5, 34))])
  LogicalTableScan(table=[[CATALOG, SALES, EMP]])
})))], variablesSet=[[$cor0]])
    LogicalTableScan(table=[[CATALOG, SALES, EMP]])
{noformat}

Plan just after SubqueryRemoveRule:
{noformat}

LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], 
SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
  LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], 
SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
    LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], 
SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], i=[$9])
      LogicalFilter(condition=[AND(OR(IS NULL($12), =($10, 0)), OR(>=($11, 
$10), =($10, 0)))])
        LogicalJoin(condition=[true], joinType=[left])
          LogicalJoin(condition=[true], joinType=[inner])
            LogicalCorrelate(correlation=[$cor0], joinType=[INNER], 
requiredColumns=[{7}])
              LogicalTableScan(table=[[CATALOG, SALES, EMP]])
              LogicalAggregate(group=[{0}])
                LogicalProject(i=[true])
                  LogicalFilter(condition=[=($cor0.DEPTNO, $7)])
                    LogicalTableScan(table=[[CATALOG, SALES, EMP]])
            LogicalAggregate(group=[{}], c=[COUNT()], ck=[COUNT($0, $1, $2, $3, 
$4, $5, $6, $7, $8)])
              LogicalFilter(condition=[AND(=($2, $cor0.JOB), =($5, 34))])
                LogicalTableScan(table=[[CATALOG, SALES, EMP]])
          LogicalAggregate(group=[{0}])
            LogicalProject(i=[true])
              LogicalFilter(condition=[AND(=($2, $cor0.JOB), =($5, 34))])
                LogicalTableScan(table=[[CATALOG, SALES, EMP]])
{noformat}



> RelDecorrelator's allLessThan failing for NOT EXISTS sub-query
> --------------------------------------------------------------
>
>                 Key: CALCITE-1511
>                 URL: https://issues.apache.org/jira/browse/CALCITE-1511
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>            Reporter: Vineet Garg
>            Assignee: Julian Hyde
>              Labels: sub-query
>
> When planning a query with more than one EXISTS in the same WHERE clause, 
> Calcite throws in the {{RelDecorrelator.allLessThan}} method.
> Calcite hits an assertion for following query (planning is done by calling 
> {{SubQueryRemoveRule}} followed by {{decorrelateQuery}}):
> {code}  select * from emp
> where EXISTS (select * from emp e where emp.deptno = e.deptno)
> AND NOT EXISTS (select * from emp ee where ee.job = emp.job AND ee.sal=34) 
> {code}
> Assertion
> {noformat} Caused by: java.lang.AssertionError: out of range; value: 3, 
> limit: 3 {noformat}
> This assertion is hit in {{RelDecorrelator's allLessThan}} which is called 
> while registering newly de-correlated {{LogicalAggregate}}.
> Plan just before {{SubQueryRemoveRule}}:
> {noformat}
> LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], 
> SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
>   LogicalFilter(condition=[AND(EXISTS({
> LogicalFilter(condition=[=($cor0.DEPTNO, $7)])
>   LogicalTableScan(table=[[CATALOG, SALES, EMP]])
> }), NOT(EXISTS({
> LogicalFilter(condition=[AND(=($2, $cor0.JOB), =($5, 34))])
>   LogicalTableScan(table=[[CATALOG, SALES, EMP]])
> })))], variablesSet=[[$cor0]])
>     LogicalTableScan(table=[[CATALOG, SALES, EMP]])
> {noformat}
> Plan just after {{SubQueryRemoveRule}}:
> {noformat}
> LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], 
> SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
>   LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], 
> SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
>     LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], 
> SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], i=[$9])
>       LogicalFilter(condition=[AND(OR(IS NULL($12), =($10, 0)), OR(>=($11, 
> $10), =($10, 0)))])
>         LogicalJoin(condition=[true], joinType=[left])
>           LogicalJoin(condition=[true], joinType=[inner])
>             LogicalCorrelate(correlation=[$cor0], joinType=[INNER], 
> requiredColumns=[{7}])
>               LogicalTableScan(table=[[CATALOG, SALES, EMP]])
>               LogicalAggregate(group=[{0}])
>                 LogicalProject(i=[true])
>                   LogicalFilter(condition=[=($cor0.DEPTNO, $7)])
>                     LogicalTableScan(table=[[CATALOG, SALES, EMP]])
>             LogicalAggregate(group=[{}], c=[COUNT()], ck=[COUNT($0, $1, $2, 
> $3, $4, $5, $6, $7, $8)])
>               LogicalFilter(condition=[AND(=($2, $cor0.JOB), =($5, 34))])
>                 LogicalTableScan(table=[[CATALOG, SALES, EMP]])
>           LogicalAggregate(group=[{0}])
>             LogicalProject(i=[true])
>               LogicalFilter(condition=[AND(=($2, $cor0.JOB), =($5, 34))])
>                 LogicalTableScan(table=[[CATALOG, SALES, EMP]])
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to