[
https://issues.apache.org/jira/browse/CALCITE-6009?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17766039#comment-17766039
]
LakeShen edited comment on CALCITE-6009 at 9/17/23 4:16 AM:
------------------------------------------------------------
My idea is to add a new optimization rule called RemoveRedundantSort, which
will remove the redundant sort, as well as the redundant Limit.
But I find in calcite,there is already a rule called SortRemoveRule, so I'm
going to put the optimization logic inside it.
was (Author: shenlang):
My idea is to add a new optimization rule called RemoveRedundantSort, which
will remove the redundant sort, as well as the redundant Limit
> Add the optimize for removing the redundant Limit when a Limit's source row
> number less than Limit's fetch
> ----------------------------------------------------------------------------------------------------------
>
> Key: CALCITE-6009
> URL: https://issues.apache.org/jira/browse/CALCITE-6009
> Project: Calcite
> Issue Type: Improvement
> Components: core
> Reporter: LakeShen
> Priority: Major
>
> In calcite,Limit would be represented by Sort,such as `LogicalSort[fetch =
> 5]`.
> When the Limit' source row number is less than the Limit's fetch,we could
> remove the the redundant Limit.
> For example:
> {code:java}
> SELECT * FROM (VALUES 1,2,3,4,5,6) AS t1 LIMIT 10 {code}
> The plan tree is :
> {code:java}
> LogicalSort(fetch=[10])
> LogicalProject(t1=[$0])
> LogicalValues(tuples=[[{ 1 }, { 2 }, { 3 }, { 4 }, { 5 }, { 6 }]]) {code}
> Because the Limit's source max row number is 6,the Limit's fetch is 10,so we
> could remove the redundant Limit.
> Another example is :
> {code:java}
> SELECT count(*) FROM orders LIMIT 2 {code}
> The plan tree is :
> {code:java}
> LogicalSort(fetch=[2])
> LogicalAggregate(group=[{}], EXPR$0=[COUNT()])
> LogicalTableScan(table=[[tpch, ORDERS]]) {code}
> Because Limit's source max row number is 1,the Limit's fetch is 2, so we
> could remove the redundant Limit.
> The logic is same as presto's RemoveRedundantLimit
> rule:https://github.com/prestodb/presto/blob/50fbc07111ecca60a1a5e62755f095fa204120d0/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/RemoveRedundantLimit.java#L27
--
This message was sent by Atlassian Jira
(v8.20.10#820010)