[
https://issues.apache.org/jira/browse/CALCITE-7492?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18076949#comment-18076949
]
Julian Hyde commented on CALCITE-7492:
--------------------------------------
I understand what you mean, but rather than "deterministic expression" I would
say "expression that has a constant value within the group".
We don't have a way to say that an aggregate function can be reduced if its
values are all the same. But {{SqlSingletonAggFunction}} says what happens if
an aggregate function is applied to a single row, and if an
{{SqlAggFunction.getDistinctOptionality()}} returns {{Optionality.IGNORED}} (as
do {{max}} and {{min}}) then you can assume that it will return the same for
one non-null value as for several. (You still need to be careful of the case
that the value is repeated NULL values.)
> Support deterministic expressions involving only GROUP BY keys as aggregate
> arguments
> -------------------------------------------------------------------------------------
>
> Key: CALCITE-7492
> URL: https://issues.apache.org/jira/browse/CALCITE-7492
> 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, max(sal + 1) as max_plus from emp group by sal, deptno {code}
> It should be optimized as follows (the calculation of the aggregate function
> max is not necessary):
> {code:java}
> select sal, sal + 1 as max_plus from emp group by sal, deptno {code}
> and current plan:
> {code:java}
> LogicalProject(SAL=[$0], MAX_PLUS=[$2])
> LogicalAggregate(group=[{0, 1}], MAX_PLUS=[MAX($2)])
> LogicalProject(SAL=[$5], DEPTNO=[$7], $f2=[+($5, 1)])
> LogicalTableScan(table=[[CATALOG, SALES, EMP]]) {code}
> it may be optimized.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)