mihaibudiu commented on code in PR #5132:
URL: https://github.com/apache/calcite/pull/5132#discussion_r3679604478
##########
core/src/main/java/org/apache/calcite/rel/rules/PruneEmptyRules.java:
##########
@@ -542,6 +560,30 @@ public interface SortFetchZeroRuleConfig extends
PruneEmptyRule.Config {
}
}
+ /** Configuration for a rule that prunes a Sort if its {@code OFFSET} skips
at
+ * least as many rows as its input can ever produce. */
+ @Value.Immutable
+ public interface SortOffsetGreaterThanMaxRowsRuleConfig extends
PruneEmptyRule.Config {
+ SortOffsetGreaterThanMaxRowsRuleConfig DEFAULT =
+ ImmutableSortOffsetGreaterThanMaxRowsRuleConfig.of()
+ .withOperandSupplier(b -> b.operand(Sort.class).anyInputs())
+ .withDescription("PruneSortOffsetGreaterThanMaxRows");
+
+ @Override default PruneEmptyRule toRule() {
+ return new RemoveEmptySingleRule(this) {
+ @Override public boolean matches(final RelOptRuleCall call) {
+ final Sort sort = call.rel(0);
+ // Only consider a static (non-dynamic) OFFSET. If the offset skips
at
+ // least as many rows as the input can ever produce, the Sort returns
+ // no rows. RelMdMaxRowCount#getMaxRowCount(Sort) already subtracts
the
+ // offset from the input row count, so the Sort is definitely empty.
+ return sort.offset instanceof RexLiteral
+ && RelMdUtil.isRelDefinitelyEmpty(call.getMetadataQuery(), sort);
Review Comment:
If you can merge two rules without increasing complexity you should.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]