morrySnow commented on code in PR #17355:
URL: https://github.com/apache/doris/pull/17355#discussion_r1126263751


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/logical/PushdownLimit.java:
##########
@@ -67,65 +74,45 @@ public List<Rule> buildRules() {
                             LogicalUnion union = limit.child();
                             ImmutableList<Plan> newUnionChildren = 
union.children()
                                     .stream()
-                                    .map(child -> addLimit(limit, child))
+                                    .map(child -> limit.withChildren(child))
                                     .collect(ImmutableList.toImmutableList());
+                            if (union.children().equals(newUnionChildren)) {
+                                return null;
+                            }
                             return 
limit.withChildren(union.withChildren(newUnionChildren));
                         })
-                        .toRule(RuleType.PUSH_LIMIT_THROUGH_UNION)
+                        .toRule(RuleType.PUSH_LIMIT_THROUGH_UNION),
+                logicalLimit(logicalOneRowRelation())
+                        .then(limit -> limit.getLimit() > 0
+                                ? limit.child() : new 
LogicalEmptyRelation(limit.child().getOutput()))
+                        .toRule(RuleType.PUSH_LIMIT_THROUGH_ONE_ROW_RELATION),

Review Comment:
   this rule name is not good. it do not push limit **THROUGH** one row relation



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/logical/PushdownLimit.java:
##########
@@ -67,65 +74,45 @@ public List<Rule> buildRules() {
                             LogicalUnion union = limit.child();
                             ImmutableList<Plan> newUnionChildren = 
union.children()
                                     .stream()
-                                    .map(child -> addLimit(limit, child))
+                                    .map(child -> limit.withChildren(child))
                                     .collect(ImmutableList.toImmutableList());
+                            if (union.children().equals(newUnionChildren)) {
+                                return null;
+                            }
                             return 
limit.withChildren(union.withChildren(newUnionChildren));
                         })
-                        .toRule(RuleType.PUSH_LIMIT_THROUGH_UNION)
+                        .toRule(RuleType.PUSH_LIMIT_THROUGH_UNION),
+                logicalLimit(logicalOneRowRelation())
+                        .then(limit -> limit.getLimit() > 0
+                                ? limit.child() : new 
LogicalEmptyRelation(limit.child().getOutput()))
+                        .toRule(RuleType.PUSH_LIMIT_THROUGH_ONE_ROW_RELATION),
+                logicalLimit(logicalEmptyRelation())
+                        .then(UnaryNode::child)
+                        .toRule(RuleType.PUSH_LIMIT_THROUGH_EMPTY_RELATION),

Review Comment:
   ditto, may be eliminate limit on xxxx is better



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/logical/PushdownLimit.java:
##########
@@ -40,24 +39,32 @@
  * <p>
  * Limit can't be push down if it has a valid offset info.
  */
-public class LimitPushDown implements RewriteRuleFactory {
+public class PushdownLimit implements RewriteRuleFactory {
 
     @Override
     public List<Rule> buildRules() {
         return ImmutableList.of(
                 // limit -> join
                 logicalLimit(logicalJoin(any(), 
any())).whenNot(Limit::hasValidOffset)

Review Comment:
   maybe do not need `join(any(), any())`? `join()` is enough 



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to