On Thu, 26 Feb 2026 at 02:00, Marcos Pegoraro <[email protected]> wrote:
> Perhaps this way we will have a better understanding of this case.
I'm not sure how you thought partial mode was related to FILTER. Did
you read something in the documentation that led you to believe
they're somehow related? I imagine you just wrongly assumed that and
that's why you're confused. FILTER is implemented by filtering rows
according to the FILTER's WHERE clause before the aggregate's
transition function is called. That does not require any functionality
provided by the partial aggregate code.
As for the proposed patch, I'm strongly against it. If people are
confused about what partial aggregation is, then let's modify the
documentation to explain what it means.
Currently, [1] says:
"Aggregate functions that support Partial Mode are eligible to
participate in various optimizations, such as parallel aggregation.".
We could replace that with something like:
"Partial Mode allows input values which belong to the same logical
group to be aggregated separately and later combined to form a single
aggregate state per group. These aggregate states must then be
finalized, which will produce a result equivalent to if all input
values had been aggregated together. Parallel aggregation uses this
so that each parallel worker can aggregate a subset of input values
and form an aggregate state per group. We say these aggregate states
are "partial" as other parallel workers may have aggregated input
values which logically belong to the same group. In the leader
process, the partial aggregate states generated by the parallel
workers are combined to form a single aggregate state per logical
group. The leader finalizes these aggregate states to produce the
final result."
Partial aggregates are also used for combining groups partially
aggregated at the partition level in partitionwise aggregates. Just
look at:
create table hp (a int, b int) partition by hash (a,b);
create table hp0 partition of hp for values with (modulus 2, remainder 0);
create table hp1 partition of hp for values with (modulus 2, remainder 1);
set enable_partitionwise_aggregate=1;
explain (costs off) select a,count(*) from hp group by a;
QUERY PLAN
----------------------------------------
Finalize HashAggregate
Group Key: hp.a
-> Append
-> Partial HashAggregate
Group Key: hp.a
-> Seq Scan on hp0 hp
-> Partial HashAggregate
Group Key: hp_1.a
-> Seq Scan on hp1 hp_1
David
[1] https://www.postgresql.org/docs/current/functions-aggregate.html