From 5fe5a2cee91117673e04617aeb1a38e305dcd783 Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Tue, 29 Mar 2016 15:04:05 -0400 Subject: Allow aggregate transition states to be serialized and deserialized. This is necessary infrastructure for supporting parallel aggregation for aggregates whose transition type is "internal". Such values can't be passed between cooperating processes, because they are just pointers. David Rowley, reviewed by Tomas Vondra and by me. --- src/backend/parser/parse_agg.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/backend/parser/parse_agg.c') diff --git a/src/backend/parser/parse_agg.c b/src/backend/parser/parse_agg.c index 583462a9181..91bfe66c590 100644 --- a/src/backend/parser/parse_agg.c +++ b/src/backend/parser/parse_agg.c @@ -1964,6 +1964,45 @@ build_aggregate_combinefn_expr(Oid agg_state_type, *combinefnexpr = (Expr *) fexpr; } +/* + * Like build_aggregate_transfn_expr, but creates an expression tree for the + * serialization or deserialization function of an aggregate, rather than the + * transition function. This may be used for either the serialization or + * deserialization function by swapping the first two parameters over. + */ +void +build_aggregate_serialfn_expr(Oid agg_input_type, + Oid agg_output_type, + Oid agg_input_collation, + Oid serialfn_oid, + Expr **serialfnexpr) +{ + Param *argp; + List *args; + FuncExpr *fexpr; + + /* Build arg list to use in the FuncExpr node. */ + argp = makeNode(Param); + argp->paramkind = PARAM_EXEC; + argp->paramid = -1; + argp->paramtype = agg_input_type; + argp->paramtypmod = -1; + argp->paramcollid = agg_input_collation; + argp->location = -1; + + /* takes a single arg of the agg_input_type */ + args = list_make1(argp); + + fexpr = makeFuncExpr(serialfn_oid, + agg_output_type, + args, + InvalidOid, + agg_input_collation, + COERCE_EXPLICIT_CALL); + fexpr->funcvariadic = false; + *serialfnexpr = (Expr *) fexpr; +} + /* * Like build_aggregate_transfn_expr, but creates an expression tree for the * final function of an aggregate, rather than the transition function. -- cgit v1.2.3