zhuqi-lucas commented on code in PR #14644: URL: https://github.com/apache/datafusion/pull/14644#discussion_r1957056599
########## datafusion/physical-plan/src/sorts/sort.rs: ########## @@ -641,7 +702,15 @@ pub fn sort_batch( lexsort_to_indices(&sort_columns, fetch)? }; - let columns = take_arrays(batch.columns(), &indices, None)?; + let mut columns = take_arrays(batch.columns(), &indices, None)?; + + // The columns may be larger than the unsorted columns in `batch` especially for variable length + // data types due to exponential growth when building the sort columns. We shrink the columns + // to prevent memory reservation failures, as well as excessive memory allocation when running + // merges in `SortPreservingMergeStream`. + columns.iter_mut().for_each(|c| { Review Comment: It seems you already benchmarked it, we may can the benchmark code also. -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org