Danny Chen created CALCITE-3404:

             Summary: Promote plan for AggregateExpandDistinctAggregatesRule 
when all the agg expressions are distinct and have same arguments
                 Key: CALCITE-3404
                 URL: https://issues.apache.org/jira/browse/CALCITE-3404
             Project: Calcite
          Issue Type: Improvement
          Components: core
    Affects Versions: 1.21.0
            Reporter: Danny Chen
            Assignee: Danny Chen
             Fix For: 1.22.0

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

Than plan has regression from
LogicalAggregate(group=[{}], EXPR$0=[SUM($0)], EXPR$1=[COUNT($0)], 
      LogicalTableScan(table=[[CATALOG, SALES, EMP]])
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)], 
        LogicalTableScan(table=[[CATALOG, SALES, EMP]])

The distinct trait actually can be reused.

This message was sent by Atlassian Jira

Reply via email to