fix: release interning state before terminal output to fix hash aggregate regression (#23178)#23180
Closed
bhonepyisone wants to merge 1 commit into
Closed
Conversation
…gate regression Closes apache#23178 PR apache#23055 introduced EmitTo::First(batch_size) for incremental hash aggregate output. During the terminal output phase (Outputting state), no more intern() calls happen, but emit(EmitTo::First(n)) still maintained the hash lookup state on every output batch: - GroupValuesColumn: map.retain() with complex index-list manipulation - GroupValuesPrimitive: map.retain() shifting all remaining indexes - GroupValuesRows: rebuilds rows + map.retain() This caused O(groups * output_batches) unnecessary work, resulting in a ~3.3x performance regression (2.43s -> 8.04s on TPC-DS Q23). Fix: add release_interning_state() to the GroupValues trait, called once during the Building -> Outputting state transition. It clears the hash map and interning buffers, making retain a no-op during terminal output. The group values themselves are stored separately and are not cleared, so output data is preserved. Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
|
Fixed in #23182 |
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.
What
Fixes the hash aggregate output performance regression introduced by #23055.
Problem
PR #23055 introduced
EmitTo::First(batch_size)for incremental hash aggregate output. During the terminal output phase (Outputtingstate), no moreintern()calls happen, butemit(EmitTo::First(n))still maintained the hash lookup state on every output batch:GroupValuesColumn(multi-col)map.retain()with complex index-list manipulationGroupValuesPrimitive(single-col)map.retain()shifting all remaining indexesGroupValuesRows(fallback)map.retain()This caused O(groups × output_batches) unnecessary work.
Performance Impact
On TPC-DS SF10 query 23 with 24 target partitions:
EmitToto output #23055: ~2.43s meanEmitToto output #23055 (regressed): ~8.04s meanThe problematic node spent ~32s in
emitting_timevs ~3s in actual aggregation time.Fix
Added
release_interning_state()to theGroupValuestrait, called once during theBuilding → Outputtingstate transition instart_outputting(). It clears the hash map and interning buffers, makingretaina no-op during terminal output.The group values themselves are stored separately (in
values/group_values/ column builders) and are not cleared, so output data is preserved.Files Changed
group_values/mod.rs— Addedrelease_interning_state()to theGroupValuestraitaggregate_hash_table/common.rs— Call it instart_outputting()multi_group_by/mod.rs— Clear map, hashes, group-index lists (the main hot path)row.rs— Clear map, hashes, row bufferssingle_group_by/primitive.rs— Clear mapsingle_group_by/boolean.rs— No-op (no hash map)single_group_by/bytes.rs— No-op (map rebuilt on emit)single_group_by/bytes_view.rs— No-op (map rebuilt on emit)Closes #23178