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

Sean Hsuan-Yi Chu commented on CALCITE-841:
-------------------------------------------

I think the problem is the "order of evaluation" suggested by the Topological 
Sort. 

In the given example, we have the following following expressions:

{code}
(1). sum(deptno)
(2). sum(deptno + deptno)
(3). deptno + deptno
{code}
Note that (1) and (2) correspond LogicalWindow and (3) corresponds to a 
LogicalProject.

Apparently, (3) needs to be evaluated before (2). And, there is no dependency 
between (1) and (2). The "current" topological sort will give this order: (1), 
(3), (2). 

Although it is a correct topological order in the mathematical sense,  this 
order actually suggests inserting a Project between Two Windows and splits the 
two LogicalWindow apart. However, if the order (3), (1), (2) is chosen, then, 
given the same window frame, CalcRelSplitter would not split the LogicalWindow.

On the other hand, though the WindowMergeRule (and PushProjectOverWindowRule) 
would probably help resolve this issue, the LogicalWindow should not be split 
apart by CalcRelSplitter at the first place. In this issue, the root cause 
seems in CalcRelSplitter itself

> When the argument of window functions is an expression, redundant windows 
> could be generated
> --------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-841
>                 URL: https://issues.apache.org/jira/browse/CALCITE-841
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Sean Hsuan-Yi Chu
>            Assignee: Julian Hyde
>
> Firstly of all, this issue happens when HepPlanner is used with 
> ProjectToWindowRule.PROJECT rule.
> A query with this pattern:
> {code}
> select fn(col) over w, fn(expr) over w
> from ...
> {code}
> will generate two "LogicalWindow" even if we have only an identical window 
> frame.
> For example, 
> {code}
> select sum(deptno) over(partition by deptno order by sal) as sum1, 
> sum(deptno + deptno) over(partition by deptno order by sal) as sum2
> from emp
> {code}
> gives:
> {code}
> LogicalProject($0=[$2], $1=[$4])
>   LogicalWindow(window#0=[window(partition {1} order by [0] range between 
> UNBOUNDED PRECEDING and CURRENT ROW aggs [SUM($3)])])
>     LogicalProject(SAL=[$0], DEPTNO=[$1], $2=[$2], $3=[+($1, $1)])
>       LogicalProject(SAL=[$5], DEPTNO=[$7], $2=[$9])
>         LogicalWindow(window#0=[window(partition {7} order by [5] range 
> between UNBOUNDED PRECEDING and CURRENT ROW aggs [SUM($7)])])
>           LogicalTableScan(table=[[CATALOG, SALES, EMP]])
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to