Copilot commented on code in PR #12059:
URL: https://github.com/apache/arrow-rs/pull/12059#discussion_r4661921467


##########
arrow-select/src/interleave.rs:
##########
@@ -264,33 +264,72 @@ fn interleave_dictionaries<K: ArrowDictionaryKeyType>(
     let dictionaries: Vec<_> = arrays.iter().map(|x| 
x.as_dictionary::<K>()).collect();
     let (should_merge, has_overflow) =
         should_merge_dictionary_values::<K>(&dictionaries, indices.len());
-    if !should_merge {
-        return if has_overflow {
-            interleave_fallback(arrays, indices)
+    let strategy = if should_merge {
+        DictionaryInterleaveStrategy::MergeDictionaries
+    } else {
+        let first_values = dictionaries[0].values();
+        if dictionaries
+            .iter()
+            .skip(1)
+            .all(|dictionary| Arc::ptr_eq(first_values, dictionary.values()))
+        {

Review Comment:
   This check considers every input dictionary, including sources that 
contribute no selected valid key, so any retained all-null or unreferenced 
dictionary with a different values `Arc` disables `SharedDictionary` and sends 
the selected rows through the merge/fallback path. That misses the optimization 
for the exact cases described in the issue (for example, two referenced slices 
sharing `V` plus an unused/null-only batch) and makes this fast path sensitive 
to unrelated retained inputs. Build the identity check from the sources and 
valid key positions actually present in `indices`, then reuse the shared 
mapping when those are the only referenced mappings.



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