PostgreSQL Source Code  git master
nodeWindowAgg.h File Reference
#include "nodes/execnodes.h"
Include dependency graph for nodeWindowAgg.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

WindowAggStateExecInitWindowAgg (WindowAgg *node, EState *estate, int eflags)
 
void ExecEndWindowAgg (WindowAggState *node)
 
void ExecReScanWindowAgg (WindowAggState *node)
 

Function Documentation

◆ ExecEndWindowAgg()

void ExecEndWindowAgg ( WindowAggState node)

Definition at line 2504 of file nodeWindowAgg.c.

References WindowAggState::agg_row_slot, WindowStatePerAggData::aggcontext, WindowAggState::aggcontext, ExecClearTuple(), ExecEndNode(), ExecFreeExprContext(), WindowAggState::first_part_slot, WindowAggState::framehead_slot, WindowAggState::frametail_slot, i, MemoryContextDelete(), WindowAggState::numaggs, outerPlan, outerPlanState, WindowAggState::partcontext, WindowAggState::peragg, WindowAggState::perfunc, pfree(), ScanState::ps, PlanState::ps_ExprContext, release_partition(), WindowAggState::ss, ScanState::ss_ScanTupleSlot, WindowAggState::temp_slot_1, WindowAggState::temp_slot_2, and WindowAggState::tmpcontext.

Referenced by ExecEndNode().

2505 {
2507  int i;
2508 
2509  release_partition(node);
2510 
2514  ExecClearTuple(node->temp_slot_1);
2515  ExecClearTuple(node->temp_slot_2);
2516  if (node->framehead_slot)
2518  if (node->frametail_slot)
2520 
2521  /*
2522  * Free both the expr contexts.
2523  */
2524  ExecFreeExprContext(&node->ss.ps);
2525  node->ss.ps.ps_ExprContext = node->tmpcontext;
2526  ExecFreeExprContext(&node->ss.ps);
2527 
2528  for (i = 0; i < node->numaggs; i++)
2529  {
2530  if (node->peragg[i].aggcontext != node->aggcontext)
2532  }
2535 
2536  pfree(node->perfunc);
2537  pfree(node->peragg);
2538 
2539  outerPlan = outerPlanState(node);
2540  ExecEndNode(outerPlan);
2541 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:198
ScanState ss
Definition: execnodes.h:1883
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:539
ExprContext * ps_ExprContext
Definition: execnodes.h:902
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:475
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1127
static void release_partition(WindowAggState *winstate)
TupleTableSlot * temp_slot_1
Definition: execnodes.h:1953
WindowStatePerFunc perfunc
Definition: execnodes.h:1890
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:561
TupleTableSlot * first_part_slot
Definition: execnodes.h:1946
ExprContext * tmpcontext
Definition: execnodes.h:1931
PlanState ps
Definition: execnodes.h:1124
void pfree(void *pointer)
Definition: mcxt.c:936
#define outerPlanState(node)
Definition: execnodes.h:914
TupleTableSlot * temp_slot_2
Definition: execnodes.h:1954
WindowStatePerAgg peragg
Definition: execnodes.h:1891
MemoryContext aggcontext
Definition: execnodes.h:1929
#define outerPlan(node)
Definition: plannodes.h:174
TupleTableSlot * agg_row_slot
Definition: execnodes.h:1952
TupleTableSlot * frametail_slot
Definition: execnodes.h:1949
TupleTableSlot * framehead_slot
Definition: execnodes.h:1948
MemoryContext aggcontext
int i
MemoryContext partcontext
Definition: execnodes.h:1928

◆ ExecInitWindowAgg()

WindowAggState* ExecInitWindowAgg ( WindowAgg node,
EState estate,
int  eflags 
)

Definition at line 2238 of file nodeWindowAgg.c.

References ACL_EXECUTE, aclcheck_error(), ACLCHECK_OK, WindowAggState::agg_row_slot, WindowAggState::agg_winobj, WindowAggState::aggcontext, WindowStatePerFuncData::aggno, ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, WindowFuncExprState::args, WindowObjectData::argstates, Assert, contain_volatile_functions(), CurrentMemoryContext, ExprContext::ecxt_aggnulls, ExprContext::ecxt_aggvalues, ExprContext::ecxt_per_query_memory, elog, WindowAgg::endInRangeFunc, WindowAgg::endOffset, equal(), ERROR, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecAssignExprContext(), ExecAssignProjectionInfo(), ExecCreateScanSlotFromOuterPlan(), ExecInitExpr(), ExecInitExtraTupleSlot(), ExecInitNode(), ExecInitResultTupleSlotTL(), PlanState::ExecProcNode, execTuplesMatchPrepare(), ExecWindowAgg(), WindowAggState::first_part_slot, WindowStatePerFuncData::flinfo, fmgr_info(), fmgr_info_cxt(), fmgr_info_set_expr, WindowAggState::framehead_slot, FRAMEOPTION_END_UNBOUNDED_FOLLOWING, FRAMEOPTION_GROUPS, FRAMEOPTION_RANGE, FRAMEOPTION_START_UNBOUNDED_PRECEDING, WindowAgg::frameOptions, WindowAggState::frameOptions, WindowAggState::frametail_slot, WindowAggState::funcs, get_func_name(), get_typlenbyval(), GetUserId(), i, initialize_peragg(), WindowAgg::inRangeAsc, WindowAgg::inRangeColl, WindowAgg::inRangeNullsFirst, InvokeFunctionExecuteHook, lfirst, list_length(), WindowObjectData::localmem, makeNode, WindowObjectData::markptr, NIL, WindowAggState::numaggs, WindowStatePerFuncData::numArguments, WindowAggState::numfuncs, OBJECT_FUNCTION, OidIsValid, WindowAgg::ordColIdx, WindowAggState::ordEqfunction, WindowAgg::ordNumCols, WindowAgg::ordOperators, outerPlan, outerPlanState, palloc0(), WindowAgg::partColIdx, WindowAggState::partcontext, WindowAggState::partEqfunction, WindowAgg::partNumCols, WindowAgg::partOperators, WindowAggState::peragg, WindowAggState::perfunc, pg_proc_aclcheck(), WindowStatePerFuncData::plain_agg, WindowAgg::plan, PlanState::plan, ScanState::ps, PlanState::ps_ExprContext, Plan::qual, PlanState::qual, WindowObjectData::readptr, WindowStatePerFuncData::resulttypeByVal, WindowStatePerFuncData::resulttypeLen, WindowAggState::ss, ScanState::ss_ScanTupleSlot, WindowAgg::startInRangeFunc, WindowAgg::startOffset, WindowAggState::startOffset, PlanState::state, WindowAggState::temp_slot_1, WindowAggState::temp_slot_2, WindowAggState::tmpcontext, TupleTableSlot::tts_tupleDescriptor, WindowStatePerFuncData::wfunc, WindowFuncExprState::wfunc, WindowStatePerAggData::wfuncno, WindowFuncExprState::wfuncno, WindowStatePerFuncData::wfuncstate, WindowStatePerFuncData::winCollation, WindowFunc::winfnoid, WindowStatePerFuncData::winobj, WindowFunc::winref, WindowAgg::winref, and WindowObjectData::winstate.

Referenced by ExecInitNode().

2239 {
2240  WindowAggState *winstate;
2241  Plan *outerPlan;
2242  ExprContext *econtext;
2243  ExprContext *tmpcontext;
2244  WindowStatePerFunc perfunc;
2245  WindowStatePerAgg peragg;
2246  int frameOptions = node->frameOptions;
2247  int numfuncs,
2248  wfuncno,
2249  numaggs,
2250  aggno;
2251  TupleDesc scanDesc;
2252  ListCell *l;
2253 
2254  /* check for unsupported flags */
2255  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
2256 
2257  /*
2258  * create state structure
2259  */
2260  winstate = makeNode(WindowAggState);
2261  winstate->ss.ps.plan = (Plan *) node;
2262  winstate->ss.ps.state = estate;
2263  winstate->ss.ps.ExecProcNode = ExecWindowAgg;
2264 
2265  /*
2266  * Create expression contexts. We need two, one for per-input-tuple
2267  * processing and one for per-output-tuple processing. We cheat a little
2268  * by using ExecAssignExprContext() to build both.
2269  */
2270  ExecAssignExprContext(estate, &winstate->ss.ps);
2271  tmpcontext = winstate->ss.ps.ps_ExprContext;
2272  winstate->tmpcontext = tmpcontext;
2273  ExecAssignExprContext(estate, &winstate->ss.ps);
2274 
2275  /* Create long-lived context for storage of partition-local memory etc */
2276  winstate->partcontext =
2278  "WindowAgg Partition",
2280 
2281  /*
2282  * Create mid-lived context for aggregate trans values etc.
2283  *
2284  * Note that moving aggregates each use their own private context, not
2285  * this one.
2286  */
2287  winstate->aggcontext =
2289  "WindowAgg Aggregates",
2291 
2292  /*
2293  * WindowAgg nodes never have quals, since they can only occur at the
2294  * logical top level of a query (ie, after any WHERE or HAVING filters)
2295  */
2296  Assert(node->plan.qual == NIL);
2297  winstate->ss.ps.qual = NULL;
2298 
2299  /*
2300  * initialize child nodes
2301  */
2302  outerPlan = outerPlan(node);
2303  outerPlanState(winstate) = ExecInitNode(outerPlan, estate, eflags);
2304 
2305  /*
2306  * initialize source tuple type (which is also the tuple type that we'll
2307  * store in the tuplestore and use in all our working slots).
2308  */
2309  ExecCreateScanSlotFromOuterPlan(estate, &winstate->ss);
2310  scanDesc = winstate->ss.ss_ScanTupleSlot->tts_tupleDescriptor;
2311 
2312  /*
2313  * tuple table initialization
2314  */
2315  winstate->first_part_slot = ExecInitExtraTupleSlot(estate, scanDesc);
2316  winstate->agg_row_slot = ExecInitExtraTupleSlot(estate, scanDesc);
2317  winstate->temp_slot_1 = ExecInitExtraTupleSlot(estate, scanDesc);
2318  winstate->temp_slot_2 = ExecInitExtraTupleSlot(estate, scanDesc);
2319 
2320  /*
2321  * create frame head and tail slots only if needed (must match logic in
2322  * update_frameheadpos and update_frametailpos)
2323  */
2324  winstate->framehead_slot = winstate->frametail_slot = NULL;
2325 
2326  if (frameOptions & (FRAMEOPTION_RANGE | FRAMEOPTION_GROUPS))
2327  {
2328  if (!(frameOptions & FRAMEOPTION_START_UNBOUNDED_PRECEDING))
2329  winstate->framehead_slot = ExecInitExtraTupleSlot(estate, scanDesc);
2330  if (!(frameOptions & FRAMEOPTION_END_UNBOUNDED_FOLLOWING))
2331  winstate->frametail_slot = ExecInitExtraTupleSlot(estate, scanDesc);
2332  }
2333 
2334  /*
2335  * Initialize result slot, type and projection.
2336  */
2337  ExecInitResultTupleSlotTL(estate, &winstate->ss.ps);
2338  ExecAssignProjectionInfo(&winstate->ss.ps, NULL);
2339 
2340  /* Set up data for comparing tuples */
2341  if (node->partNumCols > 0)
2342  winstate->partEqfunction =
2343  execTuplesMatchPrepare(scanDesc,
2344  node->partNumCols,
2345  node->partColIdx,
2346  node->partOperators,
2347  &winstate->ss.ps);
2348 
2349  if (node->ordNumCols > 0)
2350  winstate->ordEqfunction =
2351  execTuplesMatchPrepare(scanDesc,
2352  node->ordNumCols,
2353  node->ordColIdx,
2354  node->ordOperators,
2355  &winstate->ss.ps);
2356 
2357  /*
2358  * WindowAgg nodes use aggvalues and aggnulls as well as Agg nodes.
2359  */
2360  numfuncs = winstate->numfuncs;
2361  numaggs = winstate->numaggs;
2362  econtext = winstate->ss.ps.ps_ExprContext;
2363  econtext->ecxt_aggvalues = (Datum *) palloc0(sizeof(Datum) * numfuncs);
2364  econtext->ecxt_aggnulls = (bool *) palloc0(sizeof(bool) * numfuncs);
2365 
2366  /*
2367  * allocate per-wfunc/per-agg state information.
2368  */
2369  perfunc = (WindowStatePerFunc) palloc0(sizeof(WindowStatePerFuncData) * numfuncs);
2370  peragg = (WindowStatePerAgg) palloc0(sizeof(WindowStatePerAggData) * numaggs);
2371  winstate->perfunc = perfunc;
2372  winstate->peragg = peragg;
2373 
2374  wfuncno = -1;
2375  aggno = -1;
2376  foreach(l, winstate->funcs)
2377  {
2378  WindowFuncExprState *wfuncstate = (WindowFuncExprState *) lfirst(l);
2379  WindowFunc *wfunc = wfuncstate->wfunc;
2380  WindowStatePerFunc perfuncstate;
2381  AclResult aclresult;
2382  int i;
2383 
2384  if (wfunc->winref != node->winref) /* planner screwed up? */
2385  elog(ERROR, "WindowFunc with winref %u assigned to WindowAgg with winref %u",
2386  wfunc->winref, node->winref);
2387 
2388  /* Look for a previous duplicate window function */
2389  for (i = 0; i <= wfuncno; i++)
2390  {
2391  if (equal(wfunc, perfunc[i].wfunc) &&
2392  !contain_volatile_functions((Node *) wfunc))
2393  break;
2394  }
2395  if (i <= wfuncno)
2396  {
2397  /* Found a match to an existing entry, so just mark it */
2398  wfuncstate->wfuncno = i;
2399  continue;
2400  }
2401 
2402  /* Nope, so assign a new PerAgg record */
2403  perfuncstate = &perfunc[++wfuncno];
2404 
2405  /* Mark WindowFunc state node with assigned index in the result array */
2406  wfuncstate->wfuncno = wfuncno;
2407 
2408  /* Check permission to call window function */
2409  aclresult = pg_proc_aclcheck(wfunc->winfnoid, GetUserId(),
2410  ACL_EXECUTE);
2411  if (aclresult != ACLCHECK_OK)
2412  aclcheck_error(aclresult, OBJECT_FUNCTION,
2413  get_func_name(wfunc->winfnoid));
2414  InvokeFunctionExecuteHook(wfunc->winfnoid);
2415 
2416  /* Fill in the perfuncstate data */
2417  perfuncstate->wfuncstate = wfuncstate;
2418  perfuncstate->wfunc = wfunc;
2419  perfuncstate->numArguments = list_length(wfuncstate->args);
2420 
2421  fmgr_info_cxt(wfunc->winfnoid, &perfuncstate->flinfo,
2422  econtext->ecxt_per_query_memory);
2423  fmgr_info_set_expr((Node *) wfunc, &perfuncstate->flinfo);
2424 
2425  perfuncstate->winCollation = wfunc->inputcollid;
2426 
2427  get_typlenbyval(wfunc->wintype,
2428  &perfuncstate->resulttypeLen,
2429  &perfuncstate->resulttypeByVal);
2430 
2431  /*
2432  * If it's really just a plain aggregate function, we'll emulate the
2433  * Agg environment for it.
2434  */
2435  perfuncstate->plain_agg = wfunc->winagg;
2436  if (wfunc->winagg)
2437  {
2438  WindowStatePerAgg peraggstate;
2439 
2440  perfuncstate->aggno = ++aggno;
2441  peraggstate = &winstate->peragg[aggno];
2442  initialize_peragg(winstate, wfunc, peraggstate);
2443  peraggstate->wfuncno = wfuncno;
2444  }
2445  else
2446  {
2448 
2449  winobj->winstate = winstate;
2450  winobj->argstates = wfuncstate->args;
2451  winobj->localmem = NULL;
2452  perfuncstate->winobj = winobj;
2453  }
2454  }
2455 
2456  /* Update numfuncs, numaggs to match number of unique functions found */
2457  winstate->numfuncs = wfuncno + 1;
2458  winstate->numaggs = aggno + 1;
2459 
2460  /* Set up WindowObject for aggregates, if needed */
2461  if (winstate->numaggs > 0)
2462  {
2463  WindowObject agg_winobj = makeNode(WindowObjectData);
2464 
2465  agg_winobj->winstate = winstate;
2466  agg_winobj->argstates = NIL;
2467  agg_winobj->localmem = NULL;
2468  /* make sure markptr = -1 to invalidate. It may not get used */
2469  agg_winobj->markptr = -1;
2470  agg_winobj->readptr = -1;
2471  winstate->agg_winobj = agg_winobj;
2472  }
2473 
2474  /* copy frame options to state node for easy access */
2475  winstate->frameOptions = frameOptions;
2476 
2477  /* initialize frame bound offset expressions */
2478  winstate->startOffset = ExecInitExpr((Expr *) node->startOffset,
2479  (PlanState *) winstate);
2480  winstate->endOffset = ExecInitExpr((Expr *) node->endOffset,
2481  (PlanState *) winstate);
2482 
2483  /* Lookup in_range support functions if needed */
2484  if (OidIsValid(node->startInRangeFunc))
2485  fmgr_info(node->startInRangeFunc, &winstate->startInRangeFunc);
2486  if (OidIsValid(node->endInRangeFunc))
2487  fmgr_info(node->endInRangeFunc, &winstate->endInRangeFunc);
2488  winstate->inRangeColl = node->inRangeColl;
2489  winstate->inRangeAsc = node->inRangeAsc;
2490  winstate->inRangeNullsFirst = node->inRangeNullsFirst;
2491 
2492  winstate->all_first = true;
2493  winstate->partition_spooled = false;
2494  winstate->more_partitions = false;
2495 
2496  return winstate;
2497 }
int ordNumCols
Definition: plannodes.h:808
#define NIL
Definition: pg_list.h:69
List * qual
Definition: plannodes.h:145
ExprState * endOffset
Definition: execnodes.h:1910
Datum * ecxt_aggvalues
Definition: execnodes.h:227
struct WindowStatePerAggData * WindowStatePerAgg
Definition: execnodes.h:1879
Oid inRangeColl
Definition: plannodes.h:817
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:2992
Oid GetUserId(void)
Definition: miscinit.c:284
ScanState ss
Definition: execnodes.h:1883
ExprContext * ps_ExprContext
Definition: execnodes.h:902
AttrNumber * ordColIdx
Definition: plannodes.h:809
Definition: nodes.h:513
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1127
struct WindowStatePerFuncData * WindowStatePerFunc
Definition: execnodes.h:1878
WindowFuncExprState * wfuncstate
Definition: nodeWindowAgg.c:79
bool contain_volatile_functions(Node *clause)
Definition: clauses.c:960
EState * state
Definition: execnodes.h:870
Index winref
Definition: primnodes.h:361
#define FRAMEOPTION_START_UNBOUNDED_PRECEDING
Definition: parsenodes.h:508
TupleTableSlot * temp_slot_1
Definition: execnodes.h:1953
#define OidIsValid(objectId)
Definition: c.h:594
WindowStatePerFunc perfunc
Definition: execnodes.h:1890
Oid * ordOperators
Definition: plannodes.h:810
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc)
Definition: execTuples.c:910
Oid endInRangeFunc
Definition: plannodes.h:816
TupleTableSlot * first_part_slot
Definition: execnodes.h:1946
ExprContext * tmpcontext
Definition: execnodes.h:1931
PlanState ps
Definition: execnodes.h:1124
struct WindowObjectData * agg_winobj
Definition: execnodes.h:1904
bool inRangeNullsFirst
Definition: execnodes.h:1919
Node * startOffset
Definition: plannodes.h:812
static WindowStatePerAggData * initialize_peragg(WindowAggState *winstate, WindowFunc *wfunc, WindowStatePerAgg peraggstate)
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3352
ExprState * partEqfunction
Definition: execnodes.h:1892
#define ERROR
Definition: elog.h:43
FmgrInfo endInRangeFunc
Definition: execnodes.h:1916
char * get_func_name(Oid funcid)
Definition: lsyscache.c:1397
void ExecCreateScanSlotFromOuterPlan(EState *estate, ScanState *scanstate)
Definition: execUtils.c:593
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:122
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:197
#define EXEC_FLAG_BACKWARD
Definition: executor.h:61
#define outerPlanState(node)
Definition: execnodes.h:914
TupleTableSlot * temp_slot_2
Definition: execnodes.h:1954
WindowStatePerAgg peragg
Definition: execnodes.h:1891
ExprState * ordEqfunction
Definition: execnodes.h:1893
ExprState * startOffset
Definition: execnodes.h:1909
void ExecAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc)
Definition: execUtils.c:453
Node * endOffset
Definition: plannodes.h:813
#define fmgr_info_set_expr(expr, finfo)
Definition: fmgr.h:104
#define FRAMEOPTION_END_UNBOUNDED_FOLLOWING
Definition: parsenodes.h:511
int partNumCols
Definition: plannodes.h:805
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
MemoryContext aggcontext
Definition: execnodes.h:1929
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
Definition: fmgr.c:132
#define InvokeFunctionExecuteHook(objectId)
Definition: objectaccess.h:179
#define outerPlan(node)
Definition: plannodes.h:174
#define AllocSetContextCreate(parent, name, allocparams)
Definition: memutils.h:165
bool inRangeAsc
Definition: plannodes.h:818
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:121
bool * ecxt_aggnulls
Definition: execnodes.h:228
static TupleTableSlot * ExecWindowAgg(PlanState *pstate)
WindowAggState * winstate
Definition: nodeWindowAgg.c:63
void * palloc0(Size size)
Definition: mcxt.c:864
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:874
AclResult
Definition: acl.h:178
uintptr_t Datum
Definition: postgres.h:365
TupleTableSlot * agg_row_slot
Definition: execnodes.h:1952
AttrNumber * partColIdx
Definition: plannodes.h:806
void ExecInitResultTupleSlotTL(EState *estate, PlanState *planstate)
Definition: execTuples.c:870
Plan * plan
Definition: execnodes.h:868
TupleTableSlot * frametail_slot
Definition: execnodes.h:1949
bool more_partitions
Definition: execnodes.h:1937
ExprState * execTuplesMatchPrepare(TupleDesc desc, int numCols, AttrNumber *keyColIdx, Oid *eqOperators, PlanState *parent)
Definition: execGrouping.c:60
Oid * partOperators
Definition: plannodes.h:807
#define makeNode(_type_)
Definition: nodes.h:561
#define FRAMEOPTION_RANGE
Definition: parsenodes.h:504
#define Assert(condition)
Definition: c.h:688
#define lfirst(lc)
Definition: pg_list.h:106
Index winref
Definition: plannodes.h:804
#define EXEC_FLAG_MARK
Definition: executor.h:62
FmgrInfo startInRangeFunc
Definition: execnodes.h:1915
TupleTableSlot * framehead_slot
Definition: execnodes.h:1948
bool inRangeNullsFirst
Definition: plannodes.h:819
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:425
static int list_length(const List *l)
Definition: pg_list.h:89
void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval)
Definition: lsyscache.c:2005
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:216
ExprState * qual
Definition: execnodes.h:886
Oid startInRangeFunc
Definition: plannodes.h:815
bool partition_spooled
Definition: execnodes.h:1935
#define ACL_EXECUTE
Definition: parsenodes.h:79
AclResult pg_proc_aclcheck(Oid proc_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4652
int i
Plan plan
Definition: plannodes.h:803
#define FRAMEOPTION_GROUPS
Definition: parsenodes.h:506
MemoryContext partcontext
Definition: execnodes.h:1928
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
Definition: execExpr.c:118
#define elog
Definition: elog.h:219
int frameOptions
Definition: plannodes.h:811
WindowFunc * wfunc
Definition: execnodes.h:688
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:139

◆ ExecReScanWindowAgg()

void ExecReScanWindowAgg ( WindowAggState node)

Definition at line 2548 of file nodeWindowAgg.c.

References WindowAggState::agg_row_slot, WindowAggState::all_done, WindowAggState::all_first, PlanState::chgParam, ExprContext::ecxt_aggnulls, ExprContext::ecxt_aggvalues, ExecClearTuple(), ExecReScan(), WindowAggState::first_part_slot, WindowAggState::framehead_slot, WindowAggState::frametail_slot, MemSet, WindowAggState::numfuncs, outerPlan, outerPlanState, ScanState::ps, PlanState::ps_ExprContext, release_partition(), WindowAggState::ss, ScanState::ss_ScanTupleSlot, WindowAggState::temp_slot_1, and WindowAggState::temp_slot_2.

Referenced by ExecReScan().

2549 {
2551  ExprContext *econtext = node->ss.ps.ps_ExprContext;
2552 
2553  node->all_done = false;
2554  node->all_first = true;
2555 
2556  /* release tuplestore et al */
2557  release_partition(node);
2558 
2559  /* release all temp tuples, but especially first_part_slot */
2563  ExecClearTuple(node->temp_slot_1);
2564  ExecClearTuple(node->temp_slot_2);
2565  if (node->framehead_slot)
2567  if (node->frametail_slot)
2569 
2570  /* Forget current wfunc values */
2571  MemSet(econtext->ecxt_aggvalues, 0, sizeof(Datum) * node->numfuncs);
2572  MemSet(econtext->ecxt_aggnulls, 0, sizeof(bool) * node->numfuncs);
2573 
2574  /*
2575  * if chgParam of subnode is not null then plan will be re-scanned by
2576  * first ExecProcNode.
2577  */
2578  if (outerPlan->chgParam == NULL)
2579  ExecReScan(outerPlan);
2580 }
Datum * ecxt_aggvalues
Definition: execnodes.h:227
ScanState ss
Definition: execnodes.h:1883
ExprContext * ps_ExprContext
Definition: execnodes.h:902
void ExecReScan(PlanState *node)
Definition: execAmi.c:76
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:475
#define MemSet(start, val, len)
Definition: c.h:897
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1127
static void release_partition(WindowAggState *winstate)
TupleTableSlot * temp_slot_1
Definition: execnodes.h:1953
TupleTableSlot * first_part_slot
Definition: execnodes.h:1946
PlanState ps
Definition: execnodes.h:1124
#define outerPlanState(node)
Definition: execnodes.h:914
TupleTableSlot * temp_slot_2
Definition: execnodes.h:1954
Bitmapset * chgParam
Definition: execnodes.h:896
#define outerPlan(node)
Definition: plannodes.h:174
bool * ecxt_aggnulls
Definition: execnodes.h:228
uintptr_t Datum
Definition: postgres.h:365
TupleTableSlot * agg_row_slot
Definition: execnodes.h:1952
TupleTableSlot * frametail_slot
Definition: execnodes.h:1949
TupleTableSlot * framehead_slot
Definition: execnodes.h:1948