You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Jesus Camacho Rodriguez (JIRA)" <ji...@apache.org> on 2017/06/20 09:57:00 UTC

[jira] [Created] (CALCITE-1852) Fix for UnionMergeRule to deal correctly with EXCEPT

Jesus Camacho Rodriguez created CALCITE-1852:
------------------------------------------------

             Summary: Fix for UnionMergeRule to deal correctly with EXCEPT
                 Key: CALCITE-1852
                 URL: https://issues.apache.org/jira/browse/CALCITE-1852
             Project: Calcite
          Issue Type: Bug
            Reporter: Jesus Camacho Rodriguez
            Assignee: Jesus Camacho Rodriguez
             Fix For: 1.13.0


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

For instance, given the following query:
{code:sql}
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
{code}

The plan produced by the rule is:
{code}
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]])
{code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)