xuzifu666 commented on code in PR #5132:
URL: https://github.com/apache/calcite/pull/5132#discussion_r3695015938
##########
core/src/main/java/org/apache/calcite/rel/rules/PruneEmptyRules.java:
##########
@@ -525,20 +541,20 @@ public interface IntersectEmptyPruneRuleConfig extends
PruneEmptyRule.Config {
}
}
- /** Configuration for a rule that prunes a Sort if it has limit 0. */
+ /** Configuration for a rule that prunes a Sort if it is definitely empty,
+ * for example because its input is empty, it has {@code LIMIT 0}, or its
+ * {@code OFFSET} skips more rows than the input can produce. */
@Value.Immutable
- public interface SortFetchZeroRuleConfig extends PruneEmptyRule.Config {
- SortFetchZeroRuleConfig DEFAULT = ImmutableSortFetchZeroRuleConfig.of()
+ public interface SortEmptyRuleConfig extends PruneEmptyRule.Config {
+ SortEmptyRuleConfig DEFAULT = ImmutableSortEmptyRuleConfig.of()
.withOperandSupplier(b -> b.operand(Sort.class).anyInputs())
- .withDescription("PruneSortLimit0");
+ .withDescription("PruneSortIfEmpty");
@Override default PruneEmptyRule toRule() {
return new RemoveEmptySingleRule(this) {
@Override public boolean matches(final RelOptRuleCall call) {
- Sort sort = call.rel(0);
- return sort.fetch != null
- && !(sort.fetch instanceof RexDynamicParam)
- &&
RexLiteral.bigDecimalValue(sort.fetch).equals(BigDecimal.ZERO);
+ final Sort sort = call.rel(0);
Review Comment:
OK, I generalized ZeroMaxRowsRuleConfig (EMPTY_TABLE_INSTANCE) to match any
RelNode that is definitely empty, not just TableScan. It excludes Values and
TableModify (the latter may have side effects). This removes the need for a
separate Sort-specific rule, so SORT_EMPTY_INSTANCE was deleted and
SORT_FETCH_ZERO_INSTANCE is now a deprecated alias. The rule still relies on
RelMdUtil.isRelDefinitelyEmpty, so the logic remains simple and covers LIMIT 0,
large OFFSET, and any other case where Sort's max row count is zero.
--
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]