mirror of
https://github.com/postgres/postgres.git
synced 2025-07-17 06:41:09 +03:00
Allow parallel aggregate on string_agg and array_agg
This adds combine, serial and deserial functions for the array_agg() and string_agg() aggregate functions, thus allowing these aggregates to partake in partial aggregations. This allows both parallel aggregation to take place when these aggregates are present and also allows additional partition-wise aggregation plan shapes to include plans that require additional aggregation once the partially aggregated results from the partitions have been combined. Author: David Rowley Reviewed-by: Andres Freund, Tomas Vondra, Stephen Frost, Tom Lane Discussion: https://postgr.es/m/CAKJS1f9sx_6GTcvd6TMuZnNtCh0VhBzhX6FZqw17TgVFH-ga_A@mail.gmail.com
This commit is contained in:
@ -14,6 +14,7 @@
|
||||
*/
|
||||
#include "postgres.h"
|
||||
|
||||
#include "access/htup_details.h"
|
||||
#include "catalog/pg_aggregate.h"
|
||||
#include "catalog/pg_constraint.h"
|
||||
#include "catalog/pg_type.h"
|
||||
@ -28,7 +29,7 @@
|
||||
#include "rewrite/rewriteManip.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/lsyscache.h"
|
||||
|
||||
#include "utils/syscache.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -1947,6 +1948,40 @@ resolve_aggregate_transtype(Oid aggfuncid,
|
||||
return aggtranstype;
|
||||
}
|
||||
|
||||
/*
|
||||
* agg_args_support_sendreceive
|
||||
* Returns true if all non-byval of aggref's arg types have send and
|
||||
* receive functions.
|
||||
*/
|
||||
bool
|
||||
agg_args_support_sendreceive(Aggref *aggref)
|
||||
{
|
||||
ListCell *lc;
|
||||
|
||||
foreach(lc, aggref->args)
|
||||
{
|
||||
HeapTuple typeTuple;
|
||||
Form_pg_type pt;
|
||||
TargetEntry *tle = (TargetEntry *) lfirst(lc);
|
||||
Oid type = exprType((Node *) tle->expr);
|
||||
|
||||
typeTuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(type));
|
||||
if (!HeapTupleIsValid(typeTuple))
|
||||
elog(ERROR, "cache lookup failed for type %u", type);
|
||||
|
||||
pt = (Form_pg_type) GETSTRUCT(typeTuple);
|
||||
|
||||
if (!pt->typbyval &&
|
||||
(!OidIsValid(pt->typsend) || !OidIsValid(pt->typreceive)))
|
||||
{
|
||||
ReleaseSysCache(typeTuple);
|
||||
return false;
|
||||
}
|
||||
ReleaseSysCache(typeTuple);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create an expression tree for the transition function of an aggregate.
|
||||
* This is needed so that polymorphic functions can be used within an
|
||||
|
Reference in New Issue
Block a user