[
https://issues.apache.org/jira/browse/CALCITE-7680?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18100980#comment-18100980
]
Julian Hyde commented on CALCITE-7680:
--------------------------------------
{{SortRemoveRedundantRule}} (CALCITE-5994 and CALCITE-6009) seems a better rule
to do this.
The prune rules just mechanically propagate empty {{{}RelNode{}}}s up the tree.
They don't generally reason about the internal logic of a {{{}RelNode{}}}.
> 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
> Priority: Major
> Labels: pull-request-available
> 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)