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

In AggregateExpandDistinctAggregatesRule, treat all the agg expressions as distinct if they have the same arguments and the non-distinct expressions distinct constraints can be ignored

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.21.0
    • 1.22.0
    • core

    Description

      After CALCITE-3159, the distinct constraint for MAX/MIN/BIT_OR/BIT_AND are removed automatically, so if we have a query:

      select sum(distinct deptno), count(distinct deptno), max(deptno) from emp
      

      The plan has regression from

      LogicalAggregate(group=[{}], EXPR$0=[SUM($0)], EXPR$1=[COUNT($0)], EXPR$2=[MAX($0)])
        LogicalAggregate(group=[{0}])
          LogicalProject(DEPTNO=[$7])
            LogicalTableScan(table=[[CATALOG, SALES, EMP]])
      

      to

      LogicalAggregate(group=[{}], EXPR$0=[SUM($0) FILTER $2], EXPR$1=[COUNT($0) FILTER $2], EXPR$2=[MIN($1) FILTER $3])
        LogicalProject(DEPTNO=[$0], EXPR$2=[$1], $g_0=[=($2, 0)], $g_1=[=($2, 1)])
          LogicalAggregate(group=[{0}], groups=[[{0}, {}]], EXPR$2=[MAX($0)], $g=[GROUPING($0)])
            LogicalProject(DEPTNO=[$7])
              LogicalTableScan(table=[[CATALOG, SALES, EMP]])
      

      The distinct trait actually can be reused.

      Attachments

        Issue Links

          Activity

            People

              danny0405 Danny Chen
              danny0405 Danny Chen
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m