comphead commented on code in PR #27351: URL: https://github.com/apache/datafusion/pull/27351#discussion_r4579565613
########## datafusion/physical-plan/src/aggregates/hash_stream.rs: ########## Review Comment: It skips only when the rows emitted so far plus the groups still in the table exceed 80% of the input rows, so only when the Partial has reduced its input by less than 20%. Duplicates that arrive while their key is still in the table are merged and keep the ratio down. Duplicates that arrive after their key was emitted are not merged on `main` either, so counting that key twice reflects what the Partial actually achieves. With 20M rows and 8 partitions: - 50K keys, fair 16M pool: `main` reduces only 3%. This PR skips, Partial CPU drops from 332 to 44 ms, and the query from 0.090 to 0.048 s. - 20K keys at fair 8M and 2K keys at fair 2M: `main` reduces 41% and 76%. This PR keeps aggregating, with the same counters. A high-cardinality prefix is where `main` does better. With 400K distinct keys followed by 1.6M rows over 1000 keys (2 partitions), this PR skips after the probe threshold and sends 2.00M rows downstream instead of 403K, the same decision `main` makes without a memory limit. Query time was unchanged here. Re-probing after a skip would help both cases, so I'd leave it for a separate issue. I added a case to the test where keys repeat within each batch. Both streams emit early and keep aggregating. -- 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]
