Repository navigation
Fix wrong results after external GROUP BY and max_rows_to_group_by>0 - #126249
Conversation
|
Workflow [PR], commit [b91f25c] Summary: ✅
AI ReviewSummaryPR #126249 preserves admitted keys across external Findings
Tests
Final Verdict |
472ab5d to
31c458b
Compare
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes7 object files changed (+99.36 KiB total), 0 added.
711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units91 translation units recompiled, 1004 s compile time in total, 91 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.05 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. Symbol sizes
|
31c458b to
9dd53bc
Compare
nihalzp
left a comment
There was a problem hiding this comment.
Looks good!
Regarding the quadratic memory issue, one idea could be that instead of populating the aggregation table with keys after spill, we can keep the seeded keys separately in some hash set. Then, for every incoming key, we can probe the table first and if it misses then probe the hash set: before the cap, the hash set tells whether the key is new and counts toward max_rows_to_group_by; after the cap, a key found in the hash set goes back into the table and the others are dropped. We can optionally speed this up by having a Bloom filter as well.
The benefit is that our aggregation stays fast because the local table after a spill would stay small most of the time compared to the hash set with all seeded keys. Second, we avoid the quadratic memory issue because each spill empties the aggregation table and writes only the states accumulated since the previous spill, and the seeded keys no longer count toward the spill floor.
9dd53bc to
a935ccc
Compare
You mean spilling right, yes it can be fixed that way, but I decided not to do any optimizations here and only fix the real bug, introducing separate hashtable will need extra handling, while this use case looks very narrow, not sure it worth the complexity |
With max_rows_to_group_by>0/group_by_overflow_mode=any, a stream stops admitting new keys and keeps aggregating the ones already in its hash table. But external aggregation empties that table, so every later row of an admitted key found nothing to merge into and was dropped: the key came out of the merge with only the rows that preceded the spill. The trivial `GROUP BY ... LIMIT` is not affected, since it introduced the "reseed" concept, that was used here to fix it. v2: Stop capping `GROUP BY` once external aggregation has flushed anything v3: Keep the keys of every spill so `max_rows_to_group_by` still counts them
a935ccc to
b91f25c
Compare
Cherry pick #126249 to 26.10: Fix wrong results after external GROUP BY and max_rows_to_group_by>0
…and max_rows_to_group_by>0
Backport #126249 to 26.10: Fix wrong results after external GROUP BY and max_rows_to_group_by>0
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix wrong results after external GROUP BY and max_rows_to_group_by>0 (can lead to excessive spills with
max_rows_to_group_by>0andgroup_by_overflow_mode=any, but only in case of spilling limit is small)With
max_rows_to_group_by>0/group_by_overflow_mode=any, a stream stops admitting new keys and keeps aggregating the ones already in its hash table.But external aggregation empties that table, so every later row of an admitted key found nothing to merge into and was dropped: the key came out of the merge with only the rows that preceded the spill.
The trivial
GROUP BY ... LIMITis not affected, since it introduced the "reseed" concept (in #114690), that was used here to fix it.Workflow [PR]
Sync PR [sync-upstream/pr/126249]
Version info
26.11.1.2006-master(included in26.11and later)26.10.12.12