MCPcopy Create free account
hub / github.com/apache/cloudberry / build_pertrans_for_aggref

Function build_pertrans_for_aggref

src/backend/executor/nodeAgg.c:4337–4642  ·  view source on GitHub ↗

* Build the state needed to calculate a state value for an aggregate. * * This initializes all the fields in 'pertrans'. 'aggref' is the aggregate * to initialize the state for. 'aggtransfn', 'aggtranstype', and the rest * of the arguments could be calculated from 'aggref', but the caller has * calculated them already, so might as well pass them. */

Source from the content-addressed store, hash-verified

4335 * calculated them already, so might as well pass them.
4336 */
4337static void
4338build_pertrans_for_aggref(AggStatePerTrans pertrans,
4339 AggState *aggstate, EState *estate,
4340 Aggref *aggref,
4341 Oid aggtransfn, Oid aggtranstype,
4342 Oid aggserialfn, Oid aggdeserialfn,
4343 Datum initValue, bool initValueIsNull,
4344 Oid *inputTypes, int numArguments)
4345{
4346 int numGroupingSets = Max(aggstate->maxsets, 1);
4347 Expr *serialfnexpr = NULL;
4348 Expr *deserialfnexpr = NULL;
4349 ListCell *lc;
4350 int numInputs;
4351 int numDirectArgs;
4352 List *sortlist;
4353 int numSortCols;
4354 int numDistinctCols;
4355 int i;
4356
4357 /* Begin filling in the pertrans data */
4358 pertrans->aggref = aggref;
4359 pertrans->aggshared = false;
4360 pertrans->aggCollation = aggref->inputcollid;
4361 pertrans->transfn_oid = aggtransfn;
4362 pertrans->serialfn_oid = aggserialfn;
4363 pertrans->deserialfn_oid = aggdeserialfn;
4364 pertrans->initValue = initValue;
4365 pertrans->initValueIsNull = initValueIsNull;
4366
4367 /* Count the "direct" arguments, if any */
4368 numDirectArgs = list_length(aggref->aggdirectargs);
4369
4370 /* Count the number of aggregated input columns */
4371 pertrans->numInputs = numInputs = list_length(aggref->args);
4372
4373 pertrans->aggtranstype = aggtranstype;
4374
4375 /*
4376 * When combining states, we have no use at all for the aggregate
4377 * function's transfn. Instead we use the combinefn. In this case, the
4378 * transfn and transfn_oid fields of pertrans refer to the combine
4379 * function rather than the transition function.
4380 */
4381 if (DO_AGGSPLIT_COMBINE(pertrans->aggref->aggsplit))
4382 {
4383 Expr *combinefnexpr;
4384 size_t numTransArgs;
4385
4386 /*
4387 * When combining there's only one input, the to-be-combined added
4388 * transition value from below (this node's transition value is
4389 * counted separately).
4390 */
4391 pertrans->numTransInputs = 1;
4392
4393 /* account for the current transition state */
4394 numTransArgs = pertrans->numTransInputs + 1;

Callers 1

ExecInitAggFunction · 0.85

Calls 15

list_lengthFunction · 0.85
fmgr_infoFunction · 0.85
format_type_beFunction · 0.85
IsBinaryCoercibleFunction · 0.85
get_typlenbyvalFunction · 0.85
ExecTypeFromTLFunction · 0.85
ExecInitExtraTupleSlotFunction · 0.85
get_sortgroupclause_tleFunction · 0.85

Tested by

no test coverage detected