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

RelBuilder.limit should apply offset and fetch to previous Sort operator, if possible

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.37.0
    • None

    Description

      The RelBuilder.limit(offset, fetch) method should apply offset and fetch to the previous Sort operator, if possible. If I call RelBuilder.sortLimit to create a Sort with an offset but no fetch, then call RelBuilder.limit(0, fetch) to set a fetch, it currently creates two LogicalSort nodes but should just modify the fetch of the existing LogicalSort.

      For example,

      b.scan("EMP")
          .sortLimit(2, -1, b.field("DEPTNO"))
          .limit(-1, 3)
          .build()
      

      should generate the plan

      LogicalSort(sort0=[$7], dir0=[ASC], offset=[2], fetch=[3])
        LogicalTableScan(table=[[scott, EMP]])
      

      but instead generates

      LogicalSort(fetch=[3])
        LogicalSort(sort0=[$7], dir0=[ASC], offset=[2])
          LogicalTableScan(table=[[scott, EMP]])
      

      Similarly any other RelBuilder methods that allow creating a Sort with or without offset and fetch.

      Attachments

        Activity

          People

            julianhyde Julian Hyde
            julianhyde Julian Hyde
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: