yashdotrv commented on PR #27129: URL: https://github.com/apache/datafusion/pull/27129#issuecomment-7177035628
> [@yashdotrv](https://github.com/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](https://github.com/apache/datafusion/issues/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 returns `ResourcesExhausted`. > > 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. @jayzhan211 Thanks for the feedback! I've pushed an update addressing all points: 1. **Adjusted spill-and-retry memory pool limits**: - In `hash_stream.rs` (`final_hash_spills_to_admit_large_state_batch`), reduced the pool to `2400 * 1024` so the batch does not fit alongside the table and triggers the spill-and-retry path. - In `clustered_final_stream.rs` (`clustered_final_spills_to_admit_large_state_batch`), reduced the pool to `2300 * 1024` for the same reason. 2. **Added non-retaining aggregate test (`max`)**: - Added `final_aggregate_reserves_state_batch_it_does_not_retain` using `max_udaf()`, confirming that only the up-front reservation refuses the 1 MB state batch in a 512 KB pool. 3. **Added shared deduplicated views test**: - Added `final_aggregate_does_not_charge_shared_view_bytes`, testing 8,192 views of a 2 KB value with deduplicated strings (130 KB buffer, 16 MB counted row-by-row) to confirm the fast check prevents over-charging. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
