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

RelDecorrelator outputs wrong plan for correlate sort with fetch limit

    XMLWordPrintableJSON

Details

    Description

      For query

      SELECT deptno, ename
        FROM
          (SELECT DISTINCT deptno FROM emp) t1,
            LATERAL (
              SELECT ename, sal
              FROM emp
              WHERE deptno = t1.deptno
              ORDER BY sal
              DESC LIMIT 3
            )
      

      The current plan after decorrelation is

      LogicalProject(DEPTNO=[$0], ENAME=[$1])
        LogicalJoin(condition=[=($0, $3)], joinType=[inner])
          LogicalAggregate(group=[{0}])
            LogicalProject(DEPTNO=[$7])
              LogicalTableScan(table=[[CATALOG, SALES, EMP]])
          LogicalSort(sort0=[$1], dir0=[DESC], fetch=[3])
            LogicalProject(ENAME=[$1], SAL=[$5], DEPTNO=[$7])
              LogicalTableScan(table=[[CATALOG, SALES, EMP]])
      

      which is wrong, because the partition sort(on sal) changes to global.

      Attachments

        Issue Links

          Activity

            People

              danny0405 Danny Chen
              danny0405 Danny Chen
              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 - 20m
                  20m