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

2660 {
2662  int i;
2663 
2664  release_partition(node);
2665 
2669  ExecClearTuple(node->temp_slot_1);
2670  ExecClearTuple(node->temp_slot_2);
2671  if (node->framehead_slot)
2673  if (node->frametail_slot)
2675 
2676  /*
2677  * Free both the expr contexts.
2678  */
2679  ExecFreeExprContext(&node->ss.ps);
2680  node->ss.ps.ps_ExprContext = node->tmpcontext;
2681  ExecFreeExprContext(&node->ss.ps);
2682 
2683  for (i = 0; i < node->numaggs; i++)
2684  {
2685  if (node->peragg[i].aggcontext != node->aggcontext)
2687  }
2690 
2691  pfree(node->perfunc);
2692  pfree(node->peragg);
2693 
2694  outerPlan = outerPlanState(node);
2696 }
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:556
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:650
#define outerPlanState(node)
Definition: execnodes.h:1094
int i
Definition: isn.c:73
void pfree(void *pointer)
Definition: mcxt.c:1175
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:218
static void release_partition(WindowAggState *winstate)
#define outerPlan(node)
Definition: plannodes.h:172
ExprContext * ps_ExprContext
Definition: execnodes.h:1037
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1426
PlanState ps
Definition: execnodes.h:1423
MemoryContext aggcontext
Definition: execnodes.h:2470
ScanState ss
Definition: execnodes.h:2423
WindowStatePerAgg peragg
Definition: execnodes.h:2431
MemoryContext partcontext
Definition: execnodes.h:2469
TupleTableSlot * framehead_slot
Definition: execnodes.h:2498
TupleTableSlot * frametail_slot
Definition: execnodes.h:2499
TupleTableSlot * temp_slot_2
Definition: execnodes.h:2504
TupleTableSlot * agg_row_slot
Definition: execnodes.h:2502
WindowStatePerFunc perfunc
Definition: execnodes.h:2430
TupleTableSlot * first_part_slot
Definition: execnodes.h:2496
ExprContext * tmpcontext
Definition: execnodes.h:2472
TupleTableSlot * temp_slot_1
Definition: execnodes.h:2503
MemoryContext aggcontext
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:425

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

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

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