Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-5138

Join on condition generates wrong plan when the condition is sub-query

    XMLWordPrintableJSON

Details

    Description

      The SQL:

      SELECT emp.deptno, emp.sal
      FROM dept
               LEFT JOIN emp ON (SELECT AVG(emp.sal) > 0 FROM emp) 

      Calcite generates the wrong plan:

       EnumerableCalc(expr#0..4=[{inputs}], DEPTNO=[$t3], SAL=[$t2])
         EnumerableNestedLoopJoin(condition=[$0], joinType=[left])
           EnumerableCalc(expr#0..2=[{inputs}], DEPTNO=[$t0])
             EnumerableTableScan(table=[[scott, DEPT]])
           EnumerableNestedLoopJoin(condition=[true], joinType=[left])
             EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], SAL=[$t5], DEPTNO=[$t7])
               EnumerableTableScan(table=[[scott, EMP]])
             EnumerableAggregate(group=[{}], DUMMY=[COUNT()])
               EnumerableAggregate(group=[{}], agg#0=[$SUM0($5)], agg#1=[COUNT($5)])
                 EnumerableTableScan(table=[[scott, EMP]])

      As above plan, the out NestedLoopJoin condition will be deptno column, not the AVG(emp.sal) > 0 condition.

      Attachments

        Issue Links

          Activity

            People

              nobigo xiong duan
              nobigo xiong duan
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 0.5h
                  0.5h