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

Optimization CoreRules.AGGREGATE_EXPAND_DISTINCT_AGGREGATES_TO_JOIN produces incorrect results for aggregates with groupSets

    XMLWordPrintableJSON

Details

    Description

      The optimization rule does not seem to consider the groupSets at all.
      The following two queries produce the same resulting plan:

      select count(distinct deptno) as cd, count(*) as c
      from emp
      group by cube(deptno)
      
      select count(distinct deptno) as cd, count(*) as c
      from emp
      group by deptno
      

      (Notice that one query has a cube, while the other one doesn't)
      The produced plan is:

          LogicalProject(CD=[$1], C=[$2]), id = 196
            LogicalAggregate(group=[{0}], CD=[COUNT($0)], C=[$SUM0($1)]), id = 201
              LogicalAggregate(group=[{0}], C=[COUNT()]), id = 198
                LogicalProject(DEPTNO=[$8]), id = 192
                  LogicalTableScan(table=[[schema, EMP]]), id = 163
      

      Attachments

        Issue Links

          Activity

            People

              mbudiu Mihai Budiu
              mbudiu Mihai Budiu
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: