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

Jiajun Xie updated CALCITE-6632:
--------------------------------
    Description: 
Here is a simple case:
{code:java}
select sum(100) over (partition by deptno order by sal) as s -- window1
from emp
union all
select sum(1000) over(partition by deptno order by sal) as s -- window2
from emp {code}
window1 is different from window2.

But window digest missing constants, the window2 will be replaced by window1 
after optimized.

 

The 
{code:java}
LogicalUnion(all=[true])
  LogicalProject($0=[$2])
    LogicalWindow(window#0=[window(partition {1} order by [0] aggs [SUM($2)])]) 
-- window1 digest
      LogicalProject(SAL=[$5], DEPTNO=[$7])
        LogicalTableScan(table=[[CATALOG, SALES, EMP]])
  LogicalProject($0=[$2])
    LogicalWindow(window#0=[window(partition {1} order by [0] aggs [SUM($2)])]) 
-- window1 digest
      LogicalProject(SAL=[$5], DEPTNO=[$7])
        LogicalTableScan(table=[[CATALOG, SALES, EMP]]) {code}

  was:
Here is a simple case:
{code:java}
select sum(100) over (partition by deptno order by sal) as s -- window1
from emp
union all
select sum(1000) over(partition by deptno order by sal) as s -- window2
from emp {code}
window1 is different from window2.

But window digest missing constants, the window2 will be replaced by window1 
after optimized.


> Wrong optimization because window missing constants in digest
> -------------------------------------------------------------
>
>                 Key: CALCITE-6632
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6632
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>         Environment: !image-2024-10-17-10-41-11-032.png|width=482,height=203!
>            Reporter: Jiajun Xie
>            Assignee: Jiajun Xie
>            Priority: Major
>         Attachments: image-2024-10-17-10-41-11-032.png
>
>
> Here is a simple case:
> {code:java}
> select sum(100) over (partition by deptno order by sal) as s -- window1
> from emp
> union all
> select sum(1000) over(partition by deptno order by sal) as s -- window2
> from emp {code}
> window1 is different from window2.
> But window digest missing constants, the window2 will be replaced by window1 
> after optimized.
>  
> The 
> {code:java}
> LogicalUnion(all=[true])
>   LogicalProject($0=[$2])
>     LogicalWindow(window#0=[window(partition {1} order by [0] aggs 
> [SUM($2)])]) -- window1 digest
>       LogicalProject(SAL=[$5], DEPTNO=[$7])
>         LogicalTableScan(table=[[CATALOG, SALES, EMP]])
>   LogicalProject($0=[$2])
>     LogicalWindow(window#0=[window(partition {1} order by [0] aggs 
> [SUM($2)])]) -- window1 digest
>       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