comphead commented on code in PR #10501:
URL: https://github.com/apache/datafusion/pull/10501#discussion_r1601777537
##########
datafusion/optimizer/src/push_down_limit.rs:
##########
@@ -217,6 +183,78 @@ impl OptimizerRule for PushDownLimit {
}
}
+/// Combines two limits into a single
+///
+/// Returns the combined limit `(skip, fetch)`
+///
+/// # Case 0: Parent and Child are disjoint. (`child_fetch <= skip`)
+///
+/// ```text
+/// Before merging:
+/// |........skip........|---fetch-->| Parent
Limit
+/// |...child_skip...|---child_fetch-->| Child
Limit
+/// ```
+///
+/// After merging:
+/// ```text
+/// |.........(child_skip + skip).........|
+/// ```
+///
+/// Before merging:
+/// ```text
+/// |...skip...|------------fetch------------>| Parent
Limit
+/// |...child_skip...|-------------child_fetch------------>| Child
Limit
+/// ```
+///
+/// After merging:
+/// ```text
+/// |....(child_skip + skip)....|---(child_fetch - skip)-->|
+/// ```
+///
+/// # Case 1: Parent is beyond the range of Child. (`skip < child_fetch <=
skip + fetch`)
+///
+/// Before merging:
+/// ```text
+/// |...skip...|------------fetch------------>| Parent
Limit
+/// |...child_skip...|-------------child_fetch------------>| Child
Limit
+/// ```
+///
+/// After merging:
+/// ```text
+/// |....(child_skip + skip)....|---(child_fetch - skip)-->|
+/// ```
+///
+/// # Case 2: Parent is in the range of Child. (`skip + fetch < child_fetch`)
+/// Before merging:
+/// ```text
+/// |...skip...|---fetch-->| Parent
Limit
+/// |...child_skip...|-------------child_fetch------------>| Child
Limit
+/// ```
+///
+/// After merging:
+/// ```text
+/// |....(child_skip + skip)....|---fetch-->|
+/// ```
+fn combine_limit(
+ parent_skip: usize,
+ parent_fetch: Option<usize>,
+ child_skip: usize,
+ child_fetch: Option<usize>,
+) -> (usize, Option<usize>) {
+ let combined_skip = child_skip + parent_skip;
Review Comment:
```suggestion
let combined_skip = child_skip.saturating_add(parent_skip);
```
--
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]