Skip to content

Commit

Permalink
[CALCITE-2295] Correlated SubQuery with Project will generate error plan
Browse files Browse the repository at this point in the history
  • Loading branch information
NobiGo authored and mihaibudiu committed Jan 21, 2025
1 parent f9cc84f commit 2a89ec9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9116,6 +9116,16 @@ public interface Config extends RelRule.Config {
.check();
}

/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-2295">[CALCITE-2295]
* Correlated SubQuery with Project will generate error plan</a>. */
@Test public void testDecorrelationWithProject() throws Exception {
final String sql = "select sal,\n"
+ "exists (select * from emp_b where emp.deptno = emp_b.deptno)\n"
+ "from sales.emp";
sql(sql).withSubQueryRules().withLateDecorrelate(true).check();
}

/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-3296">[CALCITE-3296]
* Decorrelator gives empty result after decorrelating sort rel with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2483,6 +2483,44 @@ LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$
LogicalAggregate(group=[{0}])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
<TestCase name="testDecorrelationWithProject">
<Resource name="sql">
<![CDATA[select sal,
exists (select * from emp_b where emp.deptno = emp_b.deptno)
from sales.emp]]>
</Resource>
<Resource name="planBefore">
<![CDATA[
LogicalProject(variablesSet=[[$cor0]], SAL=[$5], EXPR$1=[EXISTS({
LogicalFilter(condition=[=($cor0.DEPTNO, $7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP_B]])
})])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planMid">
<![CDATA[
LogicalProject(SAL=[$5], EXPR$1=[IS NOT NULL($9)])
LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{7}])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalAggregate(group=[{0}])
LogicalProject(i=[true])
LogicalFilter(condition=[=($cor0.DEPTNO, $7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP_B]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(SAL=[$5], EXPR$1=[IS NOT NULL($10)])
LogicalJoin(condition=[=($7, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(DEPTNO=[$0], $f1=[true])
LogicalAggregate(group=[{0}])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP_B]])
]]>
</Resource>
</TestCase>
Expand Down

0 comments on commit 2a89ec9

Please sign in to comment.