Repository navigation
fix(physical-plan): compact List<Dictionary> spill chunks when values are not shared across groups - #27938
Open
warrenzhu25 wants to merge 1 commit into
Open
fix(physical-plan): compact List<Dictionary> spill chunks when values are not shared across groups#27938warrenzhu25 wants to merge 1 commit into
warrenzhu25 wants to merge 1 commit into
Conversation
… are not shared across groups
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
When spilling aggregate states that contain
List<Dictionary>(e.g.,ARRAY_AGGover dictionary-encoded columns), each spill chunk is currently sliced without compacting the nested dictionary if the average total key count per dictionary value is>= 2.However, values in
ARRAY_AGGoften repeat many times within a single group while being disjoint across groups. Treating such a nested dictionary as shared causes every spilled chunk to serialize the entire uncompacted dictionary values array repeatedly, inflating spill size by orders of magnitude and triggering excessive disk usage / OOM.What changes are included in this PR?
datafusion/physical-plan/src/spill/spilled_row_sizes.rs:List,LargeList, andFixedSizeListcolumns whose child array is aDictionary.row_value_refs >= 2 * num_values, indicating values are genuinely shared across groups).row_value_refs < 2 * num_values), mark the column for compaction viaColumnSize::CompactedListDictionary(Vec<usize>)and account for each row's offset/keys plus each distinct dictionary value referenced by that row once.FixedSizeListArray(base = list.offset() * size) and null list rows / null dictionary keys.datafusion/sqllogictest/test_files/aggregate_memory_spill.slt:ARRAY_AGGover dictionary-encoded strings (1 and 2 partitions, 24M memory limit) verifying that spill size stays in MB rather than blowing up.What is the testing strategy for this PR?
datafusion/physical-plan/src/spill/spilled_row_sizes.rs(cargo test -p datafusion-physical-plan spilled_row_sizes, 14/14 passing):nested_dictionary_repeated_within_group_is_compactednested_dictionary_shared_across_groups_stays_sharedsliced_and_nullable_nested_dictionariesdatafusion/sqllogictest/test_files/aggregate_memory_spill.slt(cargo test --test sqllogictests -- aggregate_memory_spill).cargo fmt --allandcargo clippy -p datafusion-physical-plan --all-targets -- -D warnings.Are there any user-facing changes?
No public API changes. Aggregate spilling with
List<Dictionary>columns now compacts non-shared nested dictionaries per spill chunk instead of repeatedly serializing the full dictionary.Note: AI assistance was used to help investigate, implement, and test this change; all changes were reviewed and verified by the author.