Yu Xu created CALCITE-7680:
------------------------------

             Summary: PruneEmptyRules should prune Sort when OFFSET is greater 
than or equal to max input rows
                 Key: CALCITE-7680
                 URL: https://issues.apache.org/jira/browse/CALCITE-7680
             Project: Calcite
          Issue Type: Improvement
          Components: core
    Affects Versions: 1.42.0
            Reporter: Yu Xu
            Assignee: Yu Xu
             Fix For: 1.43.0


PruneEmptyRules currently misses the case where the Sort has an OFFSET that is 
large enough to skip every row the input can produce.
eg:
{code:java}
@Test void testEmptySortOffsetGreaterThanMaxRows() {
  // The input VALUES has at most 2 rows, so 'OFFSET 5' skips them all.
  final String sql = "select * from (values (1, 2), (3, 4)) as t (a, b)\n"
      + "order by a\n"
      + "offset 5 rows";
  sql(sql).check();
} {code}
plan is:
{code:java}
LogicalSort(sort0=[$0], dir0=[ASC], offset=[5])
  LogicalProject(A=[$0], B=[$1])
    LogicalValues(tuples=[[{ 1, 2 }, { 3, 4 }]]) {code}
 We could actually improve PruneEmptyRules to make the plan to:
{code:java}
LogicalValues(tuples=[[]]){code}



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

Reply via email to