diff options
Diffstat (limited to 'src/backend/executor/nodeAgg.c')
-rw-r--r-- | src/backend/executor/nodeAgg.c | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/src/backend/executor/nodeAgg.c b/src/backend/executor/nodeAgg.c index d01fc4f52e1..fd3c71e7641 100644 --- a/src/backend/executor/nodeAgg.c +++ b/src/backend/executor/nodeAgg.c @@ -2911,12 +2911,6 @@ build_pertrans_for_aggref(AggStatePerTrans pertrans, pertrans->aggtranstype = aggtranstype; - /* Detect how many arguments to pass to the transfn */ - if (AGGKIND_IS_ORDERED_SET(aggref->aggkind)) - pertrans->numTransInputs = numInputs; - else - pertrans->numTransInputs = numArguments; - /* * When combining states, we have no use at all for the aggregate * function's transfn. Instead we use the combinefn. In this case, the @@ -2926,6 +2920,17 @@ build_pertrans_for_aggref(AggStatePerTrans pertrans, if (DO_AGGSPLIT_COMBINE(aggstate->aggsplit)) { Expr *combinefnexpr; + size_t numTransArgs; + + /* + * When combining there's only one input, the to-be-combined added + * transition value from below (this node's transition value is + * counted separately). + */ + pertrans->numTransInputs = 1; + + /* account for the current transition state */ + numTransArgs = pertrans->numTransInputs + 1; build_aggregate_combinefn_expr(aggtranstype, aggref->inputcollid, @@ -2938,7 +2943,7 @@ build_pertrans_for_aggref(AggStatePerTrans pertrans, (FunctionCallInfo) palloc(SizeForFunctionCallInfo(2)); InitFunctionCallInfoData(*pertrans->transfn_fcinfo, &pertrans->transfn, - 2, + numTransArgs, pertrans->aggCollation, (void *) aggstate, NULL); @@ -2956,7 +2961,16 @@ build_pertrans_for_aggref(AggStatePerTrans pertrans, else { Expr *transfnexpr; - size_t numInputs = pertrans->numTransInputs + 1; + size_t numTransArgs; + + /* Detect how many arguments to pass to the transfn */ + if (AGGKIND_IS_ORDERED_SET(aggref->aggkind)) + pertrans->numTransInputs = numInputs; + else + pertrans->numTransInputs = numArguments; + + /* account for the current transition state */ + numTransArgs = pertrans->numTransInputs + 1; /* * Set up infrastructure for calling the transfn. Note that invtrans @@ -2976,10 +2990,10 @@ build_pertrans_for_aggref(AggStatePerTrans pertrans, fmgr_info_set_expr((Node *) transfnexpr, &pertrans->transfn); pertrans->transfn_fcinfo = - (FunctionCallInfo) palloc(SizeForFunctionCallInfo(numInputs)); + (FunctionCallInfo) palloc(SizeForFunctionCallInfo(numTransArgs)); InitFunctionCallInfoData(*pertrans->transfn_fcinfo, &pertrans->transfn, - numInputs, + numTransArgs, pertrans->aggCollation, (void *) aggstate, NULL); |