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

Julian Hyde commented on CALCITE-6734:
--------------------------------------

Good catch. The summary should say that it should trim aggregate functions that 
are not used by the consumer. The fix looks good. Some more comments on the 
test would be good - link to this case, and describe in words what is happening 
in the test case. Let’s get this merged for 1.39. 

> RelFieldTrimmer do not trim the input of aggregate properly
> -----------------------------------------------------------
>
>                 Key: CALCITE-6734
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6734
>             Project: Calcite
>          Issue Type: Improvement
>          Components: core
>    Affects Versions: 1.38.0
>            Reporter: Viggo Chen
>            Priority: Minor
>             Fix For: 1.39.0
>
>
> {code:java}
> SELECT DEPTNO,
>        SAL
> FROM
>   (SELECT DEPTNO,
>           SUM(SAL) AS SAL,
>           COUNT(ENAME) AS ENAME
>    FROM EMP
>    WHERE DEPTNO > 100
>    GROUP BY DEPTNO)
> {code}
> For above sql, ENAME is unnecessary to read.
> As show in [https://github.com/apache/calcite/pull/4095] 
> The expected plan is 
> {code:java}
> LogicalAggregate(group=[{2}], SAL=[SUM($1)])
>   LogicalFilter(condition=[>($2, 100)])
>     LogicalProject(EMPNO=[$0], SAL=[$5], DEPTNO=[$7])
>       LogicalTableScan(table=[[scott, EMP]]) {code}
> but what we get now is 
> {code:java}
> LogicalAggregate(group=[{3}], SAL=[SUM($2)])
>   LogicalFilter(condition=[>($3, 100)])
>     LogicalProject(EMPNO=[$0], ENAME=[$1], SAL=[$5], DEPTNO=[$7])
>       LogicalTableScan(table=[[scott, EMP]]) {code}
>  
> PS: EMPNO is kept because it define the collation.



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

Reply via email to