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

Wrong offset when SortJoinTransposeRule pushes a Sort with an offset

    XMLWordPrintableJSON

Details

    • Bug
    • Status: In Progress
    • Major
    • Resolution: Unresolved
    • 1.26.0
    • None
    • core

    Description

      The SortJoinTransposeRule will push a sort node past a join, and then duplicate the sort node on top of the join. When the sort node has an offset, we should only apply it once, otherwise we end up skipping twice as many rows as we should. The sort node added on top of the join should have a null offset.

       
      For example the testSortJoinTranspose6 test checks that for this initial plan

      LogicalProject(DEPTNO=[$0], EMPNO=[$2])
        LogicalSort(offset=[2], fetch=[10])
          LogicalJoin(condition=[=($0, $9)], joinType=[right])
            LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
            LogicalTableScan(table=[[CATALOG, SALES, EMP]])
      

      the SortJoinTransposeRule should convert to

      LogicalProject(DEPTNO=[$0], EMPNO=[$2])
        LogicalSort(offset=[2], fetch=[10])
          LogicalJoin(condition=[=($0, $9)], joinType=[right])
            LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
            LogicalSort(offset=[2], fetch=[10])
              LogicalTableScan(table=[[CATALOG, SALES, EMP]])
      

      Which will result in applying the offset twice. Instead the LogicalSort on top of the join should just have a null offset

      Attachments

        Issue Links

          Activity

            People

              rubenql Ruben Q L
              sylvaincrozon Sylvain Crozon
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

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