[
https://issues.apache.org/jira/browse/CALCITE-6038?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
LakeShen updated CALCITE-6038:
------------------------------
Description:
In Calcite , the TopN is represented by `Sort`,when a TopN's input source row
numer is 1,then we could remove the redundant TopN.
For example,the sql:
{code:java}
SELECT count(*) FROM orders ORDER BY 1 LIMIT 10 {code}
because the `SELECT count(*) FROM orders ` row number is 1, then we could
remove `ORDER BY 1 LIMIT 10 `,after the
{code:java}
SELECT count(*) FROM orders {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:
> Add optimization rule to remove redundant TopN when its input's row number is
> less or equal to one
> --------------------------------------------------------------------------------------------------
>
> Key: CALCITE-6038
> URL: https://issues.apache.org/jira/browse/CALCITE-6038
> Project: Calcite
> Issue Type: New Feature
> Reporter: LakeShen
> Priority: Major
>
> In Calcite , the TopN is represented by `Sort`,when a TopN's input source row
> numer is 1,then we could remove the redundant TopN.
> For example,the sql:
> {code:java}
> SELECT count(*) FROM orders ORDER BY 1 LIMIT 10 {code}
> because the `SELECT count(*) FROM orders ` row number is 1, then we could
> remove `ORDER BY 1 LIMIT 10 `,after the
> {code:java}
> SELECT count(*) FROM orders {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)