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

Julian Hyde commented on CALCITE-841:
-------------------------------------

You have a problem with a rule so are fixing the engine; and to fix the engine 
you fix a general-purpose algorithm (topological sort) which was not producing 
wrong results in the first place. Doesn't that seem wrong?

I'm not sure where the *real* problem is, but I'm pretty sure it would help a 
lot if there were something like a WindowMergeRule. Then you would not be so 
sensitive to the order in which rules get fired. (Since these rules are 
supposed to work on multiple engines, you must not be too sensitive.)

If after that you still want to fix TopologicalOrderIterator, let's do it by 
making "empties" a priority queue and you can pass in a comparator to the 
constructor. (In your case the comparator would sort based on the number of 
outgoing edges.) That would also fix the O(n ^ 2) running cost of your 
algorithm.

> 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