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

2740 {
2742  int i;
2743 
2744  if (node->buffer != NULL)
2745  {
2746  tuplestore_end(node->buffer);
2747 
2748  /* nullify so that release_partition skips the tuplestore_clear() */
2749  node->buffer = NULL;
2750  }
2751 
2752  release_partition(node);
2753 
2754  for (i = 0; i < node->numaggs; i++)
2755  {
2756  if (node->peragg[i].aggcontext != node->aggcontext)
2758  }
2761 
2762  pfree(node->perfunc);
2763  pfree(node->peragg);
2764 
2765  outerPlan = outerPlanState(node);
2767 }
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:562
#define outerPlanState(node)
Definition: execnodes.h:1222
int i
Definition: isn.c:72
void pfree(void *pointer)
Definition: mcxt.c:1521
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:454
static void release_partition(WindowAggState *winstate)
#define outerPlan(node)
Definition: plannodes.h:183
MemoryContext aggcontext
Definition: execnodes.h:2650
WindowStatePerAgg peragg
Definition: execnodes.h:2600
MemoryContext partcontext
Definition: execnodes.h:2649
Tuplestorestate * buffer
Definition: execnodes.h:2603
WindowStatePerFunc perfunc
Definition: execnodes.h:2599
MemoryContext aggcontext
void tuplestore_end(Tuplestorestate *state)
Definition: tuplestore.c:492

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

Referenced by ExecEndNode().

◆ ExecInitWindowAgg()

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

Definition at line 2431 of file nodeWindowAgg.c.

2432 {
2433  WindowAggState *winstate;
2434  Plan *outerPlan;
2435  ExprContext *econtext;
2436  ExprContext *tmpcontext;
2437  WindowStatePerFunc perfunc;
2438  WindowStatePerAgg peragg;
2439  int frameOptions = node->frameOptions;
2440  int numfuncs,
2441  wfuncno,
2442  numaggs,
2443  aggno;
2444  TupleDesc scanDesc;
2445  ListCell *l;
2446 
2447  /* check for unsupported flags */
2448  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
2449 
2450  /*
2451  * create state structure
2452  */
2453  winstate = makeNode(WindowAggState);
2454  winstate->ss.ps.plan = (Plan *) node;
2455  winstate->ss.ps.state = estate;
2456  winstate->ss.ps.ExecProcNode = ExecWindowAgg;
2457 
2458  /* copy frame options to state node for easy access */
2459  winstate->frameOptions = frameOptions;
2460 
2461  /*
2462  * Create expression contexts. We need two, one for per-input-tuple
2463  * processing and one for per-output-tuple processing. We cheat a little
2464  * by using ExecAssignExprContext() to build both.
2465  */
2466  ExecAssignExprContext(estate, &winstate->ss.ps);
2467  tmpcontext = winstate->ss.ps.ps_ExprContext;
2468  winstate->tmpcontext = tmpcontext;
2469  ExecAssignExprContext(estate, &winstate->ss.ps);
2470 
2471  /* Create long-lived context for storage of partition-local memory etc */
2472  winstate->partcontext =
2474  "WindowAgg Partition",
2476 
2477  /*
2478  * Create mid-lived context for aggregate trans values etc.
2479  *
2480  * Note that moving aggregates each use their own private context, not
2481  * this one.
2482  */
2483  winstate->aggcontext =
2485  "WindowAgg Aggregates",
2487 
2488  /* Only the top-level WindowAgg may have a qual */
2489  Assert(node->plan.qual == NIL || node->topWindow);
2490 
2491  /* Initialize the qual */
2492  winstate->ss.ps.qual = ExecInitQual(node->plan.qual,
2493  (PlanState *) winstate);
2494 
2495  /*
2496  * Setup the run condition, if we received one from the query planner.
2497  * When set, this may allow us to move into pass-through mode so that we
2498  * don't have to perform any further evaluation of WindowFuncs in the
2499  * current partition or possibly stop returning tuples altogether when all
2500  * tuples are in the same partition.
2501  */
2502  winstate->runcondition = ExecInitQual(node->runCondition,
2503  (PlanState *) winstate);
2504 
2505  /*
2506  * When we're not the top-level WindowAgg node or we are but have a
2507  * PARTITION BY clause we must move into one of the WINDOWAGG_PASSTHROUGH*
2508  * modes when the runCondition becomes false.
2509  */
2510  winstate->use_pass_through = !node->topWindow || node->partNumCols > 0;
2511 
2512  /* remember if we're the top-window or we are below the top-window */
2513  winstate->top_window = node->topWindow;
2514 
2515  /*
2516  * initialize child nodes
2517  */
2518  outerPlan = outerPlan(node);
2519  outerPlanState(winstate) = ExecInitNode(outerPlan, estate, eflags);
2520 
2521  /*
2522  * initialize source tuple type (which is also the tuple type that we'll
2523  * store in the tuplestore and use in all our working slots).
2524  */
2526  scanDesc = winstate->ss.ss_ScanTupleSlot->tts_tupleDescriptor;
2527 
2528  /* the outer tuple isn't the child's tuple, but always a minimal tuple */
2529  winstate->ss.ps.outeropsset = true;
2530  winstate->ss.ps.outerops = &TTSOpsMinimalTuple;
2531  winstate->ss.ps.outeropsfixed = true;
2532 
2533  /*
2534  * tuple table initialization
2535  */
2536  winstate->first_part_slot = ExecInitExtraTupleSlot(estate, scanDesc,
2538  winstate->agg_row_slot = ExecInitExtraTupleSlot(estate, scanDesc,
2540  winstate->temp_slot_1 = ExecInitExtraTupleSlot(estate, scanDesc,
2542  winstate->temp_slot_2 = ExecInitExtraTupleSlot(estate, scanDesc,
2544 
2545  /*
2546  * create frame head and tail slots only if needed (must create slots in
2547  * exactly the same cases that update_frameheadpos and update_frametailpos
2548  * need them)
2549  */
2550  winstate->framehead_slot = winstate->frametail_slot = NULL;
2551 
2552  if (frameOptions & (FRAMEOPTION_RANGE | FRAMEOPTION_GROUPS))
2553  {
2554  if (((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
2555  node->ordNumCols != 0) ||
2556  (frameOptions & FRAMEOPTION_START_OFFSET))
2557  winstate->framehead_slot = ExecInitExtraTupleSlot(estate, scanDesc,
2559  if (((frameOptions & FRAMEOPTION_END_CURRENT_ROW) &&
2560  node->ordNumCols != 0) ||
2561  (frameOptions & FRAMEOPTION_END_OFFSET))
2562  winstate->frametail_slot = ExecInitExtraTupleSlot(estate, scanDesc,
2564  }
2565 
2566  /*
2567  * Initialize result slot, type and projection.
2568  */
2570  ExecAssignProjectionInfo(&winstate->ss.ps, NULL);
2571 
2572  /* Set up data for comparing tuples */
2573  if (node->partNumCols > 0)
2574  winstate->partEqfunction =
2575  execTuplesMatchPrepare(scanDesc,
2576  node->partNumCols,
2577  node->partColIdx,
2578  node->partOperators,
2579  node->partCollations,
2580  &winstate->ss.ps);
2581 
2582  if (node->ordNumCols > 0)
2583  winstate->ordEqfunction =
2584  execTuplesMatchPrepare(scanDesc,
2585  node->ordNumCols,
2586  node->ordColIdx,
2587  node->ordOperators,
2588  node->ordCollations,
2589  &winstate->ss.ps);
2590 
2591  /*
2592  * WindowAgg nodes use aggvalues and aggnulls as well as Agg nodes.
2593  */
2594  numfuncs = winstate->numfuncs;
2595  numaggs = winstate->numaggs;
2596  econtext = winstate->ss.ps.ps_ExprContext;
2597  econtext->ecxt_aggvalues = (Datum *) palloc0(sizeof(Datum) * numfuncs);
2598  econtext->ecxt_aggnulls = (bool *) palloc0(sizeof(bool) * numfuncs);
2599 
2600  /*
2601  * allocate per-wfunc/per-agg state information.
2602  */
2603  perfunc = (WindowStatePerFunc) palloc0(sizeof(WindowStatePerFuncData) * numfuncs);
2604  peragg = (WindowStatePerAgg) palloc0(sizeof(WindowStatePerAggData) * numaggs);
2605  winstate->perfunc = perfunc;
2606  winstate->peragg = peragg;
2607 
2608  wfuncno = -1;
2609  aggno = -1;
2610  foreach(l, winstate->funcs)
2611  {
2612  WindowFuncExprState *wfuncstate = (WindowFuncExprState *) lfirst(l);
2613  WindowFunc *wfunc = wfuncstate->wfunc;
2614  WindowStatePerFunc perfuncstate;
2615  AclResult aclresult;
2616  int i;
2617 
2618  if (wfunc->winref != node->winref) /* planner screwed up? */
2619  elog(ERROR, "WindowFunc with winref %u assigned to WindowAgg with winref %u",
2620  wfunc->winref, node->winref);
2621 
2622  /* Look for a previous duplicate window function */
2623  for (i = 0; i <= wfuncno; i++)
2624  {
2625  if (equal(wfunc, perfunc[i].wfunc) &&
2626  !contain_volatile_functions((Node *) wfunc))
2627  break;
2628  }
2629  if (i <= wfuncno)
2630  {
2631  /* Found a match to an existing entry, so just mark it */
2632  wfuncstate->wfuncno = i;
2633  continue;
2634  }
2635 
2636  /* Nope, so assign a new PerAgg record */
2637  perfuncstate = &perfunc[++wfuncno];
2638 
2639  /* Mark WindowFunc state node with assigned index in the result array */
2640  wfuncstate->wfuncno = wfuncno;
2641 
2642  /* Check permission to call window function */
2643  aclresult = object_aclcheck(ProcedureRelationId, wfunc->winfnoid, GetUserId(),
2644  ACL_EXECUTE);
2645  if (aclresult != ACLCHECK_OK)
2646  aclcheck_error(aclresult, OBJECT_FUNCTION,
2647  get_func_name(wfunc->winfnoid));
2648  InvokeFunctionExecuteHook(wfunc->winfnoid);
2649 
2650  /* Fill in the perfuncstate data */
2651  perfuncstate->wfuncstate = wfuncstate;
2652  perfuncstate->wfunc = wfunc;
2653  perfuncstate->numArguments = list_length(wfuncstate->args);
2654  perfuncstate->winCollation = wfunc->inputcollid;
2655 
2656  get_typlenbyval(wfunc->wintype,
2657  &perfuncstate->resulttypeLen,
2658  &perfuncstate->resulttypeByVal);
2659 
2660  /*
2661  * If it's really just a plain aggregate function, we'll emulate the
2662  * Agg environment for it.
2663  */
2664  perfuncstate->plain_agg = wfunc->winagg;
2665  if (wfunc->winagg)
2666  {
2667  WindowStatePerAgg peraggstate;
2668 
2669  perfuncstate->aggno = ++aggno;
2670  peraggstate = &winstate->peragg[aggno];
2671  initialize_peragg(winstate, wfunc, peraggstate);
2672  peraggstate->wfuncno = wfuncno;
2673  }
2674  else
2675  {
2677 
2678  winobj->winstate = winstate;
2679  winobj->argstates = wfuncstate->args;
2680  winobj->localmem = NULL;
2681  perfuncstate->winobj = winobj;
2682 
2683  /* It's a real window function, so set up to call it. */
2684  fmgr_info_cxt(wfunc->winfnoid, &perfuncstate->flinfo,
2685  econtext->ecxt_per_query_memory);
2686  fmgr_info_set_expr((Node *) wfunc, &perfuncstate->flinfo);
2687  }
2688  }
2689 
2690  /* Update numfuncs, numaggs to match number of unique functions found */
2691  winstate->numfuncs = wfuncno + 1;
2692  winstate->numaggs = aggno + 1;
2693 
2694  /* Set up WindowObject for aggregates, if needed */
2695  if (winstate->numaggs > 0)
2696  {
2697  WindowObject agg_winobj = makeNode(WindowObjectData);
2698 
2699  agg_winobj->winstate = winstate;
2700  agg_winobj->argstates = NIL;
2701  agg_winobj->localmem = NULL;
2702  /* make sure markptr = -1 to invalidate. It may not get used */
2703  agg_winobj->markptr = -1;
2704  agg_winobj->readptr = -1;
2705  winstate->agg_winobj = agg_winobj;
2706  }
2707 
2708  /* Set the status to running */
2709  winstate->status = WINDOWAGG_RUN;
2710 
2711  /* initialize frame bound offset expressions */
2712  winstate->startOffset = ExecInitExpr((Expr *) node->startOffset,
2713  (PlanState *) winstate);
2714  winstate->endOffset = ExecInitExpr((Expr *) node->endOffset,
2715  (PlanState *) winstate);
2716 
2717  /* Lookup in_range support functions if needed */
2718  if (OidIsValid(node->startInRangeFunc))
2719  fmgr_info(node->startInRangeFunc, &winstate->startInRangeFunc);
2720  if (OidIsValid(node->endInRangeFunc))
2721  fmgr_info(node->endInRangeFunc, &winstate->endInRangeFunc);
2722  winstate->inRangeColl = node->inRangeColl;
2723  winstate->inRangeAsc = node->inRangeAsc;
2724  winstate->inRangeNullsFirst = node->inRangeNullsFirst;
2725 
2726  winstate->all_first = true;
2727  winstate->partition_spooled = false;
2728  winstate->more_partitions = false;
2729  winstate->next_partition = true;
2730 
2731  return winstate;
2732 }
AclResult
Definition: acl.h:182
@ ACLCHECK_OK
Definition: acl.h:183
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:2622
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
Definition: aclchk.c:3810
#define Assert(condition)
Definition: c.h:812
#define OidIsValid(objectId)
Definition: c.h:729
bool contain_volatile_functions(Node *clause)
Definition: clauses.c:537
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:223
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:224
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
Definition: execExpr.c:138
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:661
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:485
void ExecAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc)
Definition: execUtils.c:540
struct WindowStatePerAggData * WindowStatePerAgg
Definition: execnodes.h:2576
@ WINDOWAGG_RUN
Definition: execnodes.h:2584
struct WindowStatePerFuncData * WindowStatePerFunc
Definition: execnodes.h:2575
#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:1347
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:524
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:593
#define FRAMEOPTION_END_OFFSET
Definition: parsenodes.h:604
#define FRAMEOPTION_START_CURRENT_ROW
Definition: parsenodes.h:592
#define FRAMEOPTION_START_OFFSET
Definition: parsenodes.h:602
@ OBJECT_FUNCTION
Definition: parsenodes.h:2287
#define FRAMEOPTION_RANGE
Definition: parsenodes.h:584
#define FRAMEOPTION_GROUPS
Definition: parsenodes.h:586
#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:277
bool * ecxt_aggnulls
Definition: execnodes.h:279
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:265
Definition: nodes.h:129
bool outeropsset
Definition: execnodes.h:1209
const TupleTableSlotOps * outerops
Definition: execnodes.h:1201
ExprState * qual
Definition: execnodes.h:1147
Plan * plan
Definition: execnodes.h:1126
bool outeropsfixed
Definition: execnodes.h:1205
EState * state
Definition: execnodes.h:1128
ExprContext * ps_ExprContext
Definition: execnodes.h:1165
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1132
List * qual
Definition: plannodes.h:154
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1576
PlanState ps
Definition: execnodes.h:1573
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:123
ExprState * endOffset
Definition: execnodes.h:2620
ScanState ss
Definition: execnodes.h:2592
FmgrInfo endInRangeFunc
Definition: execnodes.h:2626
TupleTableSlot * framehead_slot
Definition: execnodes.h:2669
bool next_partition
Definition: execnodes.h:2657
bool partition_spooled
Definition: execnodes.h:2655
FmgrInfo startInRangeFunc
Definition: execnodes.h:2625
bool more_partitions
Definition: execnodes.h:2658
TupleTableSlot * frametail_slot
Definition: execnodes.h:2670
ExprState * ordEqfunction
Definition: execnodes.h:2602
ExprState * runcondition
Definition: execnodes.h:2637
TupleTableSlot * temp_slot_2
Definition: execnodes.h:2675
WindowAggStatus status
Definition: execnodes.h:2616
TupleTableSlot * agg_row_slot
Definition: execnodes.h:2673
struct WindowObjectData * agg_winobj
Definition: execnodes.h:2613
bool inRangeNullsFirst
Definition: execnodes.h:2629
ExprState * partEqfunction
Definition: execnodes.h:2601
ExprState * startOffset
Definition: execnodes.h:2619
TupleTableSlot * first_part_slot
Definition: execnodes.h:2667
ExprContext * tmpcontext
Definition: execnodes.h:2652
TupleTableSlot * temp_slot_1
Definition: execnodes.h:2674
bool use_pass_through
Definition: execnodes.h:2632
int partNumCols
Definition: plannodes.h:1047
Oid endInRangeFunc
Definition: plannodes.h:1091
Node * endOffset
Definition: plannodes.h:1077
bool topWindow
Definition: plannodes.h:1106
Plan plan
Definition: plannodes.h:1041
Oid inRangeColl
Definition: plannodes.h:1094
Node * startOffset
Definition: plannodes.h:1074
List * runCondition
Definition: plannodes.h:1080
Oid startInRangeFunc
Definition: plannodes.h:1088
bool inRangeAsc
Definition: plannodes.h:1097
Index winref
Definition: plannodes.h:1044
bool inRangeNullsFirst
Definition: plannodes.h:1100
int ordNumCols
Definition: plannodes.h:1059
int frameOptions
Definition: plannodes.h:1071
WindowFunc * wfunc
Definition: execnodes.h:883
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, WindowAggState::next_partition, 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 2774 of file nodeWindowAgg.c.

2775 {
2777  ExprContext *econtext = node->ss.ps.ps_ExprContext;
2778 
2779  node->status = WINDOWAGG_RUN;
2780  node->all_first = true;
2781 
2782  /* release tuplestore et al */
2783  release_partition(node);
2784 
2785  /* release all temp tuples, but especially first_part_slot */
2789  ExecClearTuple(node->temp_slot_1);
2790  ExecClearTuple(node->temp_slot_2);
2791  if (node->framehead_slot)
2793  if (node->frametail_slot)
2795 
2796  /* Forget current wfunc values */
2797  MemSet(econtext->ecxt_aggvalues, 0, sizeof(Datum) * node->numfuncs);
2798  MemSet(econtext->ecxt_aggnulls, 0, sizeof(bool) * node->numfuncs);
2799 
2800  /*
2801  * if chgParam of subnode is not null then plan will be re-scanned by
2802  * first ExecProcNode.
2803  */
2804  if (outerPlan->chgParam == NULL)
2806 }
#define MemSet(start, val, len)
Definition: c.h:974
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().