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

Yu Xu commented on CALCITE-7680:
--------------------------------

Thanks for the suggestions [~julianhyde] . I’d like to share my thoughts on the 
currently implemented solution (please correct me if I’m mistaken): That's a 
fair point for Sort-specific reasoning. However, the current implementation no 
longer contains Sort-specific logic; it simply uses 
{{{}RelMdUtil.isRelDefinitelyEmpty{}}}, which delegates the per-operator 
reasoning to {{{}RelMdMaxRowCount{}}}. Keeping it in {{PruneEmptyRules}} avoids 
duplicating the "replace with empty Values" logic and also covers other 
definitely-empty cases like {{{}Filter(false){}}}. If we moved this to 
{{{}SortRemoveRedundantRule{}}}, we would still need a separate mechanism for 
non-Sort operators.

> 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)

Reply via email to