* initialize_windowaggregate * parallel to initialize_aggregates in nodeAgg.c */
| 235 | * parallel to initialize_aggregates in nodeAgg.c |
| 236 | */ |
| 237 | static void |
| 238 | initialize_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 |
no test coverage detected