[ 
https://issues.apache.org/jira/browse/CALCITE-7493?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18076865#comment-18076865
 ] 

Julian Hyde commented on CALCITE-7493:
--------------------------------------

It would be valid to optimize “count(distinct sal)” to “case when sal is null 
then 0 else 1 end”, and I believe we already do that. But optimizing 
“count(sal)” to “1” in that query doesn’t seem valid. 

> Support constant-result aggregates (e.g., COUNT, STDDEV) over GROUP BY keys
> ---------------------------------------------------------------------------
>
>                 Key: CALCITE-7493
>                 URL: https://issues.apache.org/jira/browse/CALCITE-7493
>             Project: Calcite
>          Issue Type: Improvement
>          Components: core
>    Affects Versions: 1.41.0
>            Reporter: Yu Xu
>            Assignee: Yu Xu
>            Priority: Major
>
> Sql like:
> {code:java}
> select sal, count(sal) as cnt, stddev(sal) as sd,
> stddev_pop(sal) as sdp, var_pop(sal) as vp, var_samp(sal) as vs
> from emp group by sal, deptno {code}
>  
> It should be able to be optimized to:
> ||agg funcions||Better simplified results||
> |{{COUNT(sal)}}|{{1}}|
> |{{STDDEV(sal)}}|{{0}}|
> |{{STDDEV_POP(sal)}}|{{0}}|
> and current plan:
> {code:java}
> LogicalProject(SAL=[$0], CNT=[$2], SD=[$3], SDP=[$4], VP=[$5], VS=[$6])
>   LogicalAggregate(group=[{0, 1}], CNT=[COUNT()], SD=[STDDEV($0)], 
> SDP=[STDDEV_POP($0)], VP=[VAR_POP($0)], VS=[VAR_SAMP($0)])
>     LogicalProject(SAL=[$5], DEPTNO=[$7])
>       LogicalTableScan(table=[[CATALOG, SALES, EMP]]) {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to