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

Enable ProjectSetOpTransposeRule for UNION (distinct) SetOp operator

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Won't Fix
    • 1.16.0
    • 1.17.0
    • core
    • None

    Description

      Currently ProjectSetOpTransposeRule rule can transpose UnionAll SetOp and Project RelNodes. It disabled for Union (distinct) SetOp operator.

      // cannot push project past a distinct
      if (!setOp.all) {
       return;
      }
      
      

      After removing this check the rule works fineĀ and transposesĀ Union (distinct) SetOp and Project RelNodes.

      Test case for reproduce (RelOptRulesTest class):

      
      @Test public void testPushProjectPastUnionDistinct() {
       checkPlanning(ProjectSetOpTransposeRule.INSTANCE,
       "select sal from "
       + "(select * from emp e1 union select * from emp e2)");
      }
      
          <TestCase name="testPushProjectPastUnionDistinct">
            <Resource name="sql">
              <![CDATA[select sal from (select * from emp e1 union all select * from emp e2)]]>
            </Resource>
            <Resource name="planBefore">
              <![CDATA[
      LogicalProject(SAL=[$5])
        LogicalUnion(all=[false])
          LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
            LogicalTableScan(table=[[CATALOG, SALES, EMP]])
          LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
            LogicalTableScan(table=[[CATALOG, SALES, EMP]])
      ]]>
            </Resource>
            <Resource name="planAfter">
              <![CDATA[
      LogicalUnion(all=[false])
        LogicalProject(SAL=[$5])
          LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
            LogicalTableScan(table=[[CATALOG, SALES, EMP]])
        LogicalProject(SAL=[$5])
          LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
            LogicalTableScan(table=[[CATALOG, SALES, EMP]])
      ]]>
            </Resource>
          </TestCase>
      
      

      Attachments

        Issue Links

          Activity

            People

              vitalii Vitalii Diravka
              vitalii Vitalii Diravka
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: