[ 
https://issues.apache.org/jira/browse/CALCITE-7479?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Zhen Chen updated CALCITE-7479:
-------------------------------
    Description: 
{*}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.

  was:
{*}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.


> 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
>            Priority: Minor
>
> {*}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)

Reply via email to