Add support for adaptive partial aggregation#20979
Conversation
|
There was a problem hiding this comment.
are these configs same as the ones used in Trino ?
There was a problem hiding this comment.
Should we add a comment on what a null result means ?
There was a problem hiding this comment.
nit: Will hash agg ever produce non unique rows ? ie, Is the word unique redundant ?
There was a problem hiding this comment.
Yes, it will always be unique, but I think its clearer to call it unique to understand the logic, instead of something more generic like outputRowsProduced
There was a problem hiding this comment.
nit: Add a comment on what an empty uniquerowsproduced means and how it differs from 0 unique rows.
There was a problem hiding this comment.
Do we need any special handling in this clause wrt to spillEnabled ?
There was a problem hiding this comment.
+1. looking at the code with spillEnabled we are bypassing it and going with Skip . Would that cause local OOMs?
There was a problem hiding this comment.
Whether spill is enabled or not, if partial aggregation is not effective, we should use SkipAggregationBuilder instead. It would not cause local OOM since SkipAggregationBuilder doesn't use any additional memory other than the already allocated partial agg output buffer.
There was a problem hiding this comment.
is this comment superfluous ?
There was a problem hiding this comment.
Removed. But will note that there are tons of places where we have no op as single line comment
There was a problem hiding this comment.
fillConsecutive ? or Range to borrow the python name ?
There was a problem hiding this comment.
renamed to fillConsecutive
There was a problem hiding this comment.
Q: What is the policy b/w the feature config name and the session prop name agreeing on the prefix experimental ?
There was a problem hiding this comment.
There is no policy - session prop name is totally different from feature config name and session props do not have prefixes unto themselves. When they do have prefix, it's to refer to the catalog to which the session prop should be applied.
There was a problem hiding this comment.
Why should the partial agg disabling look at the byte size instead of just the input and output row cardinalities ?
There was a problem hiding this comment.
+1. It would be nice to clarify this in a comment
There was a problem hiding this comment.
Also I would refactor this check totalBytesProcessed >= maxPartialMemory.toBytes() * ENABLE_AGGREGATION_BUFFER_SIZE_TO_INPUT_BYTES_RATIO) to a shouldEnablePartialAggregation similar to the disable method below.
There was a problem hiding this comment.
I've added a comment clarifying why we look at # bytes as the floor instead of # of rows.
There was a problem hiding this comment.
Can you think of more tests for this ?
For example, anything to verify that the "vacous group-by" results output by the partial agg into the output buffer are consumable by the final agg for different data types ?
There was a problem hiding this comment.
We do test several data types in the unit tests. For comprehensiveness, I think this is better suited for verifier testing, which will test wide range of data types
|
Starting to take a look today. |
Should this be documented, possibly in Aggregate Functions? |
ajaygeorge
left a comment
There was a problem hiding this comment.
Looks mostly good.
Adding some comments
There was a problem hiding this comment.
nit : maxPartialAggregationMemory
There was a problem hiding this comment.
renamed to maxPartialAggregationMemorySize
There was a problem hiding this comment.
nit considering to disable -> considering disabling
There was a problem hiding this comment.
+1. It would be nice to clarify this in a comment
There was a problem hiding this comment.
same as above. why bytes is important to look at?
There was a problem hiding this comment.
Comment should address this here too, it is the same reason.
There was a problem hiding this comment.
+1. looking at the code with spillEnabled we are bypassing it and going with Skip . Would that cause local OOMs?
There was a problem hiding this comment.
Also I would refactor this check totalBytesProcessed >= maxPartialMemory.toBytes() * ENABLE_AGGREGATION_BUFFER_SIZE_TO_INPUT_BYTES_RATIO) to a shouldEnablePartialAggregation similar to the disable method below.
There was a problem hiding this comment.
add requireNonNull(accumulatorFactories, "accumulatorFactories is null"); before this line
There was a problem hiding this comment.
nit. prefer functional style. (inputHashChannel.map(size -> 1).orElse(0))
There was a problem hiding this comment.
feels clearer to me to leave as is
There was a problem hiding this comment.
can you help me understand why were are using NOOP here.? Is it because we are not doing any aggregation and just returning the flat rows.?
There was a problem hiding this comment.
Yes exactly, there is no memory used by this builder
ajaygeorge
left a comment
There was a problem hiding this comment.
LGTM % a few comments.
When partial aggregation is not effectively reducing cardinality, instead send raw input rows directly to the final aggregation step. Port of: github.com/trinodb/trino/pull/11011 github.com/trinodb/trino/pull/17143 Co-authored-by: Lukasz Stec <lukasz.s.stec@gmail.com> Co-authored-by: Karol Sobczak <sopel39@users.noreply.github.com>
e1ede28 to
c2312bb
Compare
I've added session property info to enable this in Release Notes section |
When partial aggregation is not effectively reducing cardinality, instead send raw input rows directly to the final aggregation step.
Port of github.com/trinodb/trino/pull/11011 and github.com/trinodb/trino/pull/17143
Description
This change adds support for adaptive partial aggregation.
Motivation and Context
Partial Aggregation can be inefficient when the number of unique values is high and the buffer is too small to effectively reduce cardinality. In these cases, the wasted CPU from hashing exceeds the benefit of transmitting less rows over the network. Partial aggregation should be disabled in this case.
Impact
Benchmarks results on TPCH:
Test Plan
Contributor checklist
Release Notes