[ https://issues.apache.org/jira/browse/CALCITE-5894?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17751001#comment-17751001 ]
Alessandro Solimando commented on CALCITE-5894: ----------------------------------------------- [~libenchao], I see your point but since Calcite it's a general-purpose library, I am not sure we can make assumptions on the physical implementation, some can be less mature than others and still benefit from this optimization. I don't have supporting examples in mind, but removing sort might unlock the application of further simplifications, it's hard to think of all the implications but it's reasonable that we are missing some further optimizations because of (extra) sort operators, at the end of the day we have syntactical matching. In summary, I think this rule would be nice to have, even if we decide it's not part of the standard ruleset. What do you think? > Add SortRemoveRedundantRule to remove redundant sort fields if sort fields > contains unique key > ---------------------------------------------------------------------------------------------- > > Key: CALCITE-5894 > URL: https://issues.apache.org/jira/browse/CALCITE-5894 > Project: Calcite > Issue Type: New Feature > Reporter: JingDas > Assignee: JingDas > Priority: Minor > > In some scene, Sort fields can be reduct, if sort fields contain unique key > For Example > {code:java} > SELECT name, Emp.salary FROM Emp > order by empno, ename{code} > where `empno` is a key, `ename` is redundant since `empno` alone is > sufficient to determine the order of any two records. > So the SQL can be optimized as following: > {code:java} > SELECT name, Emp.salary FROM Emp > order by empno{code} > Sorting is an expensive operation, however. Therefore, it is imperative that > sorting > is optimized to avoid unnecessary sort field. > -- This message was sent by Atlassian Jira (v8.20.10#820010)