[jira] [Commented] (CALCITE-5940) Add the Rule to merge Limit

2023-09-27 Thread Jiajun Xie (Jira)


[ 
https://issues.apache.org/jira/browse/CALCITE-5940?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17769535#comment-17769535
 ] 

Jiajun Xie commented on CALCITE-5940:
-

Fixed in 
[aef9bdb|https://github.com/apache/calcite/commit/aef9bdb5c091e4df84eeb47a9aa70770dd3d3fb8].

Thanks for your PR [~shenlang].

Thanks for your review  [~kgyrtkirk] ,  [~nobigo], [~taoran].

> Add the Rule to merge Limit
> ---
>
> Key: CALCITE-5940
> URL: https://issues.apache.org/jira/browse/CALCITE-5940
> Project: Calcite
>  Issue Type: New Feature
>Reporter: LakeShen
>Assignee: LakeShen
>Priority: Major
>  Labels: pull-request-available
> Fix For: 1.36.0
>
>
> Now in calcite,the Limit will be represented using 
> LogicalSort(fetch=[xx]),but there are few rules to optimize Limit.
> In trino and presto,there are many optimization rules to optimize Limit.
> For example,the sql:
> {code:java}
> select * from nation limit 0 {code}
> The limit 0 will use empty ValuesNode(Calcite LogicalValues) to optimize,so 
> the SQL is not delivered to the Worker compute,the rule could see: 
> [EvaluateZeroLimit|https://github.com/prestodb/presto/blob/fea80c96ddfe4dc42f79c3cff9294b88595275ce/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/EvaluateZeroLimit.java#L28C1-L28C31]
> The sql:
> {code:java}
> select concat('-',N_REGIONKEY) from (select * from nation limit 1) limit 
> 10 {code}
> It would be optimized by 
> [MergeLimits|https://github.com/prestodb/presto/blob/fea80c96ddfe4dc42f79c3cff9294b88595275ce/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/MergeLimits.java#L26]
>  rule to:
> {code:java}
> select concat('-',N_REGIONKEY) from nation limit 10  {code}
> The value of limit takes the minimum of the outer limit and the inner limit.
> The sql:
> {code:java}
> select concat('-',N_REGIONKEY) from (SELECT * FROM nation order BY 
> N_REGIONKEY DESC LIMIT 1) limit 10 {code}
> It would be optimized by 
> [MergeLimitWithTopN|https://github.com/prestodb/presto/blob/fea80c96ddfe4dc42f79c3cff9294b88595275ce/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/MergeLimitWithTopN.java#L28C1-L28C31]
>  rule to:
> {code:java}
> SELECT concat('-',N_REGIONKEY) FROM nation order BY N_REGIONKEY DESC LIMIT 
> 10{code}
> So I propose to add these three rules to Calcite as well, to optimize the 
> Limit case.
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (CALCITE-5940) Add the Rule to merge Limit

2023-09-27 Thread LakeShen (Jira)


[ 
https://issues.apache.org/jira/browse/CALCITE-5940?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17769467#comment-17769467
 ] 

LakeShen commented on CALCITE-5940:
---

Hi [~jiajunbernoulli] ,thanks for your suggestions,I have done for it.

> Add the Rule to merge Limit
> ---
>
> Key: CALCITE-5940
> URL: https://issues.apache.org/jira/browse/CALCITE-5940
> Project: Calcite
>  Issue Type: New Feature
>Reporter: LakeShen
>Assignee: LakeShen
>Priority: Major
>  Labels: pull-request-available
> Fix For: 1.36.0
>
>
> Now in calcite,the Limit will be represented using 
> LogicalSort(fetch=[xx]),but there are few rules to optimize Limit.
> In trino and presto,there are many optimization rules to optimize Limit.
> For example,the sql:
> {code:java}
> select * from nation limit 0 {code}
> The limit 0 will use empty ValuesNode(Calcite LogicalValues) to optimize,so 
> the SQL is not delivered to the Worker compute,the rule could see: 
> [EvaluateZeroLimit|https://github.com/prestodb/presto/blob/fea80c96ddfe4dc42f79c3cff9294b88595275ce/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/EvaluateZeroLimit.java#L28C1-L28C31]
> The sql:
> {code:java}
> select concat('-',N_REGIONKEY) from (select * from nation limit 1) limit 
> 10 {code}
> It would be optimized by 
> [MergeLimits|https://github.com/prestodb/presto/blob/fea80c96ddfe4dc42f79c3cff9294b88595275ce/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/MergeLimits.java#L26]
>  rule to:
> {code:java}
> select concat('-',N_REGIONKEY) from nation limit 10  {code}
> The value of limit takes the minimum of the outer limit and the inner limit.
> The sql:
> {code:java}
> select concat('-',N_REGIONKEY) from (SELECT * FROM nation order BY 
> N_REGIONKEY DESC LIMIT 1) limit 10 {code}
> It would be optimized by 
> [MergeLimitWithTopN|https://github.com/prestodb/presto/blob/fea80c96ddfe4dc42f79c3cff9294b88595275ce/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/MergeLimitWithTopN.java#L28C1-L28C31]
>  rule to:
> {code:java}
> SELECT concat('-',N_REGIONKEY) FROM nation order BY N_REGIONKEY DESC LIMIT 
> 10{code}
> So I propose to add these three rules to Calcite as well, to optimize the 
> Limit case.
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)