Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion datafusion/physical-plan/src/coalesce/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ fn gc_string_view_batch(batch: &RecordBatch) -> RecordBatch {
let Some(s) = c.as_string_view_opt() else {
return Arc::clone(c);
};

// Fast path: if the data buffers are empty, we can return the original array
if s.data_buffers().is_empty() {
return Arc::clone(c);
}

let ideal_buffer_size: usize = s
.views()
.iter()
Expand All @@ -240,7 +246,11 @@ fn gc_string_view_batch(batch: &RecordBatch) -> RecordBatch {
}
})
.sum();
let actual_buffer_size = s.get_buffer_memory_size();

// We don't use get_buffer_memory_size here, because gc is for the contents of the
// data buffers, not views and nulls.
let actual_buffer_size =
s.data_buffers().iter().map(|b| b.capacity()).sum::<usize>();

// Re-creating the array copies data and can be time consuming.
// We only do it if the array is sparse
Expand Down