Commit 7d9f6ea
Avoid repeated
## Which issue does this PR close?
- Closes apache#23249.
## Rationale for this change
The migrated partial hash aggregate output path still used
`EmitTo::First(batch_size)` when draining grouped aggregate state in
batches.
For terminal output this is unnecessary and can be expensive:
`EmitTo::First` is not just slicing the first N rows, it also shifts
remaining group indexes and maintains `GroupValues` lookup state. For
high-cardinality partial aggregate output, this can cause repeated work
during output draining.
The final hash aggregate path already avoids this by materializing
output once with `EmitTo::All` and then slicing the resulting
`RecordBatch`. This PR applies the same approach to partial hash
aggregate output.
## What changes are included in this PR?
- Remove the helper that selected `EmitTo::First(batch_size)` for hash
aggregate terminal output.
- Change migrated partial hash aggregate output to:
- materialize grouped keys and aggregate state once with `EmitTo::All`
- slice the materialized `RecordBatch` into `batch_size` chunks across
output polls
- Rename the shared materialized-output state/type to mode-neutral names
because it is now used by both final and partial output paths.
- Add a regression test with a custom `GroupsAccumulator` that fails if
partial terminal output calls `EmitTo::First(_)`.
- Strengthen the regression test to verify both batch slicing and
emitted key/state values.
## Are these changes tested?
Yes.
Local targeted tests:
```bash
cargo test -p datafusion-physical-plan partial_grouped_aggregate_materializes_before_slicing -- --nocapture
cargo test -p datafusion-physical-plan materialized_aggregate_output_slices_batches_until_exhausted -- --nocapture
git diff --check
```
Additional local verification run during development:
```bash
cargo test -p datafusion-physical-plan materialized_final_output_slices_batches_until_exhausted -- --nocapture
cargo test -p datafusion-physical-plan partial_grouped_aggregate_uses_raw_partial_stream -- --nocapture
```
The new regression test was also applied to the pre-fix baseline and
failed with the expected internal error when the partial output path
used `EmitTo::First`.
Local benchmark evidence was collected against the implementation commit
before the final test/naming polish commit.
ClickBench full 43-query run, 5 iterations, 24 cores skip partial
aggregation probe ratio `0.8`:
mode | total warm time | geomean warm time
-- | -- | --
baseline migrated aggregate | 128509.47 ms | 352.79 ms
patched migrated aggregate | 19652.37 ms | 180.65 ms
baseline old aggregate path | 19774.70 ms | 181.25 ms
Largest patched/current wins included:
q33: 32961.02ms -> 1642.08ms
q34: 32739.34ms -> 1635.07ms
q18: 25673.25ms -> 1767.25ms
q16: 5949.82ms -> 810.17ms
q17: 5906.51ms -> 807.10ms
TPC-DS SF10 full99, 10 rounds:
Failures: 0
Aggregate geomean current/main: 0.982817
Aggregate current speedup: 1.748%
## Are there any user-facing changes?
No. This is an internal physical execution change for hash aggregate
output draining. There are no public API or documented behavior changes.
---------
Co-authored-by: Qiwei Huang <qiwei.huang@jsessh.com>
Co-authored-by: kamille <kamille@apache.org>EmitTo::First in partial hash aggregate output (apache#23250)1 parent 4dadbbd commit 7d9f6ea
4 files changed
Lines changed: 273 additions & 56 deletions
File tree
- datafusion/physical-plan/src/aggregates
- aggregate_hash_table
Lines changed: 11 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
185 | | - | |
| 185 | + | |
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
| |||
214 | 214 | | |
215 | 215 | | |
216 | 216 | | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | 217 | | |
227 | 218 | | |
228 | 219 | | |
| |||
304 | 295 | | |
305 | 296 | | |
306 | 297 | | |
307 | | - | |
| 298 | + | |
308 | 299 | | |
309 | 300 | | |
310 | 301 | | |
311 | | - | |
| 302 | + | |
312 | 303 | | |
313 | 304 | | |
314 | 305 | | |
315 | | - | |
| 306 | + | |
316 | 307 | | |
317 | | - | |
318 | | - | |
319 | | - | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
320 | 312 | | |
321 | 313 | | |
322 | 314 | | |
323 | 315 | | |
324 | | - | |
| 316 | + | |
325 | 317 | | |
326 | 318 | | |
327 | 319 | | |
| |||
496 | 488 | | |
497 | 489 | | |
498 | 490 | | |
499 | | - | |
| 491 | + | |
500 | 492 | | |
501 | 493 | | |
502 | 494 | | |
| |||
506 | 498 | | |
507 | 499 | | |
508 | 500 | | |
509 | | - | |
| 501 | + | |
510 | 502 | | |
511 | 503 | | |
512 | 504 | | |
| |||
Lines changed: 8 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
61 | | - | |
| 60 | + | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | | - | |
| 85 | + | |
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
| 99 | + | |
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
| 111 | + | |
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
| |||
Lines changed: 44 additions & 26 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | | - | |
34 | | - | |
| 34 | + | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
65 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
66 | 69 | | |
67 | 70 | | |
68 | | - | |
69 | 71 | | |
70 | 72 | | |
71 | 73 | | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
89 | 79 | | |
90 | 80 | | |
91 | 81 | | |
92 | 82 | | |
93 | 83 | | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | 84 | | |
100 | 85 | | |
101 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
102 | 120 | | |
103 | 121 | | |
104 | 122 | | |
| |||
0 commit comments