PostgreSQL Source Code  git master
nodeLimit.h File Reference
#include "nodes/execnodes.h"
Include dependency graph for nodeLimit.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

LimitStateExecInitLimit (Limit *node, EState *estate, int eflags)
 
void ExecEndLimit (LimitState *node)
 
void ExecReScanLimit (LimitState *node)
 

Function Documentation

◆ ExecEndLimit()

void ExecEndLimit ( LimitState node)

Definition at line 535 of file nodeLimit.c.

536 {
538 }
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:557
#define outerPlanState(node)
Definition: execnodes.h:1133

References ExecEndNode(), and outerPlanState.

Referenced by ExecEndNode().

◆ ExecInitLimit()

LimitState* ExecInitLimit ( Limit node,
EState estate,
int  eflags 
)

Definition at line 448 of file nodeLimit.c.

449 {
450  LimitState *limitstate;
451  Plan *outerPlan;
452 
453  /* check for unsupported flags */
454  Assert(!(eflags & EXEC_FLAG_MARK));
455 
456  /*
457  * create state structure
458  */
459  limitstate = makeNode(LimitState);
460  limitstate->ps.plan = (Plan *) node;
461  limitstate->ps.state = estate;
462  limitstate->ps.ExecProcNode = ExecLimit;
463 
464  limitstate->lstate = LIMIT_INITIAL;
465 
466  /*
467  * Miscellaneous initialization
468  *
469  * Limit nodes never call ExecQual or ExecProject, but they need an
470  * exprcontext anyway to evaluate the limit/offset parameters in.
471  */
472  ExecAssignExprContext(estate, &limitstate->ps);
473 
474  /*
475  * initialize outer plan
476  */
477  outerPlan = outerPlan(node);
478  outerPlanState(limitstate) = ExecInitNode(outerPlan, estate, eflags);
479 
480  /*
481  * initialize child expressions
482  */
483  limitstate->limitOffset = ExecInitExpr((Expr *) node->limitOffset,
484  (PlanState *) limitstate);
485  limitstate->limitCount = ExecInitExpr((Expr *) node->limitCount,
486  (PlanState *) limitstate);
487  limitstate->limitOption = node->limitOption;
488 
489  /*
490  * Initialize result type.
491  */
492  ExecInitResultTypeTL(&limitstate->ps);
493 
494  limitstate->ps.resultopsset = true;
495  limitstate->ps.resultops = ExecGetResultSlotOps(outerPlanState(limitstate),
496  &limitstate->ps.resultopsfixed);
497 
498  /*
499  * limit nodes do no projections, so initialize projection info for this
500  * node appropriately
501  */
502  limitstate->ps.ps_ProjInfo = NULL;
503 
504  /*
505  * Initialize the equality evaluation, to detect ties.
506  */
507  if (node->limitOption == LIMIT_OPTION_WITH_TIES)
508  {
509  TupleDesc desc;
510  const TupleTableSlotOps *ops;
511 
512  desc = ExecGetResultType(outerPlanState(limitstate));
513  ops = ExecGetResultSlotOps(outerPlanState(limitstate), NULL);
514 
515  limitstate->last_slot = ExecInitExtraTupleSlot(estate, desc, ops);
516  limitstate->eqfunction = execTuplesMatchPrepare(desc,
517  node->uniqNumCols,
518  node->uniqColIdx,
519  node->uniqOperators,
520  node->uniqCollations,
521  &limitstate->ps);
522  }
523 
524  return limitstate;
525 }
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
Definition: execExpr.c:128
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
void ExecInitResultTypeTL(PlanState *planstate)
Definition: execTuples.c:1756
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1832
TupleDesc ExecGetResultType(PlanState *planstate)
Definition: execUtils.c:498
const TupleTableSlotOps * ExecGetResultSlotOps(PlanState *planstate, bool *isfixed)
Definition: execUtils.c:507
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:488
@ LIMIT_INITIAL
Definition: execnodes.h:2741
#define EXEC_FLAG_MARK
Definition: executor.h:69
Assert(fmt[strlen(fmt) - 1] !='\n')
static TupleTableSlot * ExecLimit(PlanState *pstate)
Definition: nodeLimit.c:41
@ LIMIT_OPTION_WITH_TIES
Definition: nodes.h:442
#define makeNode(_type_)
Definition: nodes.h:176
#define outerPlan(node)
Definition: plannodes.h:183
PlanState ps
Definition: execnodes.h:2753
ExprState * limitOffset
Definition: execnodes.h:2754
ExprState * limitCount
Definition: execnodes.h:2755
LimitOption limitOption
Definition: execnodes.h:2756
TupleTableSlot * last_slot
Definition: execnodes.h:2765
ExprState * eqfunction
Definition: execnodes.h:2763
LimitStateCond lstate
Definition: execnodes.h:2760
LimitOption limitOption
Definition: plannodes.h:1279
Node * limitCount
Definition: plannodes.h:1276
int uniqNumCols
Definition: plannodes.h:1282
Node * limitOffset
Definition: plannodes.h:1273
const TupleTableSlotOps * resultops
Definition: execnodes.h:1114
bool resultopsset
Definition: execnodes.h:1122
Plan * plan
Definition: execnodes.h:1037
EState * state
Definition: execnodes.h:1039
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:1077
bool resultopsfixed
Definition: execnodes.h:1118
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1043

References Assert(), LimitState::eqfunction, EXEC_FLAG_MARK, ExecAssignExprContext(), ExecGetResultSlotOps(), ExecGetResultType(), ExecInitExpr(), ExecInitExtraTupleSlot(), ExecInitNode(), ExecInitResultTypeTL(), ExecLimit(), PlanState::ExecProcNode, execTuplesMatchPrepare(), LimitState::last_slot, LIMIT_INITIAL, LIMIT_OPTION_WITH_TIES, LimitState::limitCount, Limit::limitCount, LimitState::limitOffset, Limit::limitOffset, LimitState::limitOption, Limit::limitOption, LimitState::lstate, makeNode, outerPlan, outerPlanState, PlanState::plan, LimitState::ps, PlanState::ps_ProjInfo, PlanState::resultops, PlanState::resultopsfixed, PlanState::resultopsset, PlanState::state, and Limit::uniqNumCols.

Referenced by ExecInitNode().

◆ ExecReScanLimit()

void ExecReScanLimit ( LimitState node)

Definition at line 542 of file nodeLimit.c.

543 {
545 
546  /*
547  * Recompute limit/offset in case parameters changed, and reset the state
548  * machine. We must do this before rescanning our child node, in case
549  * it's a Sort that we are passing the parameters down to.
550  */
551  recompute_limits(node);
552 
553  /*
554  * if chgParam of subnode is not null then plan will be re-scanned by
555  * first ExecProcNode.
556  */
557  if (outerPlan->chgParam == NULL)
559 }
void ExecReScan(PlanState *node)
Definition: execAmi.c:78
static void recompute_limits(LimitState *node)
Definition: nodeLimit.c:354

References ExecReScan(), outerPlan, outerPlanState, and recompute_limits().

Referenced by ExecReScan().