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

Function initialize_windowaggregate

src/backend/executor/nodeWindowAgg.c:237–278  ·  view source on GitHub ↗

* initialize_windowaggregate * parallel to initialize_aggregates in nodeAgg.c */

Source from the content-addressed store, hash-verified

235 * parallel to initialize_aggregates in nodeAgg.c
236 */
237static void
238initialize_windowaggregate(WindowAggState *winstate,
239 WindowStatePerFunc perfuncstate,
240 WindowStatePerAgg peraggstate)
241{
242 MemoryContext oldContext;
243
244 /*
245 * If we're using a private aggcontext, we may reset it here. But if the
246 * context is shared, we don't know which other aggregates may still need
247 * it, so we must leave it to the caller to reset at an appropriate time.
248 */
249 if (peraggstate->aggcontext != winstate->aggcontext)
250 MemoryContextResetAndDeleteChildren(peraggstate->aggcontext);
251
252 if (peraggstate->initValueIsNull)
253 peraggstate->transValue = peraggstate->initValue;
254 else
255 {
256 oldContext = MemoryContextSwitchTo(peraggstate->aggcontext);
257 peraggstate->transValue = datumCopy(peraggstate->initValue,
258 peraggstate->transtypeByVal,
259 peraggstate->transtypeLen);
260 MemoryContextSwitchTo(oldContext);
261 }
262 peraggstate->transValueIsNull = peraggstate->initValueIsNull;
263 peraggstate->transValueCount = 0;
264 peraggstate->resultValue = (Datum) 0;
265 peraggstate->resultValueIsNull = true;
266
267 if (peraggstate->isDistinct)
268 {
269 peraggstate->distinctSortState =
270 tuplesort_begin_datum(peraggstate->distinctType,
271 peraggstate->distinctLtOper,
272 peraggstate->distinctColl,
273 false, /* nullsFirstFlag */
274 PlanStateOperatorMemKB((PlanState *) winstate),
275 NULL, /* coordinate */
276 false);
277 }
278}
279
280/*
281 * advance_windowaggregate

Callers 2

eval_windowaggregatesFunction · 0.85

Calls 4

MemoryContextSwitchToFunction · 0.85
datumCopyFunction · 0.85
tuplesort_begin_datumFunction · 0.85
PlanStateOperatorMemKBFunction · 0.85

Tested by

no test coverage detected