Re: Parallel aggregates in PG 16.1
От | Matthias van de Meent |
---|---|
Тема | Re: Parallel aggregates in PG 16.1 |
Дата | |
Msg-id | CAEze2WhpnVjHFv6z9kEhdnhCUCYx8go_PbMjMDdiBkZJuiiv=g@mail.gmail.com обсуждение исходный текст |
Ответ на | Parallel aggregates in PG 16.1 (ZIMANYI Esteban <esteban.zimanyi@ulb.be>) |
Список | pgsql-hackers |
On Fri, 10 Nov 2023 at 11:47, ZIMANYI Esteban <esteban.zimanyi@ulb.be> wrote: > > In MobilityDB > https://github.com/MobilityDB/MobilityDB > we have defined a tstzspan type which is a fixed-size equivalent of the tstzrange type in PostgreSQL. > > We have a span_union aggregate function which is the equivalent of the range_agg function in PostgreSQL defined as follows > > CREATE FUNCTION tstzspan_union_finalfn(internal) > RETURNS tstzspanset > AS 'MODULE_PATHNAME', 'Span_union_finalfn' > LANGUAGE C IMMUTABLE PARALLEL SAFE; > > CREATE AGGREGATE span_union(tstzspan) ( > SFUNC = array_agg_transfn, > STYPE = internal, > COMBINEFUNC = array_agg_combine, > SERIALFUNC = array_agg_serialize, > DESERIALFUNC = array_agg_deserialize, > FINALFUNC = tstzspan_union_finalfn > ); > > As can be seen, we reuse the array_agg function to accumulate the values in an array and the final function just does similarwork as the range_agg_finalfn to merge the overlapping spans. Did you note the following section in the CREATE AGGREGATE documentation [0]? """ An aggregate can optionally support partial aggregation, as described in Section 38.12.4. This requires specifying the COMBINEFUNC parameter. If the state_data_type is internal, it's usually also appropriate to provide the SERIALFUNC and DESERIALFUNC parameters so that parallel aggregation is possible. Note that the aggregate must also be marked PARALLEL SAFE to enable parallel aggregation. """ From this, it seems like the PARALLEL = SAFE argument is missing from your aggregate definition as provided above. Kind regards, Matthias van de Meent Neon (https://neon.tech) [0] https://www.postgresql.org/docs/16/sql-createaggregate.html
В списке pgsql-hackers по дате отправления: