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

AggregateExpandDistinctAggregatesRule does not expand aggregates properly

    Details

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

      Description

      A query with two aggregate calls, sum(comm) and min(comm), it produces an incorrect plan. The main problem is that it fails to index the input of sum(comm) and min(comm) properly. This seems to only happen in the special case where there is only one distinct aggregate call.

      SELECT deptno, sum(comm), min(comm), SUM(DISTINCT sal) FROM emp GROUP BY deptno
      

      AggregateExpandDistinctAggregatesRule produces the following plan in this case.

      LogicalAggregate(group=[{0}], EXPR$1=[SUM($3)], EXPR$2=[MIN($3)], EXPR$3=[SUM($1)])
        LogicalAggregate(group=[{0, 2}], EXPR$1=[SUM($1)], EXPR$2=[MIN($1)])
          LogicalProject(DEPTNO=[$7], COMM=[$6], SAL=[$5])
            LogicalTableScan(table=[[CATALOG, SALES, EMP]])
      

      In the above plan, the top LogicalAggregate EXPR$1=[SUM($3]] is incorrect, it should be SUM($2).

        Attachments

          Activity

            People

            • Assignee:
              julianhyde Julian Hyde
              Reporter:
              minjikim MinJi Kim
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: