Zhen Chen created CALCITE-7479:
----------------------------------
Summary: Remove redundant aggregate group keys with FD
Key: CALCITE-7479
URL: https://issues.apache.org/jira/browse/CALCITE-7479
Project: Calcite
Issue Type: New Feature
Components: core
Affects Versions: 1.41.0
Reporter: Zhen Chen
{*}Proposal{*}
Add a new aggregate rewrite rule to identify and remove redundant grouping keys
from an {{{}Aggregate{}}}that are functionally determined by preceding grouping
keys. To preserve the original semantics, the rewrite will: * Shorten the
grouping key list of the {{Aggregate}}
* Use {{{}SINGLE_VALUE{}}}to restore the removed grouping column(s)
* Reorder the output columns to match the original order using a {{Project}}
{*}Example of the Planned Change{*}
Original SQL:
{code:java}
select deptno, name, count() as c
from sales.dept
group by deptno, name {code}
Original plan:
{code:java}
LogicalAggregate(group=[{0, 1}], C=[COUNT()])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]]) {code}
Rewritten plan:
{code:java}
LogicalProject(DEPTNO=[$0], NAME=[$1], C=[$2])
LogicalAggregate(group=[{0}], NAME=[SINGLE_VALUE($1)], C=[COUNT()])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]]) {code}
{*}Explanation{*} *
If {{{}name{}}}is functionally determined by {{{}deptno{}}}, then
{{{}name{}}}is removed from the grouping keys.
*
{{{}SINGLE_VALUE{}}}is used to retain the value of the removed column
semantically.
*
The {{{}Project{}}}restores the final output column order and field names.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)