alamb commented on code in PR #5021:
URL: https://github.com/apache/arrow-datafusion/pull/5021#discussion_r1086502979


##########
datafusion/optimizer/src/push_down_limit.rs:
##########
@@ -37,104 +37,97 @@ impl PushDownLimit {
     }
 }
 
-fn is_no_join_condition(join: &Join) -> bool {
-    join.on.is_empty() && join.filter.is_none()
-}
-
-fn push_down_join(
-    join: &Join,
-    left_limit: Option<usize>,
-    right_limit: Option<usize>,
-) -> LogicalPlan {
-    let left = match left_limit {
-        Some(limit) => LogicalPlan::Limit(Limit {
-            skip: 0,
-            fetch: Some(limit),
-            input: Arc::new((*join.left).clone()),
-        }),
-        None => (*join.left).clone(),
-    };
-    let right = match right_limit {
-        Some(limit) => LogicalPlan::Limit(Limit {
-            skip: 0,
-            fetch: Some(limit),
-            input: Arc::new((*join.right).clone()),
-        }),
-        None => (*join.right).clone(),
-    };
-    LogicalPlan::Join(Join {
-        left: Arc::new(left),
-        right: Arc::new(right),
-        on: join.on.clone(),
-        filter: join.filter.clone(),
-        join_type: join.join_type,
-        join_constraint: join.join_constraint,
-        schema: join.schema.clone(),
-        null_equals_null: join.null_equals_null,
-    })
-}
-
 /// Push down Limit.
 impl OptimizerRule for PushDownLimit {
     fn try_optimize(
         &self,
         plan: &LogicalPlan,
         _config: &dyn OptimizerConfig,
     ) -> Result<Option<LogicalPlan>> {
+        use std::cmp::min;
+
         let limit = match plan {
             LogicalPlan::Limit(limit) => limit,
             _ => return Ok(None),
         };
 
-        if let LogicalPlan::Limit(child_limit) = &*limit.input {
+        if let LogicalPlan::Limit(child) = &*limit.input {
+            // Merge the Parent Limit and the Child Limit.
+
+            //  Case 0: Parent and Child are disjoint. (child_fetch <= skip)

Review Comment:
   these pictures are wonderfully helpful -- thank you @HaoYang670 



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

Reply via email to