Repository navigation
Conversation
1c93e8c to
0539bfb
Compare
jayzhan211
left a comment
There was a problem hiding this comment.
@yashdotrv thanks for picking this up. Please correct the description, since most of the state is still unreserved and buffer growth is not the main cause. With the ignored #26705 cases in #26728 turned on, unreserved memory grows 121-124 MB for median (122-143 MB on main) and 500-505 MB for array_agg (531-589 MB), against a 16 MB bound. At the peak 19.1 MB of 152 MB is reserved for median, about one of the four partial states; the others appear to be queued in CoalescePartitionsExec.
A follow-up is fine because that queue is outside these streams, so #26705 should stay open. The description should also say that array_agg over 1000 groups at 30-60 MB goes from passing to ResourcesExhausted, while peak RSS at 100 MB stays near 610 MB.
|
@jayzhan211 ty for your review, I'll work on the suggestions and get back. |
0539bfb to
a7850b7
Compare
|
@jayzhan211 Thanks again for the review and detailed pointers! I have updated the branch with the requested changes:
|
jayzhan211
left a comment
There was a problem hiding this comment.
@yashdotrv thanks for the quick turnaround; every point from the first round is addressed. One new problem remains: the charge counts the whole buffer behind a zero-copy slice, so a grouped query without a hash repartition goes from passing to ResourcesExhausted. Details and a fix are inline on incoming_state_batch_reservation_bytes. The fix changes how the new tests should build their large state batch, so I've also asked for one more test there.
b1f2c29 to
b8d1065
Compare
@jayzhan211 Thanks for catching the zero-copy buffer slicing issue and for the detailed suggestions! I have updated the PR and rebased against the latest
|
jayzhan211
left a comment
There was a problem hiding this comment.
@yashdotrv thanks for adopting every point from the last round. The 500k-group query without a hash repartition now passes at 40–80 MB again, and the 30M-row median at 300 MB is still refused. Two tests no longer reach the paths they are named for; the fixes are inline.
Optional: the Rationale opens with the mechanism, so a reviewer can't see the symptom from its first paragraph, and "What changes" doesn't mention the 1 KiB/row rule, which is the part that decides which batches are charged. Something like:
SELECT median(v) FROM generate_series(1, 30000000)with 4 target partitions and a 300 MB memory limit runs past the limit (656–939 MB peak RSS in #26705): the partial aggregate releases its reservation when it emits its state, and the final aggregate reserves memory only after merging it. This PR reserves each incoming state batch before merging it, so that query now returnsResourcesExhausted.A batch is charged only when its rows reference more than 1 KiB each on average (and 64 KiB in total), so ordinary
batch_size-bounded state batches are not charged. Slices of a larger partial output are charged only for the bytes their rows reference.
- Charge partial-state batches only when bytes per row exceed 1 KiB and total bytes exceed 64 KiB - Restore early break on soft group limit before table memory resize in FinalHashAggregateStream - Extract shared spill_table helper in FinalHashAggregateStream - Guard incoming batch memory reservation calculation to Partial input mode in AggregateStream - Replace synthetic tests with large-buffer retaining batches to properly test state batch admission - Add test for ClusteredFinalAggregateStream spill-and-retry on partial clustering - Add test for FinalHashAggregateStream spill-and-retry on large state batch - Restore aggregate_memory_call_sequence.rs to match main
… aggregate - Measure only bytes referenced by slice rows using SpilledRowSizes when buffer exceeds in_flight_bytes - Add unit tests for bounded state batches, shared buffer slices, and Single mode raw input - Update test cases to use realistic state payloads
b8d1065 to
5f65736
Compare
@jayzhan211 Thanks for the feedback! I've pushed an update addressing all points:
|
…uplicated states - Lower memory pool sizes in hash_stream and clustered_final_stream tests to exercise the spill-and-retry path - Add test verifying that up-front reservation refuses state batches even for non-retaining aggregates (max) - Add test verifying that shared Utf8View values with deduplicated strings are not over-charged
b7fb5d3 to
142a800
Compare
Which issue does this PR close?
Part of #26705.
Rationale for this change
SELECT median(v) FROM generate_series(1, 30000000)with 4 target partitions and a 300 MB memory limit runs past the limit (656–939 MB peak RSS in #26705): the partial aggregate releases its reservation when it emits its state, and the final aggregate reserves memory only after merging it. This PR reserves each incoming state batch before merging it, so that query now returnsResourcesExhausted.What changes are included in this PR?
AggregateStream,FinalHashAggregateStream, andClusteredFinalAggregateStream.batch_size-bounded state batches are not charged.SpilledRowSizes.Are these changes tested?
Yes, with new unit tests in
aggregate_stream,hash_stream, andclustered_final_stream.