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

Function finalize_partialaggregate

src/backend/executor/nodeAgg.c:1203–1257  ·  view source on GitHub ↗

* Compute the output value of one partial aggregate. * * The serialization function will be run, and the result delivered, in the * output-tuple context; caller's CurrentMemoryContext does not matter. */

Source from the content-addressed store, hash-verified

1201 * output-tuple context; caller's CurrentMemoryContext does not matter.
1202 */
1203static void
1204finalize_partialaggregate(AggState *aggstate,
1205 AggStatePerAgg peragg,
1206 AggStatePerGroup pergroupstate,
1207 Datum *resultVal, bool *resultIsNull)
1208{
1209 AggStatePerTrans pertrans = &aggstate->pertrans[peragg->transno];
1210 MemoryContext oldContext;
1211
1212 oldContext = MemoryContextSwitchTo(aggstate->ss.ps.ps_ExprContext->ecxt_per_tuple_memory);
1213
1214 /*
1215 * serialfn_oid will be set if we must serialize the transvalue before
1216 * returning it
1217 */
1218 if (OidIsValid(pertrans->serialfn_oid))
1219 {
1220 /* Don't call a strict serialization function with NULL input. */
1221 if (pertrans->serialfn.fn_strict && pergroupstate->transValueIsNull)
1222 {
1223 *resultVal = (Datum) 0;
1224 *resultIsNull = true;
1225 }
1226 else
1227 {
1228 FunctionCallInfo fcinfo = pertrans->serialfn_fcinfo;
1229
1230 fcinfo->args[0].value =
1231 MakeExpandedObjectReadOnly(pergroupstate->transValue,
1232 pergroupstate->transValueIsNull,
1233 pertrans->transtypeLen);
1234 fcinfo->args[0].isnull = pergroupstate->transValueIsNull;
1235 fcinfo->isnull = false;
1236
1237 *resultVal = FunctionCallInvoke(fcinfo);
1238 *resultIsNull = fcinfo->isnull;
1239 }
1240 }
1241 else
1242 {
1243 /* Don't need MakeExpandedObjectReadOnly; datumCopy will copy it */
1244 *resultVal = pergroupstate->transValue;
1245 *resultIsNull = pergroupstate->transValueIsNull;
1246 }
1247
1248 /* If result is pass-by-ref, make sure it is in the right context. */
1249 if (!peragg->resulttypeByVal && !*resultIsNull &&
1250 !MemoryContextContainsGenericAllocation(CurrentMemoryContext,
1251 DatumGetPointer(*resultVal)))
1252 *resultVal = datumCopy(*resultVal,
1253 peragg->resulttypeByVal,
1254 peragg->resulttypeLen);
1255
1256 MemoryContextSwitchTo(oldContext);
1257}
1258
1259/*
1260 * Extract the attributes that make up the grouping key into the

Callers 1

finalize_aggregatesFunction · 0.85

Calls 3

MemoryContextSwitchToFunction · 0.85
datumCopyFunction · 0.85

Tested by

no test coverage detected