Commit d58e0c6
Fix final hash aggregate output regression by materializing once (apache#23182)
## Which issue does this PR close?
- part of apache#22710
- short-term solution for apache#23178.
- closes apache#23178
## Rationale for this change
PR apache#23055 changed final hash aggregate output to emit groups
incrementally with
`EmitTo::First(batch_size)`. For terminal final aggregate output, this
can cause
the group value state to be repeatedly compacted while output batches
are being
produced. On TPC-DS q23 this showed up as a significant regression.
This PR implements the short-term approach discussed in apache#23178:
materialize the
final aggregate output once, then return slices of that materialized
`RecordBatch` according to `batch_size`.
This avoids changing the `GroupValues` API while preserving bounded
downstream
batch sizes.
## What changes are included in this PR?
- Adds an `OutputtingMaterialized` hash aggregate state.
- Adds `MaterializedOutput`, a small wrapper around a `RecordBatch` plus
output
offset.
- Changes final hash aggregate output to:
- emit all final groups once,
- evaluate all final aggregate values once,
- slice the materialized batch for subsequent output polling.
- Leaves partial aggregate output behavior unchanged.
- Adds focused tests for materialized output slicing and final hash
aggregate
output state transitions.
## Performance
TPC-DS SF10 full 99 queries, 10 rounds:
- Total runtime ratio: `0.857051`
- Geomean ratio: `0.976652` (~2.4% faster)
- q23 ratio: `0.313770` (~218.7% faster), faster in `10/10` rounds
Regressions over 5% were observed in 10 queries. Most have small
absolute
deltas, but the largest slowdowns were:
- q67: `1.055907`, +170.996 ms
- q39: `1.060436`, +98.544 ms
- q9: `1.050135`, +37.858 ms
- q70: `1.061124`, +11.848 ms
- q35: `1.052392`, +9.386 ms
- q33: `1.063655`, +6.995 ms
- q98: `1.071688`, +6.515 ms
- q91: `1.109819`, +5.362 ms
- q15: `1.058356`, +5.072 ms
- q27: `1.057686`, +0.815 ms
Overall, this recovers the q23 regression strongly and improves
full-query
geomean, but q39 and q67 are worth calling out as residual per-query
slowdowns.
## Testing
- `cargo fmt --all -- --check`
- `cargo test -p datafusion-physical-plan materializ`
- `cargo test -p datafusion-physical-plan aggregates::`
- TPC-DS SF10 q23, 3 rounds
- TPC-DS SF10 full 99 queries, 10 rounds
---------
Co-authored-by: Qiwei Huang <qiwei.huang@jsessh.com>
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>1 parent d111dd0 commit d58e0c6
4 files changed
Lines changed: 138 additions & 20 deletions
File tree
- datafusion/physical-plan
- src/aggregates/aggregate_hash_table
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| 126 | + | |
126 | 127 | | |
127 | 128 | | |
128 | 129 | | |
| |||
Lines changed: 86 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
185 | 188 | | |
186 | 189 | | |
187 | 190 | | |
| |||
297 | 300 | | |
298 | 301 | | |
299 | 302 | | |
| 303 | + | |
300 | 304 | | |
| 305 | + | |
301 | 306 | | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
302 | 312 | | |
303 | 313 | | |
304 | 314 | | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
305 | 350 | | |
306 | 351 | | |
307 | 352 | | |
| |||
440 | 485 | | |
441 | 486 | | |
442 | 487 | | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
Lines changed: 46 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | | - | |
| 28 | + | |
| 29 | + | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
| |||
55 | 57 | | |
56 | 58 | | |
57 | 59 | | |
58 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
59 | 63 | | |
60 | 64 | | |
61 | | - | |
62 | 65 | | |
63 | 66 | | |
64 | 67 | | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
82 | 73 | | |
83 | 74 | | |
84 | 75 | | |
| |||
87 | 78 | | |
88 | 79 | | |
89 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 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 | + | |
90 | 116 | | |
91 | 117 | | |
92 | 118 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
94 | 99 | | |
95 | 100 | | |
96 | 101 | | |
| |||
0 commit comments