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

"OR ... IN" sub-query conversion is wrong

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.12.0
    • Fix Version/s: 1.14.0
    • Component/s: core
    • Labels:

      Description

      This query:

      select * from emp where deptno = 10 or deptno in (
          select dept.deptno from dept where deptno < 5)
      

      Is converted to this by SqlToRelConverter:

      LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
        LogicalFilter(condition=[OR(=($7, 10), true)])
          LogicalJoin(condition=[=($7, $9)], joinType=[inner])
            LogicalTableScan(table=[[CATALOG, SALES, EMP]])
            LogicalAggregate(group=[{0}])
              LogicalProject(DEPTNO=[$0])
                LogicalFilter(condition=[<($0, 5)])
                  LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
      

      But that's not right.

      LogicalFilter(condition=[OR(=($7, 10), true)])

      is always true and is in the wrong place anyway (it's applied after the inner join, where all the deptno = 10 records have already been removed).

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                julianhyde Julian Hyde
                Reporter:
                gian Gian Merlino
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: