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

Hongze Zhang commented on CALCITE-2798:
---------------------------------------

I am curious about what should happen if we remove the collations for all 
logical rel nodes (except for LogicalSort).

Here is what ISO/IEC 9075-2 says:
{quote}The ordering of the rows of the table specified by the <query 
expression> is guaranteed only for the that immediately contains the <order by 
clause>
{quote}
I can see some optimizations will not be performed on logical rel nodes, 
however it seems we can anyway apply them only for rel nodes that have physical 
conventions.

And I feel that 
[CALCITE-2593|https://issues.apache.org/jira/browse/CALCITE-2593] can also be 
fixed by that.

> Optimizer should remove ORDER BY in sub-query, provided it has no LIMIT or 
> OFFSET
> ---------------------------------------------------------------------------------
>
>                 Key: CALCITE-2798
>                 URL: https://issues.apache.org/jira/browse/CALCITE-2798
>             Project: Calcite
>          Issue Type: Improvement
>          Components: core
>    Affects Versions: 1.18.0
>            Reporter: Vladimir Sitnikov
>            Assignee: Julian Hyde
>            Priority: Major
>
> The following SQL performs sort twice, however inner sort can be eliminated
> {code}select * from (
>   select * from "emps" 
> order by "emps"."deptno"
> ) order by 1 desc{code}
> The same goes for (window calculation will sort on its own)
> {code}select row_number() over (order by "emps"."deptno")  from (
>   select * from "emps" 
> order by "emps"."deptno" desc
> ){code}
> The same goes for SetOp (union, minus):
> {code}select * from (
>   select * from "emps" 
> order by "emps"."deptno"
> ) union select * from (
>   select * from "emps" 
> order by "emps"."deptno" desc
> ){code}
> There might be other cases like that (e.g. Aggregate, Join, Exchange, 
> SortExchange)



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to