1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-21 10:42:50 +03:00

Cleanup some aggregate code in the executor

Here we alter the code that calls build_pertrans_for_aggref() so that the
function no longer needs to special-case whether it's dealing with an
aggtransfn or an aggcombinefn.  This allows us to reuse the
build_aggregate_transfn_expr() function and just get rid of the
build_aggregate_combinefn_expr() completely.

All of the special case code that was in build_pertrans_for_aggref() has
been moved up to the calling functions.

This saves about a dozen lines of code in nodeAgg.c and a few dozen more
in parse_agg.c

Also, rename a few variables in nodeAgg.c to try to make it more clear
that we're working with either a aggtransfn or an aggcombinefn.  Some of
the old names would have you believe that we were always working with an
aggtransfn.

Discussion: https://postgr.es/m/CAApHDvptMQ9FmF0D67zC_w88yVnoNVR2+kkOQGUrCmdxWxLULQ@mail.gmail.com
This commit is contained in:
David Rowley
2021-07-04 18:47:31 +12:00
parent 792259591c
commit 63b1af9437
3 changed files with 118 additions and 155 deletions

View File

@@ -1959,6 +1959,11 @@ resolve_aggregate_transtype(Oid aggfuncid,
* latter may be InvalidOid, however if invtransfn_oid is set then
* transfn_oid must also be set.
*
* transfn_oid may also be passed as the aggcombinefn when the *transfnexpr is
* to be used for a combine aggregate phase. We expect invtransfn_oid to be
* InvalidOid in this case since there is no such thing as an inverse
* combinefn.
*
* Pointers to the constructed trees are returned into *transfnexpr,
* *invtransfnexpr. If there is no invtransfn, the respective pointer is set
* to NULL. Since use of the invtransfn is optional, NULL may be passed for
@@ -2021,35 +2026,6 @@ build_aggregate_transfn_expr(Oid *agg_input_types,
}
}
/*
* Like build_aggregate_transfn_expr, but creates an expression tree for the
* combine function of an aggregate, rather than the transition function.
*/
void
build_aggregate_combinefn_expr(Oid agg_state_type,
Oid agg_input_collation,
Oid combinefn_oid,
Expr **combinefnexpr)
{
Node *argp;
List *args;
FuncExpr *fexpr;
/* combinefn takes two arguments of the aggregate state type */
argp = make_agg_arg(agg_state_type, agg_input_collation);
args = list_make2(argp, argp);
fexpr = makeFuncExpr(combinefn_oid,
agg_state_type,
args,
InvalidOid,
agg_input_collation,
COERCE_EXPLICIT_CALL);
/* combinefn is currently never treated as variadic */
*combinefnexpr = (Expr *) fexpr;
}
/*
* Like build_aggregate_transfn_expr, but creates an expression tree for the
* serialization function of an aggregate.