Dandandan commented on code in PR #20463:
URL: https://github.com/apache/datafusion/pull/20463#discussion_r2836377916


##########
datafusion/physical-plan/src/joins/sort_merge_join/stream.rs:
##########
@@ -1577,6 +1983,30 @@ fn produce_buffered_null_batch(
     )?))
 }
 
+/// Checks if a `UInt64Array` contains a contiguous ascending range (e.g. 
[3,4,5,6]).
+/// Returns `Some(start..start+len)` if so, `None` otherwise.
+/// This allows replacing an O(n) `take` with an O(1) `slice`.
+#[inline]
+fn is_contiguous_range(indices: &UInt64Array) -> Option<Range<usize>> {
+    if indices.is_empty() || indices.null_count() > 0 {
+        return None;
+    }
+    let start = indices.value(0);
+    let len = indices.len() as u64;
+    // Quick rejection: if last element doesn't match expected, not contiguous
+    if indices.value(indices.len() - 1) != start + len - 1 {
+        return None;
+    }
+    // Verify every element is sequential (handles duplicates and gaps)
+    let values = indices.values();

Review Comment:
   You could move the `let values = indices.values()` to the top, so you can 
use `values[i]` indexing everywhere.



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