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 202 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().

203 {
204  Relation relation;
205  HeapScanDesc scanDesc;
206 
207  /*
208  * get information from node
209  */
210  relation = node->ss.ss_currentRelation;
211  scanDesc = node->ss.ss_currentScanDesc;
212 
213  /*
214  * Free the exprcontext
215  */
216  ExecFreeExprContext(&node->ss.ps);
217 
218  /*
219  * clean out the tuple table
220  */
223 
224  /*
225  * close heap scan
226  */
227  if (scanDesc != NULL)
228  heap_endscan(scanDesc);
229 
230  /*
231  * close the heap relation.
232  */
233  ExecCloseScanRelation(relation);
234 }
void heap_endscan(HeapScanDesc scan)
Definition: heapam.c:1572
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:485
ScanState ss
Definition: execnodes.h:1222
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1213
Relation ss_currentRelation
Definition: execnodes.h:1211
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:574
PlanState ps
Definition: execnodes.h:1210
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:955
void ExecCloseScanRelation(Relation scanrel)
Definition: execUtils.c:709
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1212

◆ ExecInitSeqScan()

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

Definition at line 139 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().

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

◆ ExecReScanSeqScan()

void ExecReScanSeqScan ( SeqScanState node)

Definition at line 248 of file nodeSeqscan.c.

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

Referenced by ExecReScan().

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

◆ ExecSeqScan()

static TupleTableSlot* ExecSeqScan ( PlanState pstate)
static

Definition at line 124 of file nodeSeqscan.c.

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

Referenced by ExecInitSeqScan().

125 {
126  SeqScanState *node = castNode(SeqScanState, pstate);
127 
128  return ExecScan(&node->ss,
131 }
#define castNode(_type_, nodeptr)
Definition: nodes.h:586
TupleTableSlot * ExecScan(ScanState *node, ExecScanAccessMtd accessMtd, ExecScanRecheckMtd recheckMtd)
Definition: execScan.c:121
ScanState ss
Definition: execnodes.h:1222
static TupleTableSlot * SeqNext(SeqScanState *node)
Definition: nodeSeqscan.c:49
bool(* ExecScanRecheckMtd)(ScanState *node, TupleTableSlot *slot)
Definition: executor.h:421
static bool SeqRecheck(SeqScanState *node, TupleTableSlot *slot)
Definition: nodeSeqscan.c:105
TupleTableSlot *(* ExecScanAccessMtd)(ScanState *node)
Definition: executor.h:420

◆ ExecSeqScanEstimate()

void ExecSeqScanEstimate ( SeqScanState node,
ParallelContext pcxt 
)

Definition at line 274 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().

276 {
277  EState *estate = node->ss.ps.state;
278 
281  shm_toc_estimate_keys(&pcxt->estimator, 1);
282 }
shm_toc_estimator estimator
Definition: parallel.h:41
Snapshot es_snapshot
Definition: execnodes.h:479
ScanState ss
Definition: execnodes.h:1222
EState * state
Definition: execnodes.h:920
#define shm_toc_estimate_chunk(e, sz)
Definition: shm_toc.h:51
Size pscan_len
Definition: execnodes.h:1223
PlanState ps
Definition: execnodes.h:1210
#define shm_toc_estimate_keys(e, cnt)
Definition: shm_toc.h:53
Size heap_parallelscan_estimate(Snapshot snapshot)
Definition: heapam.c:1607

◆ ExecSeqScanInitializeDSM()

void ExecSeqScanInitializeDSM ( SeqScanState node,
ParallelContext pcxt 
)

Definition at line 291 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().

293 {
294  EState *estate = node->ss.ps.state;
295  ParallelHeapScanDesc pscan;
296 
297  pscan = shm_toc_allocate(pcxt->toc, node->pscan_len);
299  node->ss.ss_currentRelation,
300  estate->es_snapshot);
301  shm_toc_insert(pcxt->toc, node->ss.ps.plan->plan_node_id, pscan);
302  node->ss.ss_currentScanDesc =
304 }
int plan_node_id
Definition: plannodes.h:146
Snapshot es_snapshot
Definition: execnodes.h:479
ScanState ss
Definition: execnodes.h:1222
Relation ss_currentRelation
Definition: execnodes.h:1211
EState * state
Definition: execnodes.h:920
Size pscan_len
Definition: execnodes.h:1223
PlanState ps
Definition: execnodes.h:1210
void heap_parallelscan_initialize(ParallelHeapScanDesc target, Relation relation, Snapshot snapshot)
Definition: heapam.c:1622
Plan * plan
Definition: execnodes.h:918
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition: shm_toc.c:88
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1212
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:1666
shm_toc * toc
Definition: parallel.h:44

◆ ExecSeqScanInitializeWorker()

void ExecSeqScanInitializeWorker ( SeqScanState node,
ParallelWorkerContext pwcxt 
)

Definition at line 328 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().

330 {
331  ParallelHeapScanDesc pscan;
332 
333  pscan = shm_toc_lookup(pwcxt->toc, node->ss.ps.plan->plan_node_id, false);
334  node->ss.ss_currentScanDesc =
336 }
int plan_node_id
Definition: plannodes.h:146
ScanState ss
Definition: execnodes.h:1222
Relation ss_currentRelation
Definition: execnodes.h:1211
PlanState ps
Definition: execnodes.h:1210
Plan * plan
Definition: execnodes.h:918
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1212
HeapScanDesc heap_beginscan_parallel(Relation relation, ParallelHeapScanDesc parallel_scan)
Definition: heapam.c:1666
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 313 of file nodeSeqscan.c.

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

Referenced by ExecParallelReInitializeDSM().

315 {
316  HeapScanDesc scan = node->ss.ss_currentScanDesc;
317 
319 }
ScanState ss
Definition: execnodes.h:1222
ParallelHeapScanDesc rs_parallel
Definition: relscan.h:74
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1212
void heap_parallelscan_reinitialize(ParallelHeapScanDesc parallel_scan)
Definition: heapam.c:1654

◆ SeqNext()

static TupleTableSlot * SeqNext ( SeqScanState node)
static

Definition at line 49 of file nodeSeqscan.c.

References EState::es_direction, EState::es_snapshot, ExecClearTuple(), ExecStoreBufferHeapTuple(), 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 serially
69  * executing a scan that was planned to be parallel.
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 ExecStoreHeapTuple 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  ExecStoreBufferHeapTuple(tuple, /* tuple to store */
92  slot, /* slot to store in */
93  scandesc->rs_cbuf); /* buffer associated
94  * with this tuple */
95  else
96  ExecClearTuple(slot);
97 
98  return slot;
99 }
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:485
Snapshot es_snapshot
Definition: execnodes.h:479
ScanState ss
Definition: execnodes.h:1222
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1213
Relation ss_currentRelation
Definition: execnodes.h:1211
EState * state
Definition: execnodes.h:920
ScanDirection es_direction
Definition: execnodes.h:478
PlanState ps
Definition: execnodes.h:1210
ScanDirection
Definition: sdir.h:22
HeapTuple heap_getnext(HeapScanDesc scan, ScanDirection direction)
Definition: heapam.c:1835
TupleTableSlot * ExecStoreBufferHeapTuple(HeapTuple tuple, TupleTableSlot *slot, Buffer buffer)
Definition: execTuples.c:369
Buffer rs_cbuf
Definition: relscan.h:72
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1212
HeapScanDesc heap_beginscan(Relation relation, Snapshot snapshot, int nkeys, ScanKey key)
Definition: heapam.c:1404

◆ SeqRecheck()

static bool SeqRecheck ( SeqScanState node,
TupleTableSlot slot 
)
static

Definition at line 105 of file nodeSeqscan.c.

Referenced by ExecSeqScan().

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