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

Fix for UnionMergeRule to deal correctly with EXCEPT

    Details

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

      Description

      EXCEPT might be merged by the rule even when we should not, mingling the different branches.

      For instance, given the following query:

      select * from (
        select name, deptno from
        (
          select name, deptno, count(1) from dept group by name, deptno
          except all
          select name, deptno, 1 from dept
        ) subq
        except all
        select name, deptno from
        (
          select name, deptno, 1 from dept
          except all
          select name, deptno, count(1) from dept group by name, deptno
        ) subq2
      ) a
      except all
      select name, deptno from dept
      ) aa
      

      The plan produced by the rule is:

      LogicalMinus(all=[true])
        LogicalProject(NAME=[$0], DEPTNO=[$1])
          LogicalAggregate(group=[{0, 1}], EXPR$2=[COUNT()])
            LogicalProject(NAME=[$1], DEPTNO=[$0], $f2=[1])
              LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
        LogicalProject(NAME=[$0], DEPTNO=[$1])
          LogicalProject(NAME=[$1], DEPTNO=[$0], EXPR$2=[1])
            LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
        LogicalProject(NAME=[$0], DEPTNO=[$1])
          LogicalAggregate(group=[{0, 1}], EXPR$2=[COUNT()])
            LogicalProject(NAME=[$1], DEPTNO=[$0], $f2=[1])
              LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
        LogicalProject(NAME=[$0], DEPTNO=[$1])
          LogicalProject(NAME=[$1], DEPTNO=[$0], EXPR$2=[1])
            LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
        LogicalProject(NAME=[$1], DEPTNO=[$0])
          LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
      

        Activity

        Hide
        jcamachorodriguez Jesus Camacho Rodriguez added a comment -

        Resolved in release 1.13.0 (2017-06-26).

        Show
        jcamachorodriguez Jesus Camacho Rodriguez added a comment - Resolved in release 1.13.0 (2017-06-26).
        Show
        jcamachorodriguez Jesus Camacho Rodriguez added a comment - - edited Fixed in http://git-wip-us.apache.org/repos/asf/calcite/commit/f63a65a .

          People

          • Assignee:
            jcamachorodriguez Jesus Camacho Rodriguez
            Reporter:
            jcamachorodriguez Jesus Camacho Rodriguez
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development