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 2682 of file nodeWindowAgg.c.

2683 {
2685  int i;
2686 
2687  release_partition(node);
2688 
2689  for (i = 0; i < node->numaggs; i++)
2690  {
2691  if (node->peragg[i].aggcontext != node->aggcontext)
2693  }
2696 
2697  pfree(node->perfunc);
2698  pfree(node->peragg);
2699 
2700  outerPlan = outerPlanState(node);
2702 }
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:557
#define outerPlanState(node)
Definition: execnodes.h:1213
int i
Definition: isn.c:73
void pfree(void *pointer)
Definition: mcxt.c:1520
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:454
static void release_partition(WindowAggState *winstate)
#define outerPlan(node)
Definition: plannodes.h:182
MemoryContext aggcontext
Definition: execnodes.h:2606
WindowStatePerAgg peragg
Definition: execnodes.h:2567
MemoryContext partcontext
Definition: execnodes.h:2605
WindowStatePerFunc perfunc
Definition: execnodes.h:2566
MemoryContext aggcontext

References WindowStatePerAggData::aggcontext, WindowAggState::aggcontext, ExecEndNode(), i, MemoryContextDelete(), WindowAggState::numaggs, outerPlan, outerPlanState, WindowAggState::partcontext, WindowAggState::peragg, WindowAggState::perfunc, pfree(), and release_partition().

Referenced by ExecEndNode().

◆ ExecInitWindowAgg()

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

Definition at line 2375 of file nodeWindowAgg.c.

2376 {
2377  WindowAggState *winstate;
2378  Plan *outerPlan;
2379  ExprContext *econtext;
2380  ExprContext *tmpcontext;
2381  WindowStatePerFunc perfunc;
2382  WindowStatePerAgg peragg;
2383  int frameOptions = node->frameOptions;
2384  int numfuncs,
2385  wfuncno,
2386  numaggs,
2387  aggno;
2388  TupleDesc scanDesc;
2389  ListCell *l;
2390 
2391  /* check for unsupported flags */
2392  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
2393 
2394  /*
2395  * create state structure
2396  */
2397  winstate = makeNode(WindowAggState);
2398  winstate->ss.ps.plan = (Plan *) node;
2399  winstate->ss.ps.state = estate;
2400  winstate->ss.ps.ExecProcNode = ExecWindowAgg;
2401 
2402  /* copy frame options to state node for easy access */
2403  winstate->frameOptions = frameOptions;
2404 
2405  /*
2406  * Create expression contexts. We need two, one for per-input-tuple
2407  * processing and one for per-output-tuple processing. We cheat a little
2408  * by using ExecAssignExprContext() to build both.
2409  */
2410  ExecAssignExprContext(estate, &winstate->ss.ps);
2411  tmpcontext = winstate->ss.ps.ps_ExprContext;
2412  winstate->tmpcontext = tmpcontext;
2413  ExecAssignExprContext(estate, &winstate->ss.ps);
2414 
2415  /* Create long-lived context for storage of partition-local memory etc */
2416  winstate->partcontext =
2418  "WindowAgg Partition",
2420 
2421  /*
2422  * Create mid-lived context for aggregate trans values etc.
2423  *
2424  * Note that moving aggregates each use their own private context, not
2425  * this one.
2426  */
2427  winstate->aggcontext =
2429  "WindowAgg Aggregates",
2431 
2432  /* Only the top-level WindowAgg may have a qual */
2433  Assert(node->plan.qual == NIL || node->topWindow);
2434 
2435  /* Initialize the qual */
2436  winstate->ss.ps.qual = ExecInitQual(node->plan.qual,
2437  (PlanState *) winstate);
2438 
2439  /*
2440  * Setup the run condition, if we received one from the query planner.
2441  * When set, this may allow us to move into pass-through mode so that we
2442  * don't have to perform any further evaluation of WindowFuncs in the
2443  * current partition or possibly stop returning tuples altogether when all
2444  * tuples are in the same partition.
2445  */
2446  winstate->runcondition = ExecInitQual(node->runCondition,
2447  (PlanState *) winstate);
2448 
2449  /*
2450  * When we're not the top-level WindowAgg node or we are but have a
2451  * PARTITION BY clause we must move into one of the WINDOWAGG_PASSTHROUGH*
2452  * modes when the runCondition becomes false.
2453  */
2454  winstate->use_pass_through = !node->topWindow || node->partNumCols > 0;
2455 
2456  /* remember if we're the top-window or we are below the top-window */
2457  winstate->top_window = node->topWindow;
2458 
2459  /*
2460  * initialize child nodes
2461  */
2462  outerPlan = outerPlan(node);
2463  outerPlanState(winstate) = ExecInitNode(outerPlan, estate, eflags);
2464 
2465  /*
2466  * initialize source tuple type (which is also the tuple type that we'll
2467  * store in the tuplestore and use in all our working slots).
2468  */
2470  scanDesc = winstate->ss.ss_ScanTupleSlot->tts_tupleDescriptor;
2471 
2472  /* the outer tuple isn't the child's tuple, but always a minimal tuple */
2473  winstate->ss.ps.outeropsset = true;
2474  winstate->ss.ps.outerops = &TTSOpsMinimalTuple;
2475  winstate->ss.ps.outeropsfixed = true;
2476 
2477  /*
2478  * tuple table initialization
2479  */
2480  winstate->first_part_slot = ExecInitExtraTupleSlot(estate, scanDesc,
2482  winstate->agg_row_slot = ExecInitExtraTupleSlot(estate, scanDesc,
2484  winstate->temp_slot_1 = ExecInitExtraTupleSlot(estate, scanDesc,
2486  winstate->temp_slot_2 = ExecInitExtraTupleSlot(estate, scanDesc,
2488 
2489  /*
2490  * create frame head and tail slots only if needed (must create slots in
2491  * exactly the same cases that update_frameheadpos and update_frametailpos
2492  * need them)
2493  */
2494  winstate->framehead_slot = winstate->frametail_slot = NULL;
2495 
2496  if (frameOptions & (FRAMEOPTION_RANGE | FRAMEOPTION_GROUPS))
2497  {
2498  if (((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
2499  node->ordNumCols != 0) ||
2500  (frameOptions & FRAMEOPTION_START_OFFSET))
2501  winstate->framehead_slot = ExecInitExtraTupleSlot(estate, scanDesc,
2503  if (((frameOptions & FRAMEOPTION_END_CURRENT_ROW) &&
2504  node->ordNumCols != 0) ||
2505  (frameOptions & FRAMEOPTION_END_OFFSET))
2506  winstate->frametail_slot = ExecInitExtraTupleSlot(estate, scanDesc,
2508  }
2509 
2510  /*
2511  * Initialize result slot, type and projection.
2512  */
2514  ExecAssignProjectionInfo(&winstate->ss.ps, NULL);
2515 
2516  /* Set up data for comparing tuples */
2517  if (node->partNumCols > 0)
2518  winstate->partEqfunction =
2519  execTuplesMatchPrepare(scanDesc,
2520  node->partNumCols,
2521  node->partColIdx,
2522  node->partOperators,
2523  node->partCollations,
2524  &winstate->ss.ps);
2525 
2526  if (node->ordNumCols > 0)
2527  winstate->ordEqfunction =
2528  execTuplesMatchPrepare(scanDesc,
2529  node->ordNumCols,
2530  node->ordColIdx,
2531  node->ordOperators,
2532  node->ordCollations,
2533  &winstate->ss.ps);
2534 
2535  /*
2536  * WindowAgg nodes use aggvalues and aggnulls as well as Agg nodes.
2537  */
2538  numfuncs = winstate->numfuncs;
2539  numaggs = winstate->numaggs;
2540  econtext = winstate->ss.ps.ps_ExprContext;
2541  econtext->ecxt_aggvalues = (Datum *) palloc0(sizeof(Datum) * numfuncs);
2542  econtext->ecxt_aggnulls = (bool *) palloc0(sizeof(bool) * numfuncs);
2543 
2544  /*
2545  * allocate per-wfunc/per-agg state information.
2546  */
2547  perfunc = (WindowStatePerFunc) palloc0(sizeof(WindowStatePerFuncData) * numfuncs);
2548  peragg = (WindowStatePerAgg) palloc0(sizeof(WindowStatePerAggData) * numaggs);
2549  winstate->perfunc = perfunc;
2550  winstate->peragg = peragg;
2551 
2552  wfuncno = -1;
2553  aggno = -1;
2554  foreach(l, winstate->funcs)
2555  {
2556  WindowFuncExprState *wfuncstate = (WindowFuncExprState *) lfirst(l);
2557  WindowFunc *wfunc = wfuncstate->wfunc;
2558  WindowStatePerFunc perfuncstate;
2559  AclResult aclresult;
2560  int i;
2561 
2562  if (wfunc->winref != node->winref) /* planner screwed up? */
2563  elog(ERROR, "WindowFunc with winref %u assigned to WindowAgg with winref %u",
2564  wfunc->winref, node->winref);
2565 
2566  /* Look for a previous duplicate window function */
2567  for (i = 0; i <= wfuncno; i++)
2568  {
2569  if (equal(wfunc, perfunc[i].wfunc) &&
2570  !contain_volatile_functions((Node *) wfunc))
2571  break;
2572  }
2573  if (i <= wfuncno)
2574  {
2575  /* Found a match to an existing entry, so just mark it */
2576  wfuncstate->wfuncno = i;
2577  continue;
2578  }
2579 
2580  /* Nope, so assign a new PerAgg record */
2581  perfuncstate = &perfunc[++wfuncno];
2582 
2583  /* Mark WindowFunc state node with assigned index in the result array */
2584  wfuncstate->wfuncno = wfuncno;
2585 
2586  /* Check permission to call window function */
2587  aclresult = object_aclcheck(ProcedureRelationId, wfunc->winfnoid, GetUserId(),
2588  ACL_EXECUTE);
2589  if (aclresult != ACLCHECK_OK)
2590  aclcheck_error(aclresult, OBJECT_FUNCTION,
2591  get_func_name(wfunc->winfnoid));
2592  InvokeFunctionExecuteHook(wfunc->winfnoid);
2593 
2594  /* Fill in the perfuncstate data */
2595  perfuncstate->wfuncstate = wfuncstate;
2596  perfuncstate->wfunc = wfunc;
2597  perfuncstate->numArguments = list_length(wfuncstate->args);
2598  perfuncstate->winCollation = wfunc->inputcollid;
2599 
2600  get_typlenbyval(wfunc->wintype,
2601  &perfuncstate->resulttypeLen,
2602  &perfuncstate->resulttypeByVal);
2603 
2604  /*
2605  * If it's really just a plain aggregate function, we'll emulate the
2606  * Agg environment for it.
2607  */
2608  perfuncstate->plain_agg = wfunc->winagg;
2609  if (wfunc->winagg)
2610  {
2611  WindowStatePerAgg peraggstate;
2612 
2613  perfuncstate->aggno = ++aggno;
2614  peraggstate = &winstate->peragg[aggno];
2615  initialize_peragg(winstate, wfunc, peraggstate);
2616  peraggstate->wfuncno = wfuncno;
2617  }
2618  else
2619  {
2621 
2622  winobj->winstate = winstate;
2623  winobj->argstates = wfuncstate->args;
2624  winobj->localmem = NULL;
2625  perfuncstate->winobj = winobj;
2626 
2627  /* It's a real window function, so set up to call it. */
2628  fmgr_info_cxt(wfunc->winfnoid, &perfuncstate->flinfo,
2629  econtext->ecxt_per_query_memory);
2630  fmgr_info_set_expr((Node *) wfunc, &perfuncstate->flinfo);
2631  }
2632  }
2633 
2634  /* Update numfuncs, numaggs to match number of unique functions found */
2635  winstate->numfuncs = wfuncno + 1;
2636  winstate->numaggs = aggno + 1;
2637 
2638  /* Set up WindowObject for aggregates, if needed */
2639  if (winstate->numaggs > 0)
2640  {
2641  WindowObject agg_winobj = makeNode(WindowObjectData);
2642 
2643  agg_winobj->winstate = winstate;
2644  agg_winobj->argstates = NIL;
2645  agg_winobj->localmem = NULL;
2646  /* make sure markptr = -1 to invalidate. It may not get used */
2647  agg_winobj->markptr = -1;
2648  agg_winobj->readptr = -1;
2649  winstate->agg_winobj = agg_winobj;
2650  }
2651 
2652  /* Set the status to running */
2653  winstate->status = WINDOWAGG_RUN;
2654 
2655  /* initialize frame bound offset expressions */
2656  winstate->startOffset = ExecInitExpr((Expr *) node->startOffset,
2657  (PlanState *) winstate);
2658  winstate->endOffset = ExecInitExpr((Expr *) node->endOffset,
2659  (PlanState *) winstate);
2660 
2661  /* Lookup in_range support functions if needed */
2662  if (OidIsValid(node->startInRangeFunc))
2663  fmgr_info(node->startInRangeFunc, &winstate->startInRangeFunc);
2664  if (OidIsValid(node->endInRangeFunc))
2665  fmgr_info(node->endInRangeFunc, &winstate->endInRangeFunc);
2666  winstate->inRangeColl = node->inRangeColl;
2667  winstate->inRangeAsc = node->inRangeAsc;
2668  winstate->inRangeNullsFirst = node->inRangeNullsFirst;
2669 
2670  winstate->all_first = true;
2671  winstate->partition_spooled = false;
2672  winstate->more_partitions = false;
2673 
2674  return winstate;
2675 }
AclResult
Definition: acl.h:182
@ ACLCHECK_OK
Definition: acl.h:183
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:2702
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
Definition: aclchk.c:3890
#define Assert(condition)
Definition: c.h:858
#define OidIsValid(objectId)
Definition: c.h:775
bool contain_volatile_functions(Node *clause)
Definition: clauses.c:538
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:224
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:223
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:220
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
Definition: execExpr.c:134
ExprState * execTuplesMatchPrepare(TupleDesc desc, int numCols, const AttrNumber *keyColIdx, const Oid *eqOperators, const Oid *collations, PlanState *parent)
Definition: execGrouping.c:58
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:142
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:84
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1918
void ExecInitResultTupleSlotTL(PlanState *planstate, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1886
const TupleTableSlotOps TTSOpsMinimalTuple
Definition: execTuples.c:86
void ExecCreateScanSlotFromOuterPlan(EState *estate, ScanState *scanstate, const TupleTableSlotOps *tts_ops)
Definition: execUtils.c:659
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:483
void ExecAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc)
Definition: execUtils.c:538
struct WindowStatePerAggData * WindowStatePerAgg
Definition: execnodes.h:2543
@ WINDOWAGG_RUN
Definition: execnodes.h:2551
struct WindowStatePerFuncData * WindowStatePerFunc
Definition: execnodes.h:2542
#define EXEC_FLAG_BACKWARD
Definition: executor.h:68
#define EXEC_FLAG_MARK
Definition: executor.h:69
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:127
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
Definition: fmgr.c:137
#define fmgr_info_set_expr(expr, finfo)
Definition: fmgr.h:135
void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval)
Definition: lsyscache.c:2251
char * get_func_name(Oid funcid)
Definition: lsyscache.c:1608
void * palloc0(Size size)
Definition: mcxt.c:1346
MemoryContext CurrentMemoryContext
Definition: mcxt.c:143
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:160
Oid GetUserId(void)
Definition: miscinit.c:514
static WindowStatePerAggData * initialize_peragg(WindowAggState *winstate, WindowFunc *wfunc, WindowStatePerAgg peraggstate)
static TupleTableSlot * ExecWindowAgg(PlanState *pstate)
#define makeNode(_type_)
Definition: nodes.h:155
#define InvokeFunctionExecuteHook(objectId)
Definition: objectaccess.h:213
#define FRAMEOPTION_END_CURRENT_ROW
Definition: parsenodes.h:591
#define FRAMEOPTION_END_OFFSET
Definition: parsenodes.h:602
#define FRAMEOPTION_START_CURRENT_ROW
Definition: parsenodes.h:590
#define FRAMEOPTION_START_OFFSET
Definition: parsenodes.h:600
@ OBJECT_FUNCTION
Definition: parsenodes.h:2280
#define FRAMEOPTION_RANGE
Definition: parsenodes.h:582
#define FRAMEOPTION_GROUPS
Definition: parsenodes.h:584
#define ACL_EXECUTE
Definition: parsenodes.h:83
#define lfirst(lc)
Definition: pg_list.h:172
static int list_length(const List *l)
Definition: pg_list.h:152
#define NIL
Definition: pg_list.h:68
uintptr_t Datum
Definition: postgres.h:64
Datum * ecxt_aggvalues
Definition: execnodes.h:274
bool * ecxt_aggnulls
Definition: execnodes.h:276
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:262
Definition: nodes.h:129
bool outeropsset
Definition: execnodes.h:1200
const TupleTableSlotOps * outerops
Definition: execnodes.h:1192
ExprState * qual
Definition: execnodes.h:1138
Plan * plan
Definition: execnodes.h:1117
bool outeropsfixed
Definition: execnodes.h:1196
EState * state
Definition: execnodes.h:1119
ExprContext * ps_ExprContext
Definition: execnodes.h:1156
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1123
List * qual
Definition: plannodes.h:153
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1567
PlanState ps
Definition: execnodes.h:1564
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:123
ExprState * endOffset
Definition: execnodes.h:2587
ScanState ss
Definition: execnodes.h:2559
FmgrInfo endInRangeFunc
Definition: execnodes.h:2593
TupleTableSlot * framehead_slot
Definition: execnodes.h:2634
bool partition_spooled
Definition: execnodes.h:2621
FmgrInfo startInRangeFunc
Definition: execnodes.h:2592
bool more_partitions
Definition: execnodes.h:2623
TupleTableSlot * frametail_slot
Definition: execnodes.h:2635
ExprState * ordEqfunction
Definition: execnodes.h:2569
ExprState * runcondition
Definition: execnodes.h:2610
TupleTableSlot * temp_slot_2
Definition: execnodes.h:2640
WindowAggStatus status
Definition: execnodes.h:2583
TupleTableSlot * agg_row_slot
Definition: execnodes.h:2638
struct WindowObjectData * agg_winobj
Definition: execnodes.h:2580
bool inRangeNullsFirst
Definition: execnodes.h:2596
ExprState * partEqfunction
Definition: execnodes.h:2568
ExprState * startOffset
Definition: execnodes.h:2586
TupleTableSlot * first_part_slot
Definition: execnodes.h:2632
ExprContext * tmpcontext
Definition: execnodes.h:2608
TupleTableSlot * temp_slot_1
Definition: execnodes.h:2639
bool use_pass_through
Definition: execnodes.h:2615
int partNumCols
Definition: plannodes.h:1046
Oid endInRangeFunc
Definition: plannodes.h:1090
Node * endOffset
Definition: plannodes.h:1076
bool topWindow
Definition: plannodes.h:1105
Plan plan
Definition: plannodes.h:1040
Oid inRangeColl
Definition: plannodes.h:1093
Node * startOffset
Definition: plannodes.h:1073
List * runCondition
Definition: plannodes.h:1079
Oid startInRangeFunc
Definition: plannodes.h:1087
bool inRangeAsc
Definition: plannodes.h:1096
Index winref
Definition: plannodes.h:1043
bool inRangeNullsFirst
Definition: plannodes.h:1099
int ordNumCols
Definition: plannodes.h:1058
int frameOptions
Definition: plannodes.h:1070
WindowFunc * wfunc
Definition: execnodes.h:871
Index winref
Definition: primnodes.h:581
WindowAggState * winstate
Definition: nodeWindowAgg.c:65
WindowFuncExprState * wfuncstate
Definition: nodeWindowAgg.c:81

References ACL_EXECUTE, aclcheck_error(), ACLCHECK_OK, WindowAggState::agg_row_slot, WindowAggState::agg_winobj, WindowAggState::aggcontext, WindowStatePerFuncData::aggno, WindowAggState::all_first, 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, WindowAggState::endInRangeFunc, WindowAgg::endInRangeFunc, WindowAggState::endOffset, WindowAgg::endOffset, equal(), ERROR, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecAssignExprContext(), ExecAssignProjectionInfo(), ExecCreateScanSlotFromOuterPlan(), ExecInitExpr(), ExecInitExtraTupleSlot(), ExecInitNode(), ExecInitQual(), 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_CURRENT_ROW, FRAMEOPTION_END_OFFSET, FRAMEOPTION_GROUPS, FRAMEOPTION_RANGE, FRAMEOPTION_START_CURRENT_ROW, FRAMEOPTION_START_OFFSET, WindowAggState::frameOptions, WindowAgg::frameOptions, WindowAggState::frametail_slot, WindowAggState::funcs, get_func_name(), get_typlenbyval(), GetUserId(), i, initialize_peragg(), WindowAggState::inRangeAsc, WindowAgg::inRangeAsc, WindowAggState::inRangeColl, WindowAgg::inRangeColl, WindowAggState::inRangeNullsFirst, WindowAgg::inRangeNullsFirst, InvokeFunctionExecuteHook, lfirst, list_length(), WindowObjectData::localmem, makeNode, WindowObjectData::markptr, WindowAggState::more_partitions, NIL, WindowAggState::numaggs, WindowStatePerFuncData::numArguments, WindowAggState::numfuncs, object_aclcheck(), OBJECT_FUNCTION, OidIsValid, WindowAggState::ordEqfunction, WindowAgg::ordNumCols, PlanState::outerops, PlanState::outeropsfixed, PlanState::outeropsset, outerPlan, outerPlanState, palloc0(), WindowAggState::partcontext, WindowAggState::partEqfunction, WindowAggState::partition_spooled, WindowAgg::partNumCols, WindowAggState::peragg, WindowAggState::perfunc, WindowStatePerFuncData::plain_agg, PlanState::plan, WindowAgg::plan, ScanState::ps, PlanState::ps_ExprContext, PlanState::qual, Plan::qual, WindowObjectData::readptr, WindowStatePerFuncData::resulttypeByVal, WindowStatePerFuncData::resulttypeLen, WindowAggState::runcondition, WindowAgg::runCondition, WindowAggState::ss, ScanState::ss_ScanTupleSlot, WindowAggState::startInRangeFunc, WindowAgg::startInRangeFunc, WindowAggState::startOffset, WindowAgg::startOffset, PlanState::state, WindowAggState::status, WindowAggState::temp_slot_1, WindowAggState::temp_slot_2, WindowAggState::tmpcontext, WindowAggState::top_window, WindowAgg::topWindow, TupleTableSlot::tts_tupleDescriptor, TTSOpsMinimalTuple, TTSOpsVirtual, WindowAggState::use_pass_through, WindowStatePerFuncData::wfunc, WindowFuncExprState::wfunc, WindowStatePerAggData::wfuncno, WindowFuncExprState::wfuncno, WindowStatePerFuncData::wfuncstate, WindowStatePerFuncData::winCollation, WINDOWAGG_RUN, WindowFunc::winfnoid, WindowStatePerFuncData::winobj, WindowAgg::winref, WindowFunc::winref, and WindowObjectData::winstate.

Referenced by ExecInitNode().

◆ ExecReScanWindowAgg()

void ExecReScanWindowAgg ( WindowAggState node)

Definition at line 2709 of file nodeWindowAgg.c.

2710 {
2712  ExprContext *econtext = node->ss.ps.ps_ExprContext;
2713 
2714  node->status = WINDOWAGG_RUN;
2715  node->all_first = true;
2716 
2717  /* release tuplestore et al */
2718  release_partition(node);
2719 
2720  /* release all temp tuples, but especially first_part_slot */
2724  ExecClearTuple(node->temp_slot_1);
2725  ExecClearTuple(node->temp_slot_2);
2726  if (node->framehead_slot)
2728  if (node->frametail_slot)
2730 
2731  /* Forget current wfunc values */
2732  MemSet(econtext->ecxt_aggvalues, 0, sizeof(Datum) * node->numfuncs);
2733  MemSet(econtext->ecxt_aggnulls, 0, sizeof(bool) * node->numfuncs);
2734 
2735  /*
2736  * if chgParam of subnode is not null then plan will be re-scanned by
2737  * first ExecProcNode.
2738  */
2739  if (outerPlan->chgParam == NULL)
2741 }
#define MemSet(start, val, len)
Definition: c.h:1020
void ExecReScan(PlanState *node)
Definition: execAmi.c:76
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:454

References WindowAggState::agg_row_slot, WindowAggState::all_first, 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::status, WindowAggState::temp_slot_1, WindowAggState::temp_slot_2, and WINDOWAGG_RUN.

Referenced by ExecReScan().