924060929 commented on code in PR #14569:
URL: https://github.com/apache/doris/pull/14569#discussion_r1031691842


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/logical/MergeLimits.java:
##########
@@ -43,13 +41,39 @@
 public class MergeLimits extends OneRewriteRuleFactory {
     @Override
     public Rule build() {
-        return 
logicalLimit(logicalLimit()).whenNot(Limit::hasValidOffset).then(upperLimit -> {
-            LogicalLimit<? extends Plan> bottomLimit = upperLimit.child();
+        return logicalLimit(logicalLimit()).then(limit -> {
+            long bottomLimit = limit.child().getLimit();
+            long bottomOffset = limit.child().getOffset();
+            long upLimit = limit.getLimit();
+            long upOffset = limit.getOffset();
+            // Child range [bottomOffset, bottomOffset + bottomLimit)
+            // Parent range [bottomOffset + upOffset, bottomOffset + upOffset 
+ upLimit)
+            // Merge -> [bottomOffset + upOffset, min(bottomOffset + upOffset 
+ upLimit, bottomOffset + bottomLimit) )
+            // Merge LimitPlan -> [bottomOffset + upOffset, min(upLimit, 
bottomLimit - upOffset) )
+            long newLimit;
+            if (bottomLimit >= 0 && upLimit >= 0) {
+                newLimit = Math.min(upLimit, minus(bottomLimit, upOffset));
+            } else if (upLimit < 0 & bottomLimit < 0) {

Review Comment:
   `&` ?



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to