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

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

2534 {
2536  int i;
2537 
2538  release_partition(node);
2539 
2543  ExecClearTuple(node->temp_slot_1);
2544  ExecClearTuple(node->temp_slot_2);
2545  if (node->framehead_slot)
2547  if (node->frametail_slot)
2549 
2550  /*
2551  * Free both the expr contexts.
2552  */
2553  ExecFreeExprContext(&node->ss.ps);
2554  node->ss.ps.ps_ExprContext = node->tmpcontext;
2555  ExecFreeExprContext(&node->ss.ps);
2556 
2557  for (i = 0; i < node->numaggs; i++)
2558  {
2559  if (node->peragg[i].aggcontext != node->aggcontext)
2561  }
2564 
2565  pfree(node->perfunc);
2566  pfree(node->peragg);
2567 
2568  outerPlan = outerPlanState(node);
2569  ExecEndNode(outerPlan);
2570 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:211
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:426
ScanState ss
Definition: execnodes.h:2096
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:538
ExprContext * ps_ExprContext
Definition: execnodes.h:979
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1334
static void release_partition(WindowAggState *winstate)
TupleTableSlot * temp_slot_1
Definition: execnodes.h:2166
WindowStatePerFunc perfunc
Definition: execnodes.h:2103
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:614
TupleTableSlot * first_part_slot
Definition: execnodes.h:2159
ExprContext * tmpcontext
Definition: execnodes.h:2144
PlanState ps
Definition: execnodes.h:1331
void pfree(void *pointer)
Definition: mcxt.c:1056
#define outerPlanState(node)
Definition: execnodes.h:1034
TupleTableSlot * temp_slot_2
Definition: execnodes.h:2167
WindowStatePerAgg peragg
Definition: execnodes.h:2104
MemoryContext aggcontext
Definition: execnodes.h:2142
#define outerPlan(node)
Definition: plannodes.h:170
TupleTableSlot * agg_row_slot
Definition: execnodes.h:2165
TupleTableSlot * frametail_slot
Definition: execnodes.h:2162
TupleTableSlot * framehead_slot
Definition: execnodes.h:2161
MemoryContext aggcontext
int i
MemoryContext partcontext
Definition: execnodes.h:2141

◆ ExecInitWindowAgg()

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

Definition at line 2249 of file nodeWindowAgg.c.

References ACL_EXECUTE, aclcheck_error(), ACLCHECK_OK, WindowAggState::agg_row_slot, WindowAggState::agg_winobj, WindowAggState::aggcontext, WindowStatePerFuncData::aggno, 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, WindowAgg::endInRangeFunc, WindowAgg::endOffset, equal(), ERROR, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecAssignExprContext(), ExecAssignProjectionInfo(), ExecCreateScanSlotFromOuterPlan(), ExecInitExpr(), ExecInitExtraTupleSlot(), ExecInitNode(), 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, WindowAgg::frameOptions, WindowAggState::frameOptions, WindowAggState::frametail_slot, WindowAggState::funcs, get_func_name(), get_typlenbyval(), GetUserId(), i, initialize_peragg(), WindowAgg::inRangeAsc, WindowAgg::inRangeColl, WindowAgg::inRangeNullsFirst, InvokeFunctionExecuteHook, lfirst, list_length(), WindowObjectData::localmem, makeNode, WindowObjectData::markptr, 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, WindowAgg::partNumCols, WindowAgg::partOperators, WindowAggState::peragg, WindowAggState::perfunc, pg_proc_aclcheck(), WindowStatePerFuncData::plain_agg, WindowAgg::plan, PlanState::plan, ScanState::ps, PlanState::ps_ExprContext, Plan::qual, PlanState::qual, WindowObjectData::readptr, WindowStatePerFuncData::resulttypeByVal, WindowStatePerFuncData::resulttypeLen, WindowAggState::ss, ScanState::ss_ScanTupleSlot, WindowAgg::startInRangeFunc, WindowAgg::startOffset, WindowAggState::startOffset, PlanState::state, WindowAggState::temp_slot_1, WindowAggState::temp_slot_2, WindowAggState::tmpcontext, TupleTableSlot::tts_tupleDescriptor, TTSOpsMinimalTuple, TTSOpsVirtual, WindowStatePerFuncData::wfunc, WindowFuncExprState::wfunc, WindowStatePerAggData::wfuncno, WindowFuncExprState::wfuncno, WindowStatePerFuncData::wfuncstate, WindowStatePerFuncData::winCollation, WindowFunc::winfnoid, WindowStatePerFuncData::winobj, WindowFunc::winref, WindowAgg::winref, and WindowObjectData::winstate.

Referenced by ExecInitNode().

2250 {
2251  WindowAggState *winstate;
2252  Plan *outerPlan;
2253  ExprContext *econtext;
2254  ExprContext *tmpcontext;
2255  WindowStatePerFunc perfunc;
2256  WindowStatePerAgg peragg;
2257  int frameOptions = node->frameOptions;
2258  int numfuncs,
2259  wfuncno,
2260  numaggs,
2261  aggno;
2262  TupleDesc scanDesc;
2263  ListCell *l;
2264 
2265  /* check for unsupported flags */
2266  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
2267 
2268  /*
2269  * create state structure
2270  */
2271  winstate = makeNode(WindowAggState);
2272  winstate->ss.ps.plan = (Plan *) node;
2273  winstate->ss.ps.state = estate;
2274  winstate->ss.ps.ExecProcNode = ExecWindowAgg;
2275 
2276  /*
2277  * Create expression contexts. We need two, one for per-input-tuple
2278  * processing and one for per-output-tuple processing. We cheat a little
2279  * by using ExecAssignExprContext() to build both.
2280  */
2281  ExecAssignExprContext(estate, &winstate->ss.ps);
2282  tmpcontext = winstate->ss.ps.ps_ExprContext;
2283  winstate->tmpcontext = tmpcontext;
2284  ExecAssignExprContext(estate, &winstate->ss.ps);
2285 
2286  /* Create long-lived context for storage of partition-local memory etc */
2287  winstate->partcontext =
2289  "WindowAgg Partition",
2291 
2292  /*
2293  * Create mid-lived context for aggregate trans values etc.
2294  *
2295  * Note that moving aggregates each use their own private context, not
2296  * this one.
2297  */
2298  winstate->aggcontext =
2300  "WindowAgg Aggregates",
2302 
2303  /*
2304  * WindowAgg nodes never have quals, since they can only occur at the
2305  * logical top level of a query (ie, after any WHERE or HAVING filters)
2306  */
2307  Assert(node->plan.qual == NIL);
2308  winstate->ss.ps.qual = NULL;
2309 
2310  /*
2311  * initialize child nodes
2312  */
2313  outerPlan = outerPlan(node);
2314  outerPlanState(winstate) = ExecInitNode(outerPlan, estate, eflags);
2315 
2316  /*
2317  * initialize source tuple type (which is also the tuple type that we'll
2318  * store in the tuplestore and use in all our working slots).
2319  */
2321  scanDesc = winstate->ss.ss_ScanTupleSlot->tts_tupleDescriptor;
2322 
2323  /* the outer tuple isn't the child's tuple, but always a minimal tuple */
2324  winstate->ss.ps.outeropsset = true;
2325  winstate->ss.ps.outerops = &TTSOpsMinimalTuple;
2326  winstate->ss.ps.outeropsfixed = true;
2327 
2328  /*
2329  * tuple table initialization
2330  */
2331  winstate->first_part_slot = ExecInitExtraTupleSlot(estate, scanDesc,
2333  winstate->agg_row_slot = ExecInitExtraTupleSlot(estate, scanDesc,
2335  winstate->temp_slot_1 = ExecInitExtraTupleSlot(estate, scanDesc,
2337  winstate->temp_slot_2 = ExecInitExtraTupleSlot(estate, scanDesc,
2339 
2340  /*
2341  * create frame head and tail slots only if needed (must create slots in
2342  * exactly the same cases that update_frameheadpos and update_frametailpos
2343  * need them)
2344  */
2345  winstate->framehead_slot = winstate->frametail_slot = NULL;
2346 
2347  if (frameOptions & (FRAMEOPTION_RANGE | FRAMEOPTION_GROUPS))
2348  {
2349  if (((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
2350  node->ordNumCols != 0) ||
2351  (frameOptions & FRAMEOPTION_START_OFFSET))
2352  winstate->framehead_slot = ExecInitExtraTupleSlot(estate, scanDesc,
2354  if (((frameOptions & FRAMEOPTION_END_CURRENT_ROW) &&
2355  node->ordNumCols != 0) ||
2356  (frameOptions & FRAMEOPTION_END_OFFSET))
2357  winstate->frametail_slot = ExecInitExtraTupleSlot(estate, scanDesc,
2359  }
2360 
2361  /*
2362  * Initialize result slot, type and projection.
2363  */
2365  ExecAssignProjectionInfo(&winstate->ss.ps, NULL);
2366 
2367  /* Set up data for comparing tuples */
2368  if (node->partNumCols > 0)
2369  winstate->partEqfunction =
2370  execTuplesMatchPrepare(scanDesc,
2371  node->partNumCols,
2372  node->partColIdx,
2373  node->partOperators,
2374  node->partCollations,
2375  &winstate->ss.ps);
2376 
2377  if (node->ordNumCols > 0)
2378  winstate->ordEqfunction =
2379  execTuplesMatchPrepare(scanDesc,
2380  node->ordNumCols,
2381  node->ordColIdx,
2382  node->ordOperators,
2383  node->ordCollations,
2384  &winstate->ss.ps);
2385 
2386  /*
2387  * WindowAgg nodes use aggvalues and aggnulls as well as Agg nodes.
2388  */
2389  numfuncs = winstate->numfuncs;
2390  numaggs = winstate->numaggs;
2391  econtext = winstate->ss.ps.ps_ExprContext;
2392  econtext->ecxt_aggvalues = (Datum *) palloc0(sizeof(Datum) * numfuncs);
2393  econtext->ecxt_aggnulls = (bool *) palloc0(sizeof(bool) * numfuncs);
2394 
2395  /*
2396  * allocate per-wfunc/per-agg state information.
2397  */
2398  perfunc = (WindowStatePerFunc) palloc0(sizeof(WindowStatePerFuncData) * numfuncs);
2399  peragg = (WindowStatePerAgg) palloc0(sizeof(WindowStatePerAggData) * numaggs);
2400  winstate->perfunc = perfunc;
2401  winstate->peragg = peragg;
2402 
2403  wfuncno = -1;
2404  aggno = -1;
2405  foreach(l, winstate->funcs)
2406  {
2407  WindowFuncExprState *wfuncstate = (WindowFuncExprState *) lfirst(l);
2408  WindowFunc *wfunc = wfuncstate->wfunc;
2409  WindowStatePerFunc perfuncstate;
2410  AclResult aclresult;
2411  int i;
2412 
2413  if (wfunc->winref != node->winref) /* planner screwed up? */
2414  elog(ERROR, "WindowFunc with winref %u assigned to WindowAgg with winref %u",
2415  wfunc->winref, node->winref);
2416 
2417  /* Look for a previous duplicate window function */
2418  for (i = 0; i <= wfuncno; i++)
2419  {
2420  if (equal(wfunc, perfunc[i].wfunc) &&
2421  !contain_volatile_functions((Node *) wfunc))
2422  break;
2423  }
2424  if (i <= wfuncno)
2425  {
2426  /* Found a match to an existing entry, so just mark it */
2427  wfuncstate->wfuncno = i;
2428  continue;
2429  }
2430 
2431  /* Nope, so assign a new PerAgg record */
2432  perfuncstate = &perfunc[++wfuncno];
2433 
2434  /* Mark WindowFunc state node with assigned index in the result array */
2435  wfuncstate->wfuncno = wfuncno;
2436 
2437  /* Check permission to call window function */
2438  aclresult = pg_proc_aclcheck(wfunc->winfnoid, GetUserId(),
2439  ACL_EXECUTE);
2440  if (aclresult != ACLCHECK_OK)
2441  aclcheck_error(aclresult, OBJECT_FUNCTION,
2442  get_func_name(wfunc->winfnoid));
2443  InvokeFunctionExecuteHook(wfunc->winfnoid);
2444 
2445  /* Fill in the perfuncstate data */
2446  perfuncstate->wfuncstate = wfuncstate;
2447  perfuncstate->wfunc = wfunc;
2448  perfuncstate->numArguments = list_length(wfuncstate->args);
2449 
2450  fmgr_info_cxt(wfunc->winfnoid, &perfuncstate->flinfo,
2451  econtext->ecxt_per_query_memory);
2452  fmgr_info_set_expr((Node *) wfunc, &perfuncstate->flinfo);
2453 
2454  perfuncstate->winCollation = wfunc->inputcollid;
2455 
2456  get_typlenbyval(wfunc->wintype,
2457  &perfuncstate->resulttypeLen,
2458  &perfuncstate->resulttypeByVal);
2459 
2460  /*
2461  * If it's really just a plain aggregate function, we'll emulate the
2462  * Agg environment for it.
2463  */
2464  perfuncstate->plain_agg = wfunc->winagg;
2465  if (wfunc->winagg)
2466  {
2467  WindowStatePerAgg peraggstate;
2468 
2469  perfuncstate->aggno = ++aggno;
2470  peraggstate = &winstate->peragg[aggno];
2471  initialize_peragg(winstate, wfunc, peraggstate);
2472  peraggstate->wfuncno = wfuncno;
2473  }
2474  else
2475  {
2477 
2478  winobj->winstate = winstate;
2479  winobj->argstates = wfuncstate->args;
2480  winobj->localmem = NULL;
2481  perfuncstate->winobj = winobj;
2482  }
2483  }
2484 
2485  /* Update numfuncs, numaggs to match number of unique functions found */
2486  winstate->numfuncs = wfuncno + 1;
2487  winstate->numaggs = aggno + 1;
2488 
2489  /* Set up WindowObject for aggregates, if needed */
2490  if (winstate->numaggs > 0)
2491  {
2492  WindowObject agg_winobj = makeNode(WindowObjectData);
2493 
2494  agg_winobj->winstate = winstate;
2495  agg_winobj->argstates = NIL;
2496  agg_winobj->localmem = NULL;
2497  /* make sure markptr = -1 to invalidate. It may not get used */
2498  agg_winobj->markptr = -1;
2499  agg_winobj->readptr = -1;
2500  winstate->agg_winobj = agg_winobj;
2501  }
2502 
2503  /* copy frame options to state node for easy access */
2504  winstate->frameOptions = frameOptions;
2505 
2506  /* initialize frame bound offset expressions */
2507  winstate->startOffset = ExecInitExpr((Expr *) node->startOffset,
2508  (PlanState *) winstate);
2509  winstate->endOffset = ExecInitExpr((Expr *) node->endOffset,
2510  (PlanState *) winstate);
2511 
2512  /* Lookup in_range support functions if needed */
2513  if (OidIsValid(node->startInRangeFunc))
2514  fmgr_info(node->startInRangeFunc, &winstate->startInRangeFunc);
2515  if (OidIsValid(node->endInRangeFunc))
2516  fmgr_info(node->endInRangeFunc, &winstate->endInRangeFunc);
2517  winstate->inRangeColl = node->inRangeColl;
2518  winstate->inRangeAsc = node->inRangeAsc;
2519  winstate->inRangeNullsFirst = node->inRangeNullsFirst;
2520 
2521  winstate->all_first = true;
2522  winstate->partition_spooled = false;
2523  winstate->more_partitions = false;
2524 
2525  return winstate;
2526 }
int ordNumCols
Definition: plannodes.h:830
#define NIL
Definition: pg_list.h:65
List * qual
Definition: plannodes.h:141
ExprState * endOffset
Definition: execnodes.h:2123
#define AllocSetContextCreate
Definition: memutils.h:170
Datum * ecxt_aggvalues
Definition: execnodes.h:243
struct WindowStatePerAggData * WindowStatePerAgg
Definition: execnodes.h:2092
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1796
Oid inRangeColl
Definition: plannodes.h:840
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:3008
Oid GetUserId(void)
Definition: miscinit.c:380
ScanState ss
Definition: execnodes.h:2096
ExprContext * ps_ExprContext
Definition: execnodes.h:979
AttrNumber * ordColIdx
Definition: plannodes.h:831
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:84
Definition: nodes.h:525
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1334
struct WindowStatePerFuncData * WindowStatePerFunc
Definition: execnodes.h:2091
WindowFuncExprState * wfuncstate
Definition: nodeWindowAgg.c:80
bool contain_volatile_functions(Node *clause)
Definition: clauses.c:724
EState * state
Definition: execnodes.h:942
Index winref
Definition: primnodes.h:365
TupleTableSlot * temp_slot_1
Definition: execnodes.h:2166
#define OidIsValid(objectId)
Definition: c.h:638
WindowStatePerFunc perfunc
Definition: execnodes.h:2103
Oid * ordOperators
Definition: plannodes.h:832
#define FRAMEOPTION_START_OFFSET
Definition: parsenodes.h:523
Oid endInRangeFunc
Definition: plannodes.h:839
TupleTableSlot * first_part_slot
Definition: execnodes.h:2159
Oid * partCollations
Definition: plannodes.h:829
ExprContext * tmpcontext
Definition: execnodes.h:2144
PlanState ps
Definition: execnodes.h:1331
struct WindowObjectData * agg_winobj
Definition: execnodes.h:2117
bool inRangeNullsFirst
Definition: execnodes.h:2132
Node * startOffset
Definition: plannodes.h:835
static WindowStatePerAggData * initialize_peragg(WindowAggState *winstate, WindowFunc *wfunc, WindowStatePerAgg peraggstate)
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3353
Oid * ordCollations
Definition: plannodes.h:833
ExprState * partEqfunction
Definition: execnodes.h:2105
#define ERROR
Definition: elog.h:43
FmgrInfo endInRangeFunc
Definition: execnodes.h:2129
char * get_func_name(Oid funcid)
Definition: lsyscache.c:1410
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:124
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:192
#define EXEC_FLAG_BACKWARD
Definition: executor.h:58
#define outerPlanState(node)
Definition: execnodes.h:1034
TupleTableSlot * temp_slot_2
Definition: execnodes.h:2167
WindowStatePerAgg peragg
Definition: execnodes.h:2104
ExprState * ordEqfunction
Definition: execnodes.h:2106
ExprState * startOffset
Definition: execnodes.h:2122
void ExecAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc)
Definition: execUtils.c:499
Node * endOffset
Definition: plannodes.h:836
#define FRAMEOPTION_END_CURRENT_ROW
Definition: parsenodes.h:514
#define fmgr_info_set_expr(expr, finfo)
Definition: fmgr.h:135
int partNumCols
Definition: plannodes.h:826
bool outeropsset
Definition: execnodes.h:1021
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
MemoryContext aggcontext
Definition: execnodes.h:2142
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
Definition: fmgr.c:134
#define FRAMEOPTION_START_CURRENT_ROW
Definition: parsenodes.h:513
#define InvokeFunctionExecuteHook(objectId)
Definition: objectaccess.h:179
#define outerPlan(node)
Definition: plannodes.h:170
bool inRangeAsc
Definition: plannodes.h:841
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
bool * ecxt_aggnulls
Definition: execnodes.h:245
static TupleTableSlot * ExecWindowAgg(PlanState *pstate)
WindowAggState * winstate
Definition: nodeWindowAgg.c:64
void * palloc0(Size size)
Definition: mcxt.c:980
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:946
AclResult
Definition: acl.h:177
uintptr_t Datum
Definition: postgres.h:367
TupleTableSlot * agg_row_slot
Definition: execnodes.h:2165
AttrNumber * partColIdx
Definition: plannodes.h:827
Plan * plan
Definition: execnodes.h:940
TupleTableSlot * frametail_slot
Definition: execnodes.h:2162
bool more_partitions
Definition: execnodes.h:2150
Oid * partOperators
Definition: plannodes.h:828
#define makeNode(_type_)
Definition: nodes.h:573
#define FRAMEOPTION_RANGE
Definition: parsenodes.h:505
#define Assert(condition)
Definition: c.h:732
#define lfirst(lc)
Definition: pg_list.h:190
Index winref
Definition: plannodes.h:825
ExprState * execTuplesMatchPrepare(TupleDesc desc, int numCols, const AttrNumber *keyColIdx, const Oid *eqOperators, const Oid *collations, PlanState *parent)
Definition: execGrouping.c:59
#define EXEC_FLAG_MARK
Definition: executor.h:59
FmgrInfo startInRangeFunc
Definition: execnodes.h:2128
TupleTableSlot * framehead_slot
Definition: execnodes.h:2161
bool inRangeNullsFirst
Definition: plannodes.h:842
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:444
static int list_length(const List *l)
Definition: pg_list.h:169
#define FRAMEOPTION_END_OFFSET
Definition: parsenodes.h:525
void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval)
Definition: lsyscache.c:2029
void ExecInitResultTupleSlotTL(PlanState *planstate, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1764
bool outeropsfixed
Definition: execnodes.h:1017
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:231
ExprState * qual
Definition: execnodes.h:961
Oid startInRangeFunc
Definition: plannodes.h:838
bool partition_spooled
Definition: execnodes.h:2148
#define ACL_EXECUTE
Definition: parsenodes.h:81
#define elog(elevel,...)
Definition: elog.h:226
AclResult pg_proc_aclcheck(Oid proc_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4655
int i
Plan plan
Definition: plannodes.h:824
#define FRAMEOPTION_GROUPS
Definition: parsenodes.h:507
MemoryContext partcontext
Definition: execnodes.h:2141
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
Definition: execExpr.c:121
int frameOptions
Definition: plannodes.h:834
WindowFunc * wfunc
Definition: execnodes.h:758
void ExecCreateScanSlotFromOuterPlan(EState *estate, ScanState *scanstate, const TupleTableSlotOps *tts_ops)
Definition: execUtils.c:646
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:139
const TupleTableSlotOps TTSOpsMinimalTuple
Definition: execTuples.c:86
const TupleTableSlotOps * outerops
Definition: execnodes.h:1013

◆ ExecReScanWindowAgg()

void ExecReScanWindowAgg ( WindowAggState node)

Definition at line 2577 of file nodeWindowAgg.c.

References WindowAggState::agg_row_slot, WindowAggState::all_done, WindowAggState::all_first, PlanState::chgParam, 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::temp_slot_1, and WindowAggState::temp_slot_2.

Referenced by ExecReScan().

2578 {
2580  ExprContext *econtext = node->ss.ps.ps_ExprContext;
2581 
2582  node->all_done = false;
2583  node->all_first = true;
2584 
2585  /* release tuplestore et al */
2586  release_partition(node);
2587 
2588  /* release all temp tuples, but especially first_part_slot */
2592  ExecClearTuple(node->temp_slot_1);
2593  ExecClearTuple(node->temp_slot_2);
2594  if (node->framehead_slot)
2596  if (node->frametail_slot)
2598 
2599  /* Forget current wfunc values */
2600  MemSet(econtext->ecxt_aggvalues, 0, sizeof(Datum) * node->numfuncs);
2601  MemSet(econtext->ecxt_aggnulls, 0, sizeof(bool) * node->numfuncs);
2602 
2603  /*
2604  * if chgParam of subnode is not null then plan will be re-scanned by
2605  * first ExecProcNode.
2606  */
2607  if (outerPlan->chgParam == NULL)
2608  ExecReScan(outerPlan);
2609 }
Datum * ecxt_aggvalues
Definition: execnodes.h:243
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:426
ScanState ss
Definition: execnodes.h:2096
ExprContext * ps_ExprContext
Definition: execnodes.h:979
void ExecReScan(PlanState *node)
Definition: execAmi.c:77
#define MemSet(start, val, len)
Definition: c.h:955
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1334
static void release_partition(WindowAggState *winstate)
TupleTableSlot * temp_slot_1
Definition: execnodes.h:2166
TupleTableSlot * first_part_slot
Definition: execnodes.h:2159
PlanState ps
Definition: execnodes.h:1331
#define outerPlanState(node)
Definition: execnodes.h:1034
TupleTableSlot * temp_slot_2
Definition: execnodes.h:2167
Bitmapset * chgParam
Definition: execnodes.h:972
#define outerPlan(node)
Definition: plannodes.h:170
bool * ecxt_aggnulls
Definition: execnodes.h:245
uintptr_t Datum
Definition: postgres.h:367
TupleTableSlot * agg_row_slot
Definition: execnodes.h:2165
TupleTableSlot * frametail_slot
Definition: execnodes.h:2162
TupleTableSlot * framehead_slot
Definition: execnodes.h:2161