PostgreSQL Source Code  git master
nodeSeqscan.c File Reference
#include "postgres.h"
#include "access/relscan.h"
#include "executor/execdebug.h"
#include "executor/nodeSeqscan.h"
#include "utils/rel.h"
Include dependency graph for nodeSeqscan.c:

Go to the source code of this file.

Functions

static TupleTableSlotSeqNext (SeqScanState *node)
 
static bool SeqRecheck (SeqScanState *node, TupleTableSlot *slot)
 
static TupleTableSlotExecSeqScan (PlanState *pstate)
 
SeqScanStateExecInitSeqScan (SeqScan *node, EState *estate, int eflags)
 
void ExecEndSeqScan (SeqScanState *node)
 
void ExecReScanSeqScan (SeqScanState *node)
 
void ExecSeqScanEstimate (SeqScanState *node, ParallelContext *pcxt)
 
void ExecSeqScanInitializeDSM (SeqScanState *node, ParallelContext *pcxt)
 
void ExecSeqScanReInitializeDSM (SeqScanState *node, ParallelContext *pcxt)
 
void ExecSeqScanInitializeWorker (SeqScanState *node, ParallelWorkerContext *pwcxt)
 

Function Documentation

◆ ExecEndSeqScan()

void ExecEndSeqScan ( SeqScanState node)

Definition at line 203 of file nodeSeqscan.c.

References ExecClearTuple(), ExecCloseScanRelation(), ExecFreeExprContext(), heap_endscan(), ScanState::ps, PlanState::ps_ResultTupleSlot, SeqScanState::ss, ScanState::ss_currentRelation, ScanState::ss_currentScanDesc, and ScanState::ss_ScanTupleSlot.

Referenced by ExecEndNode().

204 {
205  Relation relation;
206  HeapScanDesc scanDesc;
207 
208  /*
209  * get information from node
210  */
211  relation = node->ss.ss_currentRelation;
212  scanDesc = node->ss.ss_currentScanDesc;
213 
214  /*
215  * Free the exprcontext
216  */
217  ExecFreeExprContext(&node->ss.ps);
218 
219  /*
220  * clean out the tuple table
221  */
224 
225  /*
226  * close heap scan
227  */
228  if (scanDesc != NULL)
229  heap_endscan(scanDesc);
230 
231  /*
232  * close the heap relation.
233  */
234  ExecCloseScanRelation(relation);
235 }
void heap_endscan(HeapScanDesc scan)
Definition: heapam.c:1568
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:475
ScanState ss
Definition: execnodes.h:1136
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1127
Relation ss_currentRelation
Definition: execnodes.h:1125
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:561
PlanState ps
Definition: execnodes.h:1124
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:901
void ExecCloseScanRelation(Relation scanrel)
Definition: execUtils.c:696
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1126

◆ ExecInitSeqScan()

SeqScanState* ExecInitSeqScan ( SeqScan node,
EState estate,
int  eflags 
)

Definition at line 140 of file nodeSeqscan.c.

References Assert, ExecAssignExprContext(), ExecAssignScanProjectionInfo(), ExecInitQual(), ExecInitResultTupleSlotTL(), ExecInitScanTupleSlot(), ExecOpenScanRelation(), PlanState::ExecProcNode, ExecSeqScan(), innerPlan, makeNode, outerPlan, Scan::plan, PlanState::plan, ScanState::ps, Plan::qual, PlanState::qual, RelationGetDescr, Scan::scanrelid, SeqScanState::ss, ScanState::ss_currentRelation, and PlanState::state.

Referenced by ExecInitNode().

141 {
142  SeqScanState *scanstate;
143 
144  /*
145  * Once upon a time it was possible to have an outerPlan of a SeqScan, but
146  * not any more.
147  */
148  Assert(outerPlan(node) == NULL);
149  Assert(innerPlan(node) == NULL);
150 
151  /*
152  * create state structure
153  */
154  scanstate = makeNode(SeqScanState);
155  scanstate->ss.ps.plan = (Plan *) node;
156  scanstate->ss.ps.state = estate;
157  scanstate->ss.ps.ExecProcNode = ExecSeqScan;
158 
159  /*
160  * Miscellaneous initialization
161  *
162  * create expression context for node
163  */
164  ExecAssignExprContext(estate, &scanstate->ss.ps);
165 
166  /*
167  * Initialize scan relation.
168  *
169  * Get the relation object id from the relid'th entry in the range table,
170  * open that relation and acquire appropriate lock on it.
171  */
172  scanstate->ss.ss_currentRelation =
173  ExecOpenScanRelation(estate,
174  node->scanrelid,
175  eflags);
176 
177  /* and create slot with the appropriate rowtype */
178  ExecInitScanTupleSlot(estate, &scanstate->ss,
180 
181  /*
182  * Initialize result slot, type and projection.
183  */
184  ExecInitResultTupleSlotTL(estate, &scanstate->ss.ps);
185  ExecAssignScanProjectionInfo(&scanstate->ss);
186 
187  /*
188  * initialize child expressions
189  */
190  scanstate->ss.ps.qual =
191  ExecInitQual(node->plan.qual, (PlanState *) scanstate);
192 
193  return scanstate;
194 }
List * qual
Definition: plannodes.h:145
Plan plan
Definition: plannodes.h:330
Index scanrelid
Definition: plannodes.h:331
#define RelationGetDescr(relation)
Definition: rel.h:437
ScanState ss
Definition: execnodes.h:1136
Relation ss_currentRelation
Definition: execnodes.h:1125
EState * state
Definition: execnodes.h:870
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:204
PlanState ps
Definition: execnodes.h:1124
static TupleTableSlot * ExecSeqScan(PlanState *pstate)
Definition: nodeSeqscan.c:125
void ExecAssignScanProjectionInfo(ScanState *node)
Definition: execScan.c:235
Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
Definition: execUtils.c:638
#define innerPlan(node)
Definition: plannodes.h:173
#define outerPlan(node)
Definition: plannodes.h:174
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:874
void ExecInitResultTupleSlotTL(EState *estate, PlanState *planstate)
Definition: execTuples.c:870
Plan * plan
Definition: execnodes.h:868
#define makeNode(_type_)
Definition: nodes.h:561
#define Assert(condition)
Definition: c.h:688
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:425
ExprState * qual
Definition: execnodes.h:886
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc)
Definition: execTuples.c:895

◆ ExecReScanSeqScan()

void ExecReScanSeqScan ( SeqScanState node)

Definition at line 249 of file nodeSeqscan.c.

References ExecScanReScan(), heap_rescan(), SeqScanState::ss, and ScanState::ss_currentScanDesc.

Referenced by ExecReScan().

250 {
251  HeapScanDesc scan;
252 
253  scan = node->ss.ss_currentScanDesc;
254 
255  if (scan != NULL)
256  heap_rescan(scan, /* scan desc */
257  NULL); /* new scan keys */
258 
259  ExecScanReScan((ScanState *) node);
260 }
ScanState ss
Definition: execnodes.h:1136
void heap_rescan(HeapScanDesc scan, ScanKey key)
Definition: heapam.c:1524
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1126
void ExecScanReScan(ScanState *node)
Definition: execScan.c:262

◆ ExecSeqScan()

static TupleTableSlot* ExecSeqScan ( PlanState pstate)
static

Definition at line 125 of file nodeSeqscan.c.

References castNode, ExecScan(), SeqNext(), SeqRecheck(), and SeqScanState::ss.

Referenced by ExecInitSeqScan().

126 {
127  SeqScanState *node = castNode(SeqScanState, pstate);
128 
129  return ExecScan(&node->ss,
132 }
#define castNode(_type_, nodeptr)
Definition: nodes.h:582
TupleTableSlot * ExecScan(ScanState *node, ExecScanAccessMtd accessMtd, ExecScanRecheckMtd recheckMtd)
Definition: execScan.c:121
ScanState ss
Definition: execnodes.h:1136
static TupleTableSlot * SeqNext(SeqScanState *node)
Definition: nodeSeqscan.c:49
bool(* ExecScanRecheckMtd)(ScanState *node, TupleTableSlot *slot)
Definition: executor.h:423
static bool SeqRecheck(SeqScanState *node, TupleTableSlot *slot)
Definition: nodeSeqscan.c:106
TupleTableSlot *(* ExecScanAccessMtd)(ScanState *node)
Definition: executor.h:422

◆ ExecSeqScanEstimate()

void ExecSeqScanEstimate ( SeqScanState node,
ParallelContext pcxt 
)

Definition at line 275 of file nodeSeqscan.c.

References EState::es_snapshot, ParallelContext::estimator, heap_parallelscan_estimate(), ScanState::ps, SeqScanState::pscan_len, shm_toc_estimate_chunk, shm_toc_estimate_keys, SeqScanState::ss, and PlanState::state.

Referenced by ExecParallelEstimate().

277 {
278  EState *estate = node->ss.ps.state;
279 
282  shm_toc_estimate_keys(&pcxt->estimator, 1);
283 }
shm_toc_estimator estimator
Definition: parallel.h:41
Snapshot es_snapshot
Definition: execnodes.h:443
ScanState ss
Definition: execnodes.h:1136
EState * state
Definition: execnodes.h:870
#define shm_toc_estimate_chunk(e, sz)
Definition: shm_toc.h:51
Size pscan_len
Definition: execnodes.h:1137
PlanState ps
Definition: execnodes.h:1124
#define shm_toc_estimate_keys(e, cnt)
Definition: shm_toc.h:53
Size heap_parallelscan_estimate(Snapshot snapshot)
Definition: heapam.c:1603

◆ ExecSeqScanInitializeDSM()

void ExecSeqScanInitializeDSM ( SeqScanState node,
ParallelContext pcxt 
)

Definition at line 292 of file nodeSeqscan.c.

References EState::es_snapshot, heap_beginscan_parallel(), heap_parallelscan_initialize(), PlanState::plan, Plan::plan_node_id, ScanState::ps, SeqScanState::pscan_len, shm_toc_allocate(), shm_toc_insert(), SeqScanState::ss, ScanState::ss_currentRelation, ScanState::ss_currentScanDesc, PlanState::state, and ParallelContext::toc.

Referenced by ExecParallelInitializeDSM().

294 {
295  EState *estate = node->ss.ps.state;
296  ParallelHeapScanDesc pscan;
297 
298  pscan = shm_toc_allocate(pcxt->toc, node->pscan_len);
300  node->ss.ss_currentRelation,
301  estate->es_snapshot);
302  shm_toc_insert(pcxt->toc, node->ss.ps.plan->plan_node_id, pscan);
303  node->ss.ss_currentScanDesc =
305 }
int plan_node_id
Definition: plannodes.h:143
Snapshot es_snapshot
Definition: execnodes.h:443
ScanState ss
Definition: execnodes.h:1136
Relation ss_currentRelation
Definition: execnodes.h:1125
EState * state
Definition: execnodes.h:870
Size pscan_len
Definition: execnodes.h:1137
PlanState ps
Definition: execnodes.h:1124
void heap_parallelscan_initialize(ParallelHeapScanDesc target, Relation relation, Snapshot snapshot)
Definition: heapam.c:1618
Plan * plan
Definition: execnodes.h:868
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition: shm_toc.c:88
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1126
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
Definition: shm_toc.c:171
HeapScanDesc heap_beginscan_parallel(Relation relation, ParallelHeapScanDesc parallel_scan)
Definition: heapam.c:1662
shm_toc * toc
Definition: parallel.h:44

◆ ExecSeqScanInitializeWorker()

void ExecSeqScanInitializeWorker ( SeqScanState node,
ParallelWorkerContext pwcxt 
)

Definition at line 329 of file nodeSeqscan.c.

References heap_beginscan_parallel(), PlanState::plan, Plan::plan_node_id, ScanState::ps, shm_toc_lookup(), SeqScanState::ss, ScanState::ss_currentRelation, ScanState::ss_currentScanDesc, and ParallelWorkerContext::toc.

Referenced by ExecParallelInitializeWorker().

331 {
332  ParallelHeapScanDesc pscan;
333 
334  pscan = shm_toc_lookup(pwcxt->toc, node->ss.ps.plan->plan_node_id, false);
335  node->ss.ss_currentScanDesc =
337 }
int plan_node_id
Definition: plannodes.h:143
ScanState ss
Definition: execnodes.h:1136
Relation ss_currentRelation
Definition: execnodes.h:1125
PlanState ps
Definition: execnodes.h:1124
Plan * plan
Definition: execnodes.h:868
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1126
HeapScanDesc heap_beginscan_parallel(Relation relation, ParallelHeapScanDesc parallel_scan)
Definition: heapam.c:1662
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232

◆ ExecSeqScanReInitializeDSM()

void ExecSeqScanReInitializeDSM ( SeqScanState node,
ParallelContext pcxt 
)

Definition at line 314 of file nodeSeqscan.c.

References heap_parallelscan_reinitialize(), HeapScanDescData::rs_parallel, SeqScanState::ss, and ScanState::ss_currentScanDesc.

Referenced by ExecParallelReInitializeDSM().

316 {
317  HeapScanDesc scan = node->ss.ss_currentScanDesc;
318 
320 }
ScanState ss
Definition: execnodes.h:1136
ParallelHeapScanDesc rs_parallel
Definition: relscan.h:74
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1126
void heap_parallelscan_reinitialize(ParallelHeapScanDesc parallel_scan)
Definition: heapam.c:1650

◆ SeqNext()

static TupleTableSlot * SeqNext ( SeqScanState node)
static

Definition at line 49 of file nodeSeqscan.c.

References EState::es_direction, EState::es_snapshot, ExecClearTuple(), ExecStoreTuple(), heap_beginscan(), heap_getnext(), ScanState::ps, HeapScanDescData::rs_cbuf, SeqScanState::ss, ScanState::ss_currentRelation, ScanState::ss_currentScanDesc, ScanState::ss_ScanTupleSlot, and PlanState::state.

Referenced by ExecSeqScan().

50 {
51  HeapTuple tuple;
52  HeapScanDesc scandesc;
53  EState *estate;
54  ScanDirection direction;
55  TupleTableSlot *slot;
56 
57  /*
58  * get information from the estate and scan state
59  */
60  scandesc = node->ss.ss_currentScanDesc;
61  estate = node->ss.ps.state;
62  direction = estate->es_direction;
63  slot = node->ss.ss_ScanTupleSlot;
64 
65  if (scandesc == NULL)
66  {
67  /*
68  * We reach here if the scan is not parallel, or if we're executing a
69  * scan that was intended to be parallel serially.
70  */
71  scandesc = heap_beginscan(node->ss.ss_currentRelation,
72  estate->es_snapshot,
73  0, NULL);
74  node->ss.ss_currentScanDesc = scandesc;
75  }
76 
77  /*
78  * get the next tuple from the table
79  */
80  tuple = heap_getnext(scandesc, direction);
81 
82  /*
83  * save the tuple and the buffer returned to us by the access methods in
84  * our scan tuple slot and return the slot. Note: we pass 'false' because
85  * tuples returned by heap_getnext() are pointers onto disk pages and were
86  * not created with palloc() and so should not be pfree()'d. Note also
87  * that ExecStoreTuple will increment the refcount of the buffer; the
88  * refcount will not be dropped until the tuple table slot is cleared.
89  */
90  if (tuple)
91  ExecStoreTuple(tuple, /* tuple to store */
92  slot, /* slot to store in */
93  scandesc->rs_cbuf, /* buffer associated with this
94  * tuple */
95  false); /* don't pfree this pointer */
96  else
97  ExecClearTuple(slot);
98 
99  return slot;
100 }
TupleTableSlot * ExecStoreTuple(HeapTuple tuple, TupleTableSlot *slot, Buffer buffer, bool shouldFree)
Definition: execTuples.c:356
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:475
Snapshot es_snapshot
Definition: execnodes.h:443
ScanState ss
Definition: execnodes.h:1136
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1127
Relation ss_currentRelation
Definition: execnodes.h:1125
EState * state
Definition: execnodes.h:870
ScanDirection es_direction
Definition: execnodes.h:442
PlanState ps
Definition: execnodes.h:1124
ScanDirection
Definition: sdir.h:22
HeapTuple heap_getnext(HeapScanDesc scan, ScanDirection direction)
Definition: heapam.c:1831
Buffer rs_cbuf
Definition: relscan.h:72
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1126
HeapScanDesc heap_beginscan(Relation relation, Snapshot snapshot, int nkeys, ScanKey key)
Definition: heapam.c:1400

◆ SeqRecheck()

static bool SeqRecheck ( SeqScanState node,
TupleTableSlot slot 
)
static

Definition at line 106 of file nodeSeqscan.c.

Referenced by ExecSeqScan().

107 {
108  /*
109  * Note that unlike IndexScan, SeqScan never use keys in heap_beginscan
110  * (and this is very bad) - so, here we do not check are keys ok or not.
111  */
112  return true;
113 }