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

2655 {
2657  int i;
2658 
2659  release_partition(node);
2660 
2664  ExecClearTuple(node->temp_slot_1);
2665  ExecClearTuple(node->temp_slot_2);
2666  if (node->framehead_slot)
2668  if (node->frametail_slot)
2670 
2671  /*
2672  * Free both the expr contexts.
2673  */
2674  ExecFreeExprContext(&node->ss.ps);
2675  node->ss.ps.ps_ExprContext = node->tmpcontext;
2676  ExecFreeExprContext(&node->ss.ps);
2677 
2678  for (i = 0; i < node->numaggs; i++)
2679  {
2680  if (node->peragg[i].aggcontext != node->aggcontext)
2682  }
2685 
2686  pfree(node->perfunc);
2687  pfree(node->peragg);
2688 
2689  outerPlan = outerPlanState(node);
2691 }
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:557
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:651
#define outerPlanState(node)
Definition: execnodes.h:1120
int i
Definition: isn.c:73
void pfree(void *pointer)
Definition: mcxt.c:1306
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:376
static void release_partition(WindowAggState *winstate)
#define outerPlan(node)
Definition: plannodes.h:180
ExprContext * ps_ExprContext
Definition: execnodes.h:1063
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1452
PlanState ps
Definition: execnodes.h:1449
MemoryContext aggcontext
Definition: execnodes.h:2497
ScanState ss
Definition: execnodes.h:2450
WindowStatePerAgg peragg
Definition: execnodes.h:2458
MemoryContext partcontext
Definition: execnodes.h:2496
TupleTableSlot * framehead_slot
Definition: execnodes.h:2525
TupleTableSlot * frametail_slot
Definition: execnodes.h:2526
TupleTableSlot * temp_slot_2
Definition: execnodes.h:2531
TupleTableSlot * agg_row_slot
Definition: execnodes.h:2529
WindowStatePerFunc perfunc
Definition: execnodes.h:2457
TupleTableSlot * first_part_slot
Definition: execnodes.h:2523
ExprContext * tmpcontext
Definition: execnodes.h:2499
TupleTableSlot * temp_slot_1
Definition: execnodes.h:2530
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 2347 of file nodeWindowAgg.c.

2348 {
2349  WindowAggState *winstate;
2350  Plan *outerPlan;
2351  ExprContext *econtext;
2352  ExprContext *tmpcontext;
2353  WindowStatePerFunc perfunc;
2354  WindowStatePerAgg peragg;
2355  int frameOptions = node->frameOptions;
2356  int numfuncs,
2357  wfuncno,
2358  numaggs,
2359  aggno;
2360  TupleDesc scanDesc;
2361  ListCell *l;
2362 
2363  /* check for unsupported flags */
2364  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
2365 
2366  /*
2367  * create state structure
2368  */
2369  winstate = makeNode(WindowAggState);
2370  winstate->ss.ps.plan = (Plan *) node;
2371  winstate->ss.ps.state = estate;
2372  winstate->ss.ps.ExecProcNode = ExecWindowAgg;
2373 
2374  /*
2375  * Create expression contexts. We need two, one for per-input-tuple
2376  * processing and one for per-output-tuple processing. We cheat a little
2377  * by using ExecAssignExprContext() to build both.
2378  */
2379  ExecAssignExprContext(estate, &winstate->ss.ps);
2380  tmpcontext = winstate->ss.ps.ps_ExprContext;
2381  winstate->tmpcontext = tmpcontext;
2382  ExecAssignExprContext(estate, &winstate->ss.ps);
2383 
2384  /* Create long-lived context for storage of partition-local memory etc */
2385  winstate->partcontext =
2387  "WindowAgg Partition",
2389 
2390  /*
2391  * Create mid-lived context for aggregate trans values etc.
2392  *
2393  * Note that moving aggregates each use their own private context, not
2394  * this one.
2395  */
2396  winstate->aggcontext =
2398  "WindowAgg Aggregates",
2400 
2401  /* Only the top-level WindowAgg may have a qual */
2402  Assert(node->plan.qual == NIL || node->topWindow);
2403 
2404  /* Initialize the qual */
2405  winstate->ss.ps.qual = ExecInitQual(node->plan.qual,
2406  (PlanState *) winstate);
2407 
2408  /*
2409  * Setup the run condition, if we received one from the query planner.
2410  * When set, this may allow us to move into pass-through mode so that we
2411  * don't have to perform any further evaluation of WindowFuncs in the
2412  * current partition or possibly stop returning tuples altogether when all
2413  * tuples are in the same partition.
2414  */
2415  winstate->runcondition = ExecInitQual(node->runCondition,
2416  (PlanState *) winstate);
2417 
2418  /*
2419  * When we're not the top-level WindowAgg node or we are but have a
2420  * PARTITION BY clause we must move into one of the WINDOWAGG_PASSTHROUGH*
2421  * modes when the runCondition becomes false.
2422  */
2423  winstate->use_pass_through = !node->topWindow || node->partNumCols > 0;
2424 
2425  /* remember if we're the top-window or we are below the top-window */
2426  winstate->top_window = node->topWindow;
2427 
2428  /*
2429  * initialize child nodes
2430  */
2431  outerPlan = outerPlan(node);
2432  outerPlanState(winstate) = ExecInitNode(outerPlan, estate, eflags);
2433 
2434  /*
2435  * initialize source tuple type (which is also the tuple type that we'll
2436  * store in the tuplestore and use in all our working slots).
2437  */
2439  scanDesc = winstate->ss.ss_ScanTupleSlot->tts_tupleDescriptor;
2440 
2441  /* the outer tuple isn't the child's tuple, but always a minimal tuple */
2442  winstate->ss.ps.outeropsset = true;
2443  winstate->ss.ps.outerops = &TTSOpsMinimalTuple;
2444  winstate->ss.ps.outeropsfixed = true;
2445 
2446  /*
2447  * tuple table initialization
2448  */
2449  winstate->first_part_slot = ExecInitExtraTupleSlot(estate, scanDesc,
2451  winstate->agg_row_slot = ExecInitExtraTupleSlot(estate, scanDesc,
2453  winstate->temp_slot_1 = ExecInitExtraTupleSlot(estate, scanDesc,
2455  winstate->temp_slot_2 = ExecInitExtraTupleSlot(estate, scanDesc,
2457 
2458  /*
2459  * create frame head and tail slots only if needed (must create slots in
2460  * exactly the same cases that update_frameheadpos and update_frametailpos
2461  * need them)
2462  */
2463  winstate->framehead_slot = winstate->frametail_slot = NULL;
2464 
2465  if (frameOptions & (FRAMEOPTION_RANGE | FRAMEOPTION_GROUPS))
2466  {
2467  if (((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
2468  node->ordNumCols != 0) ||
2469  (frameOptions & FRAMEOPTION_START_OFFSET))
2470  winstate->framehead_slot = ExecInitExtraTupleSlot(estate, scanDesc,
2472  if (((frameOptions & FRAMEOPTION_END_CURRENT_ROW) &&
2473  node->ordNumCols != 0) ||
2474  (frameOptions & FRAMEOPTION_END_OFFSET))
2475  winstate->frametail_slot = ExecInitExtraTupleSlot(estate, scanDesc,
2477  }
2478 
2479  /*
2480  * Initialize result slot, type and projection.
2481  */
2483  ExecAssignProjectionInfo(&winstate->ss.ps, NULL);
2484 
2485  /* Set up data for comparing tuples */
2486  if (node->partNumCols > 0)
2487  winstate->partEqfunction =
2488  execTuplesMatchPrepare(scanDesc,
2489  node->partNumCols,
2490  node->partColIdx,
2491  node->partOperators,
2492  node->partCollations,
2493  &winstate->ss.ps);
2494 
2495  if (node->ordNumCols > 0)
2496  winstate->ordEqfunction =
2497  execTuplesMatchPrepare(scanDesc,
2498  node->ordNumCols,
2499  node->ordColIdx,
2500  node->ordOperators,
2501  node->ordCollations,
2502  &winstate->ss.ps);
2503 
2504  /*
2505  * WindowAgg nodes use aggvalues and aggnulls as well as Agg nodes.
2506  */
2507  numfuncs = winstate->numfuncs;
2508  numaggs = winstate->numaggs;
2509  econtext = winstate->ss.ps.ps_ExprContext;
2510  econtext->ecxt_aggvalues = (Datum *) palloc0(sizeof(Datum) * numfuncs);
2511  econtext->ecxt_aggnulls = (bool *) palloc0(sizeof(bool) * numfuncs);
2512 
2513  /*
2514  * allocate per-wfunc/per-agg state information.
2515  */
2516  perfunc = (WindowStatePerFunc) palloc0(sizeof(WindowStatePerFuncData) * numfuncs);
2517  peragg = (WindowStatePerAgg) palloc0(sizeof(WindowStatePerAggData) * numaggs);
2518  winstate->perfunc = perfunc;
2519  winstate->peragg = peragg;
2520 
2521  wfuncno = -1;
2522  aggno = -1;
2523  foreach(l, winstate->funcs)
2524  {
2525  WindowFuncExprState *wfuncstate = (WindowFuncExprState *) lfirst(l);
2526  WindowFunc *wfunc = wfuncstate->wfunc;
2527  WindowStatePerFunc perfuncstate;
2528  AclResult aclresult;
2529  int i;
2530 
2531  if (wfunc->winref != node->winref) /* planner screwed up? */
2532  elog(ERROR, "WindowFunc with winref %u assigned to WindowAgg with winref %u",
2533  wfunc->winref, node->winref);
2534 
2535  /* Look for a previous duplicate window function */
2536  for (i = 0; i <= wfuncno; i++)
2537  {
2538  if (equal(wfunc, perfunc[i].wfunc) &&
2539  !contain_volatile_functions((Node *) wfunc))
2540  break;
2541  }
2542  if (i <= wfuncno)
2543  {
2544  /* Found a match to an existing entry, so just mark it */
2545  wfuncstate->wfuncno = i;
2546  continue;
2547  }
2548 
2549  /* Nope, so assign a new PerAgg record */
2550  perfuncstate = &perfunc[++wfuncno];
2551 
2552  /* Mark WindowFunc state node with assigned index in the result array */
2553  wfuncstate->wfuncno = wfuncno;
2554 
2555  /* Check permission to call window function */
2556  aclresult = object_aclcheck(ProcedureRelationId, wfunc->winfnoid, GetUserId(),
2557  ACL_EXECUTE);
2558  if (aclresult != ACLCHECK_OK)
2559  aclcheck_error(aclresult, OBJECT_FUNCTION,
2560  get_func_name(wfunc->winfnoid));
2561  InvokeFunctionExecuteHook(wfunc->winfnoid);
2562 
2563  /* Fill in the perfuncstate data */
2564  perfuncstate->wfuncstate = wfuncstate;
2565  perfuncstate->wfunc = wfunc;
2566  perfuncstate->numArguments = list_length(wfuncstate->args);
2567  perfuncstate->winCollation = wfunc->inputcollid;
2568 
2569  get_typlenbyval(wfunc->wintype,
2570  &perfuncstate->resulttypeLen,
2571  &perfuncstate->resulttypeByVal);
2572 
2573  /*
2574  * If it's really just a plain aggregate function, we'll emulate the
2575  * Agg environment for it.
2576  */
2577  perfuncstate->plain_agg = wfunc->winagg;
2578  if (wfunc->winagg)
2579  {
2580  WindowStatePerAgg peraggstate;
2581 
2582  perfuncstate->aggno = ++aggno;
2583  peraggstate = &winstate->peragg[aggno];
2584  initialize_peragg(winstate, wfunc, peraggstate);
2585  peraggstate->wfuncno = wfuncno;
2586  }
2587  else
2588  {
2590 
2591  winobj->winstate = winstate;
2592  winobj->argstates = wfuncstate->args;
2593  winobj->localmem = NULL;
2594  perfuncstate->winobj = winobj;
2595 
2596  /* It's a real window function, so set up to call it. */
2597  fmgr_info_cxt(wfunc->winfnoid, &perfuncstate->flinfo,
2598  econtext->ecxt_per_query_memory);
2599  fmgr_info_set_expr((Node *) wfunc, &perfuncstate->flinfo);
2600  }
2601  }
2602 
2603  /* Update numfuncs, numaggs to match number of unique functions found */
2604  winstate->numfuncs = wfuncno + 1;
2605  winstate->numaggs = aggno + 1;
2606 
2607  /* Set up WindowObject for aggregates, if needed */
2608  if (winstate->numaggs > 0)
2609  {
2610  WindowObject agg_winobj = makeNode(WindowObjectData);
2611 
2612  agg_winobj->winstate = winstate;
2613  agg_winobj->argstates = NIL;
2614  agg_winobj->localmem = NULL;
2615  /* make sure markptr = -1 to invalidate. It may not get used */
2616  agg_winobj->markptr = -1;
2617  agg_winobj->readptr = -1;
2618  winstate->agg_winobj = agg_winobj;
2619  }
2620 
2621  /* Set the status to running */
2622  winstate->status = WINDOWAGG_RUN;
2623 
2624  /* copy frame options to state node for easy access */
2625  winstate->frameOptions = frameOptions;
2626 
2627  /* initialize frame bound offset expressions */
2628  winstate->startOffset = ExecInitExpr((Expr *) node->startOffset,
2629  (PlanState *) winstate);
2630  winstate->endOffset = ExecInitExpr((Expr *) node->endOffset,
2631  (PlanState *) winstate);
2632 
2633  /* Lookup in_range support functions if needed */
2634  if (OidIsValid(node->startInRangeFunc))
2635  fmgr_info(node->startInRangeFunc, &winstate->startInRangeFunc);
2636  if (OidIsValid(node->endInRangeFunc))
2637  fmgr_info(node->endInRangeFunc, &winstate->endInRangeFunc);
2638  winstate->inRangeColl = node->inRangeColl;
2639  winstate->inRangeAsc = node->inRangeAsc;
2640  winstate->inRangeNullsFirst = node->inRangeNullsFirst;
2641 
2642  winstate->all_first = true;
2643  winstate->partition_spooled = false;
2644  winstate->more_partitions = false;
2645 
2646  return winstate;
2647 }
AclResult
Definition: acl.h:183
@ ACLCHECK_OK
Definition: acl.h:184
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3485
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
Definition: aclchk.c:4598
#define OidIsValid(objectId)
Definition: c.h:711
bool contain_volatile_functions(Node *clause)
Definition: clauses.c:448
#define ERROR
Definition: elog.h:35
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:225
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:210
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
Definition: execExpr.c:124
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:1831
void ExecInitResultTupleSlotTL(PlanState *planstate, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1799
const TupleTableSlotOps TTSOpsMinimalTuple
Definition: execTuples.c:85
void ExecCreateScanSlotFromOuterPlan(EState *estate, ScanState *scanstate, const TupleTableSlotOps *tts_ops)
Definition: execUtils.c:683
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:481
void ExecAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc)
Definition: execUtils.c:536
struct WindowStatePerAggData * WindowStatePerAgg
Definition: execnodes.h:2434
@ WINDOWAGG_RUN
Definition: execnodes.h:2442
struct WindowStatePerFuncData * WindowStatePerFunc
Definition: execnodes.h:2433
#define EXEC_FLAG_BACKWARD
Definition: executor.h:58
#define EXEC_FLAG_MARK
Definition: executor.h:59
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
Definition: fmgr.c:136
#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:1230
MemoryContext CurrentMemoryContext
Definition: mcxt.c:124
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:153
Oid GetUserId(void)
Definition: miscinit.c:497
static WindowStatePerAggData * initialize_peragg(WindowAggState *winstate, WindowFunc *wfunc, WindowStatePerAgg peraggstate)
static TupleTableSlot * ExecWindowAgg(PlanState *pstate)
#define makeNode(_type_)
Definition: nodes.h:159
#define InvokeFunctionExecuteHook(objectId)
Definition: objectaccess.h:213
#define FRAMEOPTION_END_CURRENT_ROW
Definition: parsenodes.h:556
#define FRAMEOPTION_END_OFFSET
Definition: parsenodes.h:567
#define FRAMEOPTION_START_CURRENT_ROW
Definition: parsenodes.h:555
#define FRAMEOPTION_START_OFFSET
Definition: parsenodes.h:565
@ OBJECT_FUNCTION
Definition: parsenodes.h:1881
#define FRAMEOPTION_RANGE
Definition: parsenodes.h:547
#define FRAMEOPTION_GROUPS
Definition: parsenodes.h:549
#define ACL_EXECUTE
Definition: parsenodes.h:90
#define lfirst(lc)
Definition: pg_list.h:170
static int list_length(const List *l)
Definition: pg_list.h:150
#define NIL
Definition: pg_list.h:66
uintptr_t Datum
Definition: postgres.h:412
Datum * ecxt_aggvalues
Definition: execnodes.h:266
bool * ecxt_aggnulls
Definition: execnodes.h:268
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:254
Definition: nodes.h:112
bool outeropsset
Definition: execnodes.h:1107
const TupleTableSlotOps * outerops
Definition: execnodes.h:1099
ExprState * qual
Definition: execnodes.h:1045
Plan * plan
Definition: execnodes.h:1024
bool outeropsfixed
Definition: execnodes.h:1103
EState * state
Definition: execnodes.h:1026
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1030
List * qual
Definition: plannodes.h:151
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
ExprState * endOffset
Definition: execnodes.h:2478
FmgrInfo endInRangeFunc
Definition: execnodes.h:2484
bool partition_spooled
Definition: execnodes.h:2512
FmgrInfo startInRangeFunc
Definition: execnodes.h:2483
bool more_partitions
Definition: execnodes.h:2514
ExprState * ordEqfunction
Definition: execnodes.h:2460
ExprState * runcondition
Definition: execnodes.h:2501
WindowAggStatus status
Definition: execnodes.h:2474
struct WindowObjectData * agg_winobj
Definition: execnodes.h:2471
bool inRangeNullsFirst
Definition: execnodes.h:2487
ExprState * partEqfunction
Definition: execnodes.h:2459
ExprState * startOffset
Definition: execnodes.h:2477
bool use_pass_through
Definition: execnodes.h:2506
int partNumCols
Definition: plannodes.h:1037
Oid endInRangeFunc
Definition: plannodes.h:1081
Node * endOffset
Definition: plannodes.h:1067
bool topWindow
Definition: plannodes.h:1096
Plan plan
Definition: plannodes.h:1031
Oid inRangeColl
Definition: plannodes.h:1084
Node * startOffset
Definition: plannodes.h:1064
List * runCondition
Definition: plannodes.h:1070
Oid startInRangeFunc
Definition: plannodes.h:1078
bool inRangeAsc
Definition: plannodes.h:1087
Index winref
Definition: plannodes.h:1034
bool inRangeNullsFirst
Definition: plannodes.h:1090
int ordNumCols
Definition: plannodes.h:1049
int frameOptions
Definition: plannodes.h:1061
WindowFunc * wfunc
Definition: execnodes.h:850
Index winref
Definition: primnodes.h:495
WindowAggState * winstate
Definition: nodeWindowAgg.c:64
WindowFuncExprState * wfuncstate
Definition: nodeWindowAgg.c:80

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(), WindowFunc::inputcollid, 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, WindowFunc::winagg, WindowStatePerFuncData::winCollation, WINDOWAGG_RUN, WindowFunc::winfnoid, WindowStatePerFuncData::winobj, WindowAgg::winref, WindowFunc::winref, WindowObjectData::winstate, and WindowFunc::wintype.

Referenced by ExecInitNode().

◆ ExecReScanWindowAgg()

void ExecReScanWindowAgg ( WindowAggState node)

Definition at line 2698 of file nodeWindowAgg.c.

2699 {
2701  ExprContext *econtext = node->ss.ps.ps_ExprContext;
2702 
2703  node->status = WINDOWAGG_RUN;
2704  node->all_first = true;
2705 
2706  /* release tuplestore et al */
2707  release_partition(node);
2708 
2709  /* release all temp tuples, but especially first_part_slot */
2713  ExecClearTuple(node->temp_slot_1);
2714  ExecClearTuple(node->temp_slot_2);
2715  if (node->framehead_slot)
2717  if (node->frametail_slot)
2719 
2720  /* Forget current wfunc values */
2721  MemSet(econtext->ecxt_aggvalues, 0, sizeof(Datum) * node->numfuncs);
2722  MemSet(econtext->ecxt_aggnulls, 0, sizeof(bool) * node->numfuncs);
2723 
2724  /*
2725  * if chgParam of subnode is not null then plan will be re-scanned by
2726  * first ExecProcNode.
2727  */
2728  if (outerPlan->chgParam == NULL)
2730 }
#define MemSet(start, val, len)
Definition: c.h:953
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().