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 
2692  ExecClearTuple(node->temp_slot_1);
2693  ExecClearTuple(node->temp_slot_2);
2694  if (node->framehead_slot)
2696  if (node->frametail_slot)
2698 
2699  /*
2700  * Free both the expr contexts.
2701  */
2702  ExecFreeExprContext(&node->ss.ps);
2703  node->ss.ps.ps_ExprContext = node->tmpcontext;
2704  ExecFreeExprContext(&node->ss.ps);
2705 
2706  for (i = 0; i < node->numaggs; i++)
2707  {
2708  if (node->peragg[i].aggcontext != node->aggcontext)
2710  }
2713 
2714  pfree(node->perfunc);
2715  pfree(node->peragg);
2716 
2717  outerPlan = outerPlanState(node);
2719 }
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:557
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:658
#define outerPlanState(node)
Definition: execnodes.h:1133
int i
Definition: isn.c:73
void pfree(void *pointer)
Definition: mcxt.c:1456
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:403
static void release_partition(WindowAggState *winstate)
#define outerPlan(node)
Definition: plannodes.h:183
ExprContext * ps_ExprContext
Definition: execnodes.h:1076
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1477
PlanState ps
Definition: execnodes.h:1474
MemoryContext aggcontext
Definition: execnodes.h:2523
ScanState ss
Definition: execnodes.h:2476
WindowStatePerAgg peragg
Definition: execnodes.h:2484
MemoryContext partcontext
Definition: execnodes.h:2522
TupleTableSlot * framehead_slot
Definition: execnodes.h:2551
TupleTableSlot * frametail_slot
Definition: execnodes.h:2552
TupleTableSlot * temp_slot_2
Definition: execnodes.h:2557
TupleTableSlot * agg_row_slot
Definition: execnodes.h:2555
WindowStatePerFunc perfunc
Definition: execnodes.h:2483
TupleTableSlot * first_part_slot
Definition: execnodes.h:2549
ExprContext * tmpcontext
Definition: execnodes.h:2525
TupleTableSlot * temp_slot_1
Definition: execnodes.h:2556
MemoryContext aggcontext
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:433

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().

◆ 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  /*
2403  * Create expression contexts. We need two, one for per-input-tuple
2404  * processing and one for per-output-tuple processing. We cheat a little
2405  * by using ExecAssignExprContext() to build both.
2406  */
2407  ExecAssignExprContext(estate, &winstate->ss.ps);
2408  tmpcontext = winstate->ss.ps.ps_ExprContext;
2409  winstate->tmpcontext = tmpcontext;
2410  ExecAssignExprContext(estate, &winstate->ss.ps);
2411 
2412  /* Create long-lived context for storage of partition-local memory etc */
2413  winstate->partcontext =
2415  "WindowAgg Partition",
2417 
2418  /*
2419  * Create mid-lived context for aggregate trans values etc.
2420  *
2421  * Note that moving aggregates each use their own private context, not
2422  * this one.
2423  */
2424  winstate->aggcontext =
2426  "WindowAgg Aggregates",
2428 
2429  /* Only the top-level WindowAgg may have a qual */
2430  Assert(node->plan.qual == NIL || node->topWindow);
2431 
2432  /* Initialize the qual */
2433  winstate->ss.ps.qual = ExecInitQual(node->plan.qual,
2434  (PlanState *) winstate);
2435 
2436  /*
2437  * Setup the run condition, if we received one from the query planner.
2438  * When set, this may allow us to move into pass-through mode so that we
2439  * don't have to perform any further evaluation of WindowFuncs in the
2440  * current partition or possibly stop returning tuples altogether when all
2441  * tuples are in the same partition.
2442  */
2443  winstate->runcondition = ExecInitQual(node->runCondition,
2444  (PlanState *) winstate);
2445 
2446  /*
2447  * When we're not the top-level WindowAgg node or we are but have a
2448  * PARTITION BY clause we must move into one of the WINDOWAGG_PASSTHROUGH*
2449  * modes when the runCondition becomes false.
2450  */
2451  winstate->use_pass_through = !node->topWindow || node->partNumCols > 0;
2452 
2453  /* remember if we're the top-window or we are below the top-window */
2454  winstate->top_window = node->topWindow;
2455 
2456  /*
2457  * initialize child nodes
2458  */
2459  outerPlan = outerPlan(node);
2460  outerPlanState(winstate) = ExecInitNode(outerPlan, estate, eflags);
2461 
2462  /*
2463  * initialize source tuple type (which is also the tuple type that we'll
2464  * store in the tuplestore and use in all our working slots).
2465  */
2467  scanDesc = winstate->ss.ss_ScanTupleSlot->tts_tupleDescriptor;
2468 
2469  /* the outer tuple isn't the child's tuple, but always a minimal tuple */
2470  winstate->ss.ps.outeropsset = true;
2471  winstate->ss.ps.outerops = &TTSOpsMinimalTuple;
2472  winstate->ss.ps.outeropsfixed = true;
2473 
2474  /*
2475  * tuple table initialization
2476  */
2477  winstate->first_part_slot = ExecInitExtraTupleSlot(estate, scanDesc,
2479  winstate->agg_row_slot = ExecInitExtraTupleSlot(estate, scanDesc,
2481  winstate->temp_slot_1 = ExecInitExtraTupleSlot(estate, scanDesc,
2483  winstate->temp_slot_2 = ExecInitExtraTupleSlot(estate, scanDesc,
2485 
2486  /*
2487  * create frame head and tail slots only if needed (must create slots in
2488  * exactly the same cases that update_frameheadpos and update_frametailpos
2489  * need them)
2490  */
2491  winstate->framehead_slot = winstate->frametail_slot = NULL;
2492 
2493  if (frameOptions & (FRAMEOPTION_RANGE | FRAMEOPTION_GROUPS))
2494  {
2495  if (((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
2496  node->ordNumCols != 0) ||
2497  (frameOptions & FRAMEOPTION_START_OFFSET))
2498  winstate->framehead_slot = ExecInitExtraTupleSlot(estate, scanDesc,
2500  if (((frameOptions & FRAMEOPTION_END_CURRENT_ROW) &&
2501  node->ordNumCols != 0) ||
2502  (frameOptions & FRAMEOPTION_END_OFFSET))
2503  winstate->frametail_slot = ExecInitExtraTupleSlot(estate, scanDesc,
2505  }
2506 
2507  /*
2508  * Initialize result slot, type and projection.
2509  */
2511  ExecAssignProjectionInfo(&winstate->ss.ps, NULL);
2512 
2513  /* Set up data for comparing tuples */
2514  if (node->partNumCols > 0)
2515  winstate->partEqfunction =
2516  execTuplesMatchPrepare(scanDesc,
2517  node->partNumCols,
2518  node->partColIdx,
2519  node->partOperators,
2520  node->partCollations,
2521  &winstate->ss.ps);
2522 
2523  if (node->ordNumCols > 0)
2524  winstate->ordEqfunction =
2525  execTuplesMatchPrepare(scanDesc,
2526  node->ordNumCols,
2527  node->ordColIdx,
2528  node->ordOperators,
2529  node->ordCollations,
2530  &winstate->ss.ps);
2531 
2532  /*
2533  * WindowAgg nodes use aggvalues and aggnulls as well as Agg nodes.
2534  */
2535  numfuncs = winstate->numfuncs;
2536  numaggs = winstate->numaggs;
2537  econtext = winstate->ss.ps.ps_ExprContext;
2538  econtext->ecxt_aggvalues = (Datum *) palloc0(sizeof(Datum) * numfuncs);
2539  econtext->ecxt_aggnulls = (bool *) palloc0(sizeof(bool) * numfuncs);
2540 
2541  /*
2542  * allocate per-wfunc/per-agg state information.
2543  */
2544  perfunc = (WindowStatePerFunc) palloc0(sizeof(WindowStatePerFuncData) * numfuncs);
2545  peragg = (WindowStatePerAgg) palloc0(sizeof(WindowStatePerAggData) * numaggs);
2546  winstate->perfunc = perfunc;
2547  winstate->peragg = peragg;
2548 
2549  wfuncno = -1;
2550  aggno = -1;
2551  foreach(l, winstate->funcs)
2552  {
2553  WindowFuncExprState *wfuncstate = (WindowFuncExprState *) lfirst(l);
2554  WindowFunc *wfunc = wfuncstate->wfunc;
2555  WindowStatePerFunc perfuncstate;
2556  AclResult aclresult;
2557  int i;
2558 
2559  if (wfunc->winref != node->winref) /* planner screwed up? */
2560  elog(ERROR, "WindowFunc with winref %u assigned to WindowAgg with winref %u",
2561  wfunc->winref, node->winref);
2562 
2563  /* Look for a previous duplicate window function */
2564  for (i = 0; i <= wfuncno; i++)
2565  {
2566  if (equal(wfunc, perfunc[i].wfunc) &&
2567  !contain_volatile_functions((Node *) wfunc))
2568  break;
2569  }
2570  if (i <= wfuncno)
2571  {
2572  /* Found a match to an existing entry, so just mark it */
2573  wfuncstate->wfuncno = i;
2574  continue;
2575  }
2576 
2577  /* Nope, so assign a new PerAgg record */
2578  perfuncstate = &perfunc[++wfuncno];
2579 
2580  /* Mark WindowFunc state node with assigned index in the result array */
2581  wfuncstate->wfuncno = wfuncno;
2582 
2583  /* Check permission to call window function */
2584  aclresult = object_aclcheck(ProcedureRelationId, wfunc->winfnoid, GetUserId(),
2585  ACL_EXECUTE);
2586  if (aclresult != ACLCHECK_OK)
2587  aclcheck_error(aclresult, OBJECT_FUNCTION,
2588  get_func_name(wfunc->winfnoid));
2589  InvokeFunctionExecuteHook(wfunc->winfnoid);
2590 
2591  /* Fill in the perfuncstate data */
2592  perfuncstate->wfuncstate = wfuncstate;
2593  perfuncstate->wfunc = wfunc;
2594  perfuncstate->numArguments = list_length(wfuncstate->args);
2595  perfuncstate->winCollation = wfunc->inputcollid;
2596 
2597  get_typlenbyval(wfunc->wintype,
2598  &perfuncstate->resulttypeLen,
2599  &perfuncstate->resulttypeByVal);
2600 
2601  /*
2602  * If it's really just a plain aggregate function, we'll emulate the
2603  * Agg environment for it.
2604  */
2605  perfuncstate->plain_agg = wfunc->winagg;
2606  if (wfunc->winagg)
2607  {
2608  WindowStatePerAgg peraggstate;
2609 
2610  perfuncstate->aggno = ++aggno;
2611  peraggstate = &winstate->peragg[aggno];
2612  initialize_peragg(winstate, wfunc, peraggstate);
2613  peraggstate->wfuncno = wfuncno;
2614  }
2615  else
2616  {
2618 
2619  winobj->winstate = winstate;
2620  winobj->argstates = wfuncstate->args;
2621  winobj->localmem = NULL;
2622  perfuncstate->winobj = winobj;
2623 
2624  /* It's a real window function, so set up to call it. */
2625  fmgr_info_cxt(wfunc->winfnoid, &perfuncstate->flinfo,
2626  econtext->ecxt_per_query_memory);
2627  fmgr_info_set_expr((Node *) wfunc, &perfuncstate->flinfo);
2628  }
2629  }
2630 
2631  /* Update numfuncs, numaggs to match number of unique functions found */
2632  winstate->numfuncs = wfuncno + 1;
2633  winstate->numaggs = aggno + 1;
2634 
2635  /* Set up WindowObject for aggregates, if needed */
2636  if (winstate->numaggs > 0)
2637  {
2638  WindowObject agg_winobj = makeNode(WindowObjectData);
2639 
2640  agg_winobj->winstate = winstate;
2641  agg_winobj->argstates = NIL;
2642  agg_winobj->localmem = NULL;
2643  /* make sure markptr = -1 to invalidate. It may not get used */
2644  agg_winobj->markptr = -1;
2645  agg_winobj->readptr = -1;
2646  winstate->agg_winobj = agg_winobj;
2647  }
2648 
2649  /* Set the status to running */
2650  winstate->status = WINDOWAGG_RUN;
2651 
2652  /* copy frame options to state node for easy access */
2653  winstate->frameOptions = frameOptions;
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:2673
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
Definition: aclchk.c:3775
#define OidIsValid(objectId)
Definition: c.h:759
bool contain_volatile_functions(Node *clause)
Definition: clauses.c:483
#define ERROR
Definition: elog.h:39
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:223
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:213
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
Definition: execExpr.c:127
ExprState * execTuplesMatchPrepare(TupleDesc desc, int numCols, const AttrNumber *keyColIdx, const Oid *eqOperators, const Oid *collations, PlanState *parent)
Definition: execGrouping.c:59
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:142
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:83
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1832
void ExecInitResultTupleSlotTL(PlanState *planstate, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1800
const TupleTableSlotOps TTSOpsMinimalTuple
Definition: execTuples.c:85
void ExecCreateScanSlotFromOuterPlan(EState *estate, ScanState *scanstate, const TupleTableSlotOps *tts_ops)
Definition: execUtils.c:690
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:488
void ExecAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc)
Definition: execUtils.c:543
struct WindowStatePerAggData * WindowStatePerAgg
Definition: execnodes.h:2460
@ WINDOWAGG_RUN
Definition: execnodes.h:2468
struct WindowStatePerFuncData * WindowStatePerFunc
Definition: execnodes.h:2459
#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
Assert(fmt[strlen(fmt) - 1] !='\n')
void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval)
Definition: lsyscache.c:2209
char * get_func_name(Oid funcid)
Definition: lsyscache.c:1590
void * palloc0(Size size)
Definition: mcxt.c:1257
MemoryContext CurrentMemoryContext
Definition: mcxt.c:135
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:153
Oid GetUserId(void)
Definition: miscinit.c:510
static WindowStatePerAggData * initialize_peragg(WindowAggState *winstate, WindowFunc *wfunc, WindowStatePerAgg peraggstate)
static TupleTableSlot * ExecWindowAgg(PlanState *pstate)
#define makeNode(_type_)
Definition: nodes.h:176
#define InvokeFunctionExecuteHook(objectId)
Definition: objectaccess.h:213
#define FRAMEOPTION_END_CURRENT_ROW
Definition: parsenodes.h:589
#define FRAMEOPTION_END_OFFSET
Definition: parsenodes.h:600
#define FRAMEOPTION_START_CURRENT_ROW
Definition: parsenodes.h:588
#define FRAMEOPTION_START_OFFSET
Definition: parsenodes.h:598
@ OBJECT_FUNCTION
Definition: parsenodes.h:2101
#define FRAMEOPTION_RANGE
Definition: parsenodes.h:580
#define FRAMEOPTION_GROUPS
Definition: parsenodes.h:582
#define ACL_EXECUTE
Definition: parsenodes.h:90
#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:268
bool * ecxt_aggnulls
Definition: execnodes.h:270
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:256
Definition: nodes.h:129
bool outeropsset
Definition: execnodes.h:1120
const TupleTableSlotOps * outerops
Definition: execnodes.h:1112
ExprState * qual
Definition: execnodes.h:1058
Plan * plan
Definition: execnodes.h:1037
bool outeropsfixed
Definition: execnodes.h:1116
EState * state
Definition: execnodes.h:1039
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1043
List * qual
Definition: plannodes.h:154
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
ExprState * endOffset
Definition: execnodes.h:2504
FmgrInfo endInRangeFunc
Definition: execnodes.h:2510
bool partition_spooled
Definition: execnodes.h:2538
FmgrInfo startInRangeFunc
Definition: execnodes.h:2509
bool more_partitions
Definition: execnodes.h:2540
ExprState * ordEqfunction
Definition: execnodes.h:2486
ExprState * runcondition
Definition: execnodes.h:2527
WindowAggStatus status
Definition: execnodes.h:2500
struct WindowObjectData * agg_winobj
Definition: execnodes.h:2497
bool inRangeNullsFirst
Definition: execnodes.h:2513
ExprState * partEqfunction
Definition: execnodes.h:2485
ExprState * startOffset
Definition: execnodes.h:2503
bool use_pass_through
Definition: execnodes.h:2532
int partNumCols
Definition: plannodes.h:1044
Oid endInRangeFunc
Definition: plannodes.h:1088
Node * endOffset
Definition: plannodes.h:1074
bool topWindow
Definition: plannodes.h:1103
Plan plan
Definition: plannodes.h:1038
Oid inRangeColl
Definition: plannodes.h:1091
Node * startOffset
Definition: plannodes.h:1071
List * runCondition
Definition: plannodes.h:1077
Oid startInRangeFunc
Definition: plannodes.h:1085
bool inRangeAsc
Definition: plannodes.h:1094
Index winref
Definition: plannodes.h:1041
bool inRangeNullsFirst
Definition: plannodes.h:1097
int ordNumCols
Definition: plannodes.h:1056
int frameOptions
Definition: plannodes.h:1068
WindowFunc * wfunc
Definition: execnodes.h:863
Index winref
Definition: primnodes.h:557
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 2726 of file nodeWindowAgg.c.

2727 {
2729  ExprContext *econtext = node->ss.ps.ps_ExprContext;
2730 
2731  node->status = WINDOWAGG_RUN;
2732  node->all_first = true;
2733 
2734  /* release tuplestore et al */
2735  release_partition(node);
2736 
2737  /* release all temp tuples, but especially first_part_slot */
2741  ExecClearTuple(node->temp_slot_1);
2742  ExecClearTuple(node->temp_slot_2);
2743  if (node->framehead_slot)
2745  if (node->frametail_slot)
2747 
2748  /* Forget current wfunc values */
2749  MemSet(econtext->ecxt_aggvalues, 0, sizeof(Datum) * node->numfuncs);
2750  MemSet(econtext->ecxt_aggnulls, 0, sizeof(bool) * node->numfuncs);
2751 
2752  /*
2753  * if chgParam of subnode is not null then plan will be re-scanned by
2754  * first ExecProcNode.
2755  */
2756  if (outerPlan->chgParam == NULL)
2758 }
#define MemSet(start, val, len)
Definition: c.h:1004
void ExecReScan(PlanState *node)
Definition: execAmi.c:78

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().