[postgis-tickets] [PostGIS] #3751: Parallel support for aggregates with transitions
PostGIS
trac at osgeo.org
Fri May 5 05:19:41 PDT 2017
#3751: Parallel support for aggregates with transitions
-------------------------+---------------------------
Reporter: robe | Owner: pramsey
Type: enhancement | Status: new
Priority: high | Milestone: PostGIS 2.4.0
Component: postgis | Version: 2.3.x
Keywords: |
-------------------------+---------------------------
I didn't think aggregate functions that use transitions (take internal as
input) are parallelizable.
Turns out that even in PostgreSQL 9.6 it is possible to do so as long as
you define a serialize and deserialize function for them. These are new
args to CREATE AGGREGATE in 9.6
https://www.postgresql.org/docs/9.6/static/sql-createaggregate.html
{{{
CREATE AGGREGATE name ( [ argmode ] [ argname ] arg_data_type [ , ... ] )
(
SFUNC = sfunc,
STYPE = state_data_type
[ , SSPACE = state_data_size ]
[ , FINALFUNC = ffunc ]
[ , FINALFUNC_EXTRA ]
[ , COMBINEFUNC = combinefunc ]
[ , SERIALFUNC = serialfunc ]
[ , DESERIALFUNC = deserialfunc ]
[ , INITCOND = initial_condition ]
[ , MSFUNC = msfunc ]
[ , MINVFUNC = minvfunc ]
[ , MSTYPE = mstate_data_type ]
[ , MSSPACE = mstate_data_size ]
[ , MFINALFUNC = mffunc ]
[ , MFINALFUNC_EXTRA ]
[ , MINITCOND = minitial_condition ]
[ , SORTOP = sort_operator ]
[ , PARALLEL = { SAFE | RESTRICTED | UNSAFE } ]
)
}}}
From the docs
----
serialfunc
An aggregate function whose state_data_type is internal can
participate in parallel aggregation only if it has a serialfunc function,
which must serialize the aggregate state into a bytea value for
transmission to another process. This function must take a single argument
of type internal and return type bytea. A corresponding deserialfunc is
also required.
deserialfunc
Deserialize a previously serialized aggregate state back into
state_data_type. This function must take two arguments of types bytea and
internal, and produce a result of type internal. (Note: the second,
internal argument is unused, but is required for type safety reasons.)
----
It would be really nice if we can do this because then we have the
possiblity of making really costly aggregates like ST_Union and the
various raster aggregates parallelizable.
--
Ticket URL: <https://trac.osgeo.org/postgis/ticket/3751>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.
More information about the postgis-tickets
mailing list