[
https://issues.apache.org/jira/browse/CALCITE-2798?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16750370#comment-16750370
]
Vladimir Sitnikov commented on CALCITE-2798:
--------------------------------------------
{quote} The union query isn't a clear win. Eliminating duplicates is easier if
the input is sorted, therefore it is not a total waste of effort. Removing the
sort is a cost-based decision{quote}
I'm inclined to cost-based decisions. In other words, a rule (or a set of
rules) that would add equivalences.
{quote}I suppose the sql-to-rel converter{quote}
Someone uses just RelBuilder, so it would be great to have a rule for those
kind of features (like SortRemoveRule)
Of course it might make sense to drop irrelevant sorts at sql-to-rel level (to
reduce planning space), however I'm inclined to threat that as a secondary
option.
> Optimizer should remove unneeded Sort
> -------------------------------------
>
> 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)