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.

References ExecEndNode(), ExecFreeExprContext(), outerPlanState, and LimitState::ps.

Referenced by ExecEndNode().

536 {
537  ExecFreeExprContext(&node->ps);
539 }
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:543
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:655
#define outerPlanState(node)
Definition: execnodes.h:1039
PlanState ps
Definition: execnodes.h:2498

◆ ExecInitLimit()

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

Definition at line 448 of file nodeLimit.c.

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

Referenced by ExecInitNode().

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 }
static TupleTableSlot * ExecLimit(PlanState *pstate)
Definition: nodeLimit.c:41
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1801
Oid * uniqOperators
Definition: plannodes.h:988
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:985
const TupleTableSlotOps * ExecGetResultSlotOps(PlanState *planstate, bool *isfixed)
Definition: execUtils.c:504
EState * state
Definition: execnodes.h:947
LimitStateCond lstate
Definition: execnodes.h:2505
LimitOption limitOption
Definition: execnodes.h:2501
ExprState * limitCount
Definition: execnodes.h:2500
Node * limitOffset
Definition: plannodes.h:983
ExprState * eqfunction
Definition: execnodes.h:2508
const TupleTableSlotOps * resultops
Definition: execnodes.h:1020
Oid * uniqCollations
Definition: plannodes.h:989
LimitOption limitOption
Definition: plannodes.h:985
Node * limitCount
Definition: plannodes.h:984
#define outerPlanState(node)
Definition: execnodes.h:1039
void ExecInitResultTypeTL(PlanState *planstate)
Definition: execTuples.c:1725
ExprState * limitOffset
Definition: execnodes.h:2499
bool resultopsset
Definition: execnodes.h:1028
#define outerPlan(node)
Definition: plannodes.h:172
int uniqNumCols
Definition: plannodes.h:986
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:951
TupleTableSlot * last_slot
Definition: execnodes.h:2510
Plan * plan
Definition: execnodes.h:945
#define makeNode(_type_)
Definition: nodes.h:577
#define Assert(condition)
Definition: c.h:745
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
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:485
TupleDesc ExecGetResultType(PlanState *planstate)
Definition: execUtils.c:495
bool resultopsfixed
Definition: execnodes.h:1024
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
Definition: execExpr.c:123
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:139
PlanState ps
Definition: execnodes.h:2498
AttrNumber * uniqColIdx
Definition: plannodes.h:987

◆ ExecReScanLimit()

void ExecReScanLimit ( LimitState node)

Definition at line 543 of file nodeLimit.c.

References PlanState::chgParam, ExecReScan(), PlanState::lefttree, LimitState::ps, and recompute_limits().

Referenced by ExecReScan().

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