Silun Dong created CALCITE-7434:
-----------------------------------

             Summary: Error in new decorrelation algorithm caused by 
FilterJoinRule omitting variablesSet
                 Key: CALCITE-7434
                 URL: https://issues.apache.org/jira/browse/CALCITE-7434
             Project: Calcite
          Issue Type: Bug
          Components: core
    Affects Versions: 1.41.0
            Reporter: Silun Dong
            Assignee: Silun Dong


The following SQL will throw an error when run in CoreQuidemTest2:
{code:java}
SELECT E.EMPNO
FROM EMP E
JOIN DEPT D ON E.DEPTNO = D.DEPTNO
WHERE E.EMPNO > 10 AND D.DEPTNO = (
    SELECT MIN(D_INNER.DEPTNO)
    FROM DEPT D_INNER
    WHERE D_INNER.DEPTNO = E.DEPTNO);


java.lang.AssertionError: Correlation variable $cor0 should be defined at 
org.apache.calcite.adapter.enumerable.EnumerableRelImplementor.getCorrelVariableGetter(EnumerableRelImplementor.java:476){code}
The root cause is that {{FilterJoinRule}} was applied before the subquery was 
removed, and when [building the top 
Filter|https://github.com/apache/calcite/blob/7654dd82162508231cb3ed44e60fed356e931403/core/src/main/java/org/apache/calcite/rel/rules/FilterJoinRule.java#L251],
 the {{variablesSet}} was omitted. 
{{SubQueryRemoveRule.FILTER_SUB_QUERY_TO_MARK_CORRELATE}} performs a strict 
check on {{variablesSet}} when removing a subquery: if it is empty, a {{Join}} 
will be generated instead of a {{{}Correlate{}}}. As a result, the plan does 
not contain a {{{}Correlate{}}}, but correlated variables remain.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to