Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-5940

Add the Rule to merge Limit

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.36.0
    • None

    Description

      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:

      select * from nation limit 0 

      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

      The sql:

      select concat('-',N_REGIONKEY) from (select * from nation limit 10000) limit 10 

      It would be optimized by MergeLimits rule to:

      select concat('-',N_REGIONKEY) from nation limit 10  

      The value of limit takes the minimum of the outer limit and the inner limit.

      The sql:

      select concat('-',N_REGIONKEY) from (SELECT * FROM nation order BY N_REGIONKEY DESC LIMIT 10000) limit 10 

      It would be optimized by MergeLimitWithTopN rule to:

      SELECT concat('-',N_REGIONKEY) FROM nation order BY N_REGIONKEY DESC LIMIT 10

      So I propose to add these three rules to Calcite as well, to optimize the Limit case.

       
       

      Attachments

        Issue Links

          Activity

            People

              shenlang LakeShen
              shenlang LakeShen
              Votes:
              0 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: