PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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

void ExecEndLockRows ( LockRowsState node)

Definition at line 451 of file nodeLockRows.c.

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

Referenced by ExecEndNode().

452 {
455 }
EPQState lr_epqstate
Definition: execnodes.h:2025
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:523
void EvalPlanQualEnd(EPQState *epqstate)
Definition: execMain.c:3206
#define outerPlanState(node)
Definition: execnodes.h:893
LockRowsState* ExecInitLockRows ( LockRows node,
EState estate,
int  eflags 
)

Definition at line 352 of file nodeLockRows.c.

References Assert, LockRows::epqParam, EState::es_range_table, EvalPlanQualInit(), EXEC_FLAG_MARK, ExecAssignResultTypeFromTL(), ExecBuildAuxRowMark(), ExecFindRowMark(), ExecInitNode(), ExecInitResultTupleSlot(), 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().

353 {
354  LockRowsState *lrstate;
355  Plan *outerPlan = outerPlan(node);
356  List *epq_arowmarks;
357  ListCell *lc;
358 
359  /* check for unsupported flags */
360  Assert(!(eflags & EXEC_FLAG_MARK));
361 
362  /*
363  * create state structure
364  */
365  lrstate = makeNode(LockRowsState);
366  lrstate->ps.plan = (Plan *) node;
367  lrstate->ps.state = estate;
368  lrstate->ps.ExecProcNode = ExecLockRows;
369 
370  /*
371  * Miscellaneous initialization
372  *
373  * LockRows nodes never call ExecQual or ExecProject.
374  */
375 
376  /*
377  * Tuple table initialization (XXX not actually used...)
378  */
379  ExecInitResultTupleSlot(estate, &lrstate->ps);
380 
381  /*
382  * then initialize outer plan
383  */
384  outerPlanState(lrstate) = ExecInitNode(outerPlan, estate, eflags);
385 
386  /*
387  * LockRows nodes do no projections, so initialize projection info for
388  * this node appropriately
389  */
390  ExecAssignResultTypeFromTL(&lrstate->ps);
391  lrstate->ps.ps_ProjInfo = NULL;
392 
393  /*
394  * Create workspace in which we can remember per-RTE locked tuples
395  */
396  lrstate->lr_ntables = list_length(estate->es_range_table);
397  lrstate->lr_curtuples = (HeapTuple *)
398  palloc0(lrstate->lr_ntables * sizeof(HeapTuple));
399 
400  /*
401  * Locate the ExecRowMark(s) that this node is responsible for, and
402  * construct ExecAuxRowMarks for them. (InitPlan should already have
403  * built the global list of ExecRowMarks.)
404  */
405  lrstate->lr_arowMarks = NIL;
406  epq_arowmarks = NIL;
407  foreach(lc, node->rowMarks)
408  {
410  ExecRowMark *erm;
411  ExecAuxRowMark *aerm;
412 
413  /* ignore "parent" rowmarks; they are irrelevant at runtime */
414  if (rc->isParent)
415  continue;
416 
417  /* safety check on size of lr_curtuples array */
418  Assert(rc->rti > 0 && rc->rti <= lrstate->lr_ntables);
419 
420  /* find ExecRowMark and build ExecAuxRowMark */
421  erm = ExecFindRowMark(estate, rc->rti, false);
422  aerm = ExecBuildAuxRowMark(erm, outerPlan->targetlist);
423 
424  /*
425  * Only locking rowmarks go into our own list. Non-locking marks are
426  * passed off to the EvalPlanQual machinery. This is because we don't
427  * want to bother fetching non-locked rows unless we actually have to
428  * do an EPQ recheck.
429  */
431  lrstate->lr_arowMarks = lappend(lrstate->lr_arowMarks, aerm);
432  else
433  epq_arowmarks = lappend(epq_arowmarks, aerm);
434  }
435 
436  /* Now we have the info needed to set up EPQ state */
437  EvalPlanQualInit(&lrstate->lr_epqstate, estate,
438  outerPlan, epq_arowmarks, node->epqParam);
439 
440  return lrstate;
441 }
#define NIL
Definition: pg_list.h:69
HeapTuple * lr_curtuples
Definition: execnodes.h:2026
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:882
EPQState lr_epqstate
Definition: execnodes.h:2025
static TupleTableSlot * ExecLockRows(PlanState *pstate)
Definition: nodeLockRows.c:40
int epqParam
Definition: plannodes.h:911
EState * state
Definition: execnodes.h:849
List * es_range_table
Definition: execnodes.h:431
#define RowMarkRequiresRowShareLock(marktype)
Definition: plannodes.h:969
void ExecAssignResultTypeFromTL(PlanState *planstate)
Definition: execUtils.c:445
void ExecInitResultTupleSlot(EState *estate, PlanState *planstate)
Definition: execTuples.c:832
#define lfirst_node(type, lc)
Definition: pg_list.h:109
#define outerPlanState(node)
Definition: execnodes.h:893
PlanState ps
Definition: execnodes.h:2023
#define outerPlan(node)
Definition: plannodes.h:174
List * lappend(List *list, void *datum)
Definition: list.c:128
void * palloc0(Size size)
Definition: mcxt.c:877
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:853
void EvalPlanQualInit(EPQState *epqstate, EState *estate, Plan *subplan, List *auxrowmarks, int epqParam)
Definition: execMain.c:2795
Plan * plan
Definition: execnodes.h:847
#define makeNode(_type_)
Definition: nodes.h:557
#define Assert(condition)
Definition: c.h:664
#define EXEC_FLAG_MARK
Definition: executor.h:61
List * rowMarks
Definition: plannodes.h:910
RowMarkType markType
Definition: execnodes.h:539
static int list_length(const List *l)
Definition: pg_list.h:89
List * targetlist
Definition: plannodes.h:144
List * lr_arowMarks
Definition: execnodes.h:2024
bool isParent
Definition: plannodes.h:1020
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:2408
ExecRowMark * ExecFindRowMark(EState *estate, Index rti, bool missing_ok)
Definition: execMain.c:2384
void ExecReScanLockRows ( LockRowsState node)

Definition at line 459 of file nodeLockRows.c.

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

Referenced by ExecReScan().

460 {
461  /*
462  * if chgParam of subnode is not null then plan will be re-scanned by
463  * first ExecProcNode.
464  */
465  if (node->ps.lefttree->chgParam == NULL)
466  ExecReScan(node->ps.lefttree);
467 }
void ExecReScan(PlanState *node)
Definition: execAmi.c:76
struct PlanState * lefttree
Definition: execnodes.h:866
PlanState ps
Definition: execnodes.h:2023
Bitmapset * chgParam
Definition: execnodes.h:875