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

Go to the source code of this file.

Functions

LockRowsStateExecInitLockRows (LockRows *node, EState *estate, int eflags)
 
void ExecEndLockRows (LockRowsState *node)
 
void ExecReScanLockRows (LockRowsState *node)
 

Function Documentation

◆ ExecEndLockRows()

void ExecEndLockRows ( LockRowsState node)

Definition at line 458 of file nodeLockRows.c.

References EvalPlanQualEnd(), ExecEndNode(), LockRowsState::lr_epqstate, and outerPlanState.

Referenced by ExecEndNode().

459 {
462 }
EPQState lr_epqstate
Definition: execnodes.h:2180
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:538
void EvalPlanQualEnd(EPQState *epqstate)
Definition: execMain.c:3253
#define outerPlanState(node)
Definition: execnodes.h:966

◆ ExecInitLockRows()

LockRowsState* ExecInitLockRows ( LockRows node,
EState estate,
int  eflags 
)

Definition at line 358 of file nodeLockRows.c.

References Assert, LockRows::epqParam, EState::es_range_table, EvalPlanQualInit(), EXEC_FLAG_MARK, ExecBuildAuxRowMark(), ExecFindRowMark(), ExecInitNode(), ExecInitResultTupleSlotTL(), ExecLockRows(), PlanState::ExecProcNode, PlanRowMark::isParent, lappend(), lfirst_node, list_length(), LockRowsState::lr_arowMarks, LockRowsState::lr_curtuples, LockRowsState::lr_epqstate, LockRowsState::lr_ntables, makeNode, ExecRowMark::markType, NIL, outerPlan, outerPlanState, palloc0(), PlanState::plan, LockRowsState::ps, PlanState::ps_ProjInfo, RowMarkRequiresRowShareLock, LockRows::rowMarks, PlanRowMark::rti, PlanState::state, and Plan::targetlist.

Referenced by ExecInitNode().

359 {
360  LockRowsState *lrstate;
361  Plan *outerPlan = outerPlan(node);
362  List *epq_arowmarks;
363  ListCell *lc;
364 
365  /* check for unsupported flags */
366  Assert(!(eflags & EXEC_FLAG_MARK));
367 
368  /*
369  * create state structure
370  */
371  lrstate = makeNode(LockRowsState);
372  lrstate->ps.plan = (Plan *) node;
373  lrstate->ps.state = estate;
374  lrstate->ps.ExecProcNode = ExecLockRows;
375 
376  /*
377  * Miscellaneous initialization
378  *
379  * LockRows nodes never call ExecQual or ExecProject, therefore no
380  * ExprContext is needed.
381  */
382 
383  /*
384  * Tuple table initialization (XXX not actually used, but upper nodes
385  * access it to get this node's result tupledesc...)
386  */
387  ExecInitResultTupleSlotTL(estate, &lrstate->ps);
388 
389  /*
390  * then initialize outer plan
391  */
392  outerPlanState(lrstate) = ExecInitNode(outerPlan, estate, eflags);
393 
394  /*
395  * LockRows nodes do no projections, so initialize projection info for
396  * this node appropriately
397  */
398  lrstate->ps.ps_ProjInfo = NULL;
399 
400  /*
401  * Create workspace in which we can remember per-RTE locked tuples
402  */
403  lrstate->lr_ntables = list_length(estate->es_range_table);
404  lrstate->lr_curtuples = (HeapTuple *)
405  palloc0(lrstate->lr_ntables * sizeof(HeapTuple));
406 
407  /*
408  * Locate the ExecRowMark(s) that this node is responsible for, and
409  * construct ExecAuxRowMarks for them. (InitPlan should already have
410  * built the global list of ExecRowMarks.)
411  */
412  lrstate->lr_arowMarks = NIL;
413  epq_arowmarks = NIL;
414  foreach(lc, node->rowMarks)
415  {
417  ExecRowMark *erm;
418  ExecAuxRowMark *aerm;
419 
420  /* ignore "parent" rowmarks; they are irrelevant at runtime */
421  if (rc->isParent)
422  continue;
423 
424  /* safety check on size of lr_curtuples array */
425  Assert(rc->rti > 0 && rc->rti <= lrstate->lr_ntables);
426 
427  /* find ExecRowMark and build ExecAuxRowMark */
428  erm = ExecFindRowMark(estate, rc->rti, false);
429  aerm = ExecBuildAuxRowMark(erm, outerPlan->targetlist);
430 
431  /*
432  * Only locking rowmarks go into our own list. Non-locking marks are
433  * passed off to the EvalPlanQual machinery. This is because we don't
434  * want to bother fetching non-locked rows unless we actually have to
435  * do an EPQ recheck.
436  */
438  lrstate->lr_arowMarks = lappend(lrstate->lr_arowMarks, aerm);
439  else
440  epq_arowmarks = lappend(epq_arowmarks, aerm);
441  }
442 
443  /* Now we have the info needed to set up EPQ state */
444  EvalPlanQualInit(&lrstate->lr_epqstate, estate,
445  outerPlan, epq_arowmarks, node->epqParam);
446 
447  return lrstate;
448 }
#define NIL
Definition: pg_list.h:69
HeapTuple * lr_curtuples
Definition: execnodes.h:2181
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:948
EPQState lr_epqstate
Definition: execnodes.h:2180
static TupleTableSlot * ExecLockRows(PlanState *pstate)
Definition: nodeLockRows.c:40
int epqParam
Definition: plannodes.h:936
EState * state
Definition: execnodes.h:914
List * es_range_table
Definition: execnodes.h:480
#define RowMarkRequiresRowShareLock(marktype)
Definition: plannodes.h:994
#define lfirst_node(type, lc)
Definition: pg_list.h:109
#define outerPlanState(node)
Definition: execnodes.h:966
PlanState ps
Definition: execnodes.h:2178
#define outerPlan(node)
Definition: plannodes.h:176
List * lappend(List *list, void *datum)
Definition: list.c:128
void * palloc0(Size size)
Definition: mcxt.c:955
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:918
void ExecInitResultTupleSlotTL(EState *estate, PlanState *planstate)
Definition: execTuples.c:890
void EvalPlanQualInit(EPQState *epqstate, EState *estate, Plan *subplan, List *auxrowmarks, int epqParam)
Definition: execMain.c:2830
Plan * plan
Definition: execnodes.h:912
#define makeNode(_type_)
Definition: nodes.h:565
#define Assert(condition)
Definition: c.h:699
#define EXEC_FLAG_MARK
Definition: executor.h:61
List * rowMarks
Definition: plannodes.h:935
RowMarkType markType
Definition: execnodes.h:601
static int list_length(const List *l)
Definition: pg_list.h:89
List * targetlist
Definition: plannodes.h:146
List * lr_arowMarks
Definition: execnodes.h:2179
bool isParent
Definition: plannodes.h:1045
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:139
Definition: pg_list.h:45
ExecAuxRowMark * ExecBuildAuxRowMark(ExecRowMark *erm, List *targetlist)
Definition: execMain.c:2430
ExecRowMark * ExecFindRowMark(EState *estate, Index rti, bool missing_ok)
Definition: execMain.c:2406

◆ ExecReScanLockRows()

void ExecReScanLockRows ( LockRowsState node)

Definition at line 466 of file nodeLockRows.c.

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

Referenced by ExecReScan().

467 {
468  /*
469  * if chgParam of subnode is not null then plan will be re-scanned by
470  * first ExecProcNode.
471  */
472  if (node->ps.lefttree->chgParam == NULL)
473  ExecReScan(node->ps.lefttree);
474 }
void ExecReScan(PlanState *node)
Definition: execAmi.c:76
struct PlanState * lefttree
Definition: execnodes.h:931
PlanState ps
Definition: execnodes.h:2178
Bitmapset * chgParam
Definition: execnodes.h:941