[ https://issues.apache.org/jira/browse/CALCITE-5994?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
LakeShen updated CALCITE-5994: ------------------------------ Summary: Add optimization rule to remove Sort when its input's row number is less or equal to one (was: Add the optimize for removing the redundant order by when its source row number is less than or equal 1) > Add optimization rule to remove Sort when its input's row number is less or > equal to one > ---------------------------------------------------------------------------------------- > > Key: CALCITE-5994 > URL: https://issues.apache.org/jira/browse/CALCITE-5994 > Project: Calcite > Issue Type: Improvement > Components: core > Reporter: LakeShen > Assignee: LakeShen > Priority: Major > Labels: pull-request-available > Fix For: 1.36.0 > > > When a Sort's input source max row numer is 1,then we could remove the > redundant Sort,the Sort could be a sorted semantic Sort(offset and fetch is > null). > For example,the sql: > {code:java} > select * from (select * from tableA limit 1) order by c ; > {code} > because the `(select * from tableA limit 1) ` max row number is 1, then we > could remove order by c > {code:java} > select * from tableA limit 1; > {code} > The sql: > {code:java} > select max(totalprice) from orders order by 1 {code} > could converted to: > {code:java} > select max(totalprice) from orders{code} > Above logic are same as Presto/Trino's > [RemoveRedundantSort|https://github.com/prestodb/presto/blob/c21fc28846252cd910d90f046514bf586d7bb5c6/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/RemoveRedundantSort.java#L27] > rule: > -- This message was sent by Atlassian Jira (v8.20.10#820010)