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 200 of file nodeSeqscan.c.

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

Referenced by ExecEndNode().

201 {
202  HeapScanDesc scanDesc;
203 
204  /*
205  * get information from node
206  */
207  scanDesc = node->ss.ss_currentScanDesc;
208 
209  /*
210  * Free the exprcontext
211  */
212  ExecFreeExprContext(&node->ss.ps);
213 
214  /*
215  * clean out the tuple table
216  */
217  if (node->ss.ps.ps_ResultTupleSlot)
220 
221  /*
222  * close heap scan
223  */
224  if (scanDesc != NULL)
225  heap_endscan(scanDesc);
226 }
void heap_endscan(HeapScanDesc scan)
Definition: heapam.c:1584
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:404
ScanState ss
Definition: execnodes.h:1281
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1272
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:611
PlanState ps
Definition: execnodes.h:1269
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:970
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1271

◆ ExecInitSeqScan()

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

Definition at line 139 of file nodeSeqscan.c.

References Assert, ExecAssignExprContext(), ExecAssignScanProjectionInfo(), ExecInitQual(), ExecInitResultTypeTL(), 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, PlanState::state, and TTSOpsBufferHeapTuple.

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  * open the scan relation
167  */
168  scanstate->ss.ss_currentRelation =
169  ExecOpenScanRelation(estate,
170  node->scanrelid,
171  eflags);
172 
173  /* and create slot with the appropriate rowtype */
174  ExecInitScanTupleSlot(estate, &scanstate->ss,
177 
178  /*
179  * Initialize result type and projection.
180  */
181  ExecInitResultTypeTL(&scanstate->ss.ps);
182  ExecAssignScanProjectionInfo(&scanstate->ss);
183 
184  /*
185  * initialize child expressions
186  */
187  scanstate->ss.ps.qual =
188  ExecInitQual(node->plan.qual, (PlanState *) scanstate);
189 
190  return scanstate;
191 }
List * qual
Definition: plannodes.h:141
Plan plan
Definition: plannodes.h:339
Index scanrelid
Definition: plannodes.h:340
#define RelationGetDescr(relation)
Definition: rel.h:433
const TupleTableSlotOps TTSOpsBufferHeapTuple
Definition: execTuples.c:83
ScanState ss
Definition: execnodes.h:1281
Relation ss_currentRelation
Definition: execnodes.h:1270
EState * state
Definition: execnodes.h:934
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:206
PlanState ps
Definition: execnodes.h:1269
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:686
#define innerPlan(node)
Definition: plannodes.h:169
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1660
void ExecInitResultTypeTL(PlanState *planstate)
Definition: execTuples.c:1603
#define outerPlan(node)
Definition: plannodes.h:170
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:938
Plan * plan
Definition: execnodes.h:932
#define makeNode(_type_)
Definition: nodes.h:565
#define Assert(condition)
Definition: c.h:732
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:441
ExprState * qual
Definition: execnodes.h:953

◆ ExecReScanSeqScan()

void ExecReScanSeqScan ( SeqScanState node)

Definition at line 240 of file nodeSeqscan.c.

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

Referenced by ExecReScan().

241 {
242  HeapScanDesc scan;
243 
244  scan = node->ss.ss_currentScanDesc;
245 
246  if (scan != NULL)
247  heap_rescan(scan, /* scan desc */
248  NULL); /* new scan keys */
249 
250  ExecScanReScan((ScanState *) node);
251 }
ScanState ss
Definition: execnodes.h:1281
void heap_rescan(HeapScanDesc scan, ScanKey key)
Definition: heapam.c:1540
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1271
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:1281
static TupleTableSlot * SeqNext(SeqScanState *node)
Definition: nodeSeqscan.c:49
bool(* ExecScanRecheckMtd)(ScanState *node, TupleTableSlot *slot)
Definition: executor.h:415
static bool SeqRecheck(SeqScanState *node, TupleTableSlot *slot)
Definition: nodeSeqscan.c:105
TupleTableSlot *(* ExecScanAccessMtd)(ScanState *node)
Definition: executor.h:414

◆ ExecSeqScanEstimate()

void ExecSeqScanEstimate ( SeqScanState node,
ParallelContext pcxt 
)

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

268 {
269  EState *estate = node->ss.ps.state;
270 
273  shm_toc_estimate_keys(&pcxt->estimator, 1);
274 }
shm_toc_estimator estimator
Definition: parallel.h:41
Snapshot es_snapshot
Definition: execnodes.h:489
ScanState ss
Definition: execnodes.h:1281
EState * state
Definition: execnodes.h:934
#define shm_toc_estimate_chunk(e, sz)
Definition: shm_toc.h:51
Size pscan_len
Definition: execnodes.h:1282
PlanState ps
Definition: execnodes.h:1269
#define shm_toc_estimate_keys(e, cnt)
Definition: shm_toc.h:53
Size heap_parallelscan_estimate(Snapshot snapshot)
Definition: heapam.c:1619

◆ ExecSeqScanInitializeDSM()

void ExecSeqScanInitializeDSM ( SeqScanState node,
ParallelContext pcxt 
)

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

285 {
286  EState *estate = node->ss.ps.state;
287  ParallelHeapScanDesc pscan;
288 
289  pscan = shm_toc_allocate(pcxt->toc, node->pscan_len);
291  node->ss.ss_currentRelation,
292  estate->es_snapshot);
293  shm_toc_insert(pcxt->toc, node->ss.ps.plan->plan_node_id, pscan);
294  node->ss.ss_currentScanDesc =
296 }
int plan_node_id
Definition: plannodes.h:139
Snapshot es_snapshot
Definition: execnodes.h:489
ScanState ss
Definition: execnodes.h:1281
Relation ss_currentRelation
Definition: execnodes.h:1270
EState * state
Definition: execnodes.h:934
Size pscan_len
Definition: execnodes.h:1282
PlanState ps
Definition: execnodes.h:1269
void heap_parallelscan_initialize(ParallelHeapScanDesc target, Relation relation, Snapshot snapshot)
Definition: heapam.c:1634
Plan * plan
Definition: execnodes.h:932
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition: shm_toc.c:88
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1271
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:1678
shm_toc * toc
Definition: parallel.h:44

◆ ExecSeqScanInitializeWorker()

void ExecSeqScanInitializeWorker ( SeqScanState node,
ParallelWorkerContext pwcxt 
)

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

322 {
323  ParallelHeapScanDesc pscan;
324 
325  pscan = shm_toc_lookup(pwcxt->toc, node->ss.ps.plan->plan_node_id, false);
326  node->ss.ss_currentScanDesc =
328 }
int plan_node_id
Definition: plannodes.h:139
ScanState ss
Definition: execnodes.h:1281
Relation ss_currentRelation
Definition: execnodes.h:1270
PlanState ps
Definition: execnodes.h:1269
Plan * plan
Definition: execnodes.h:932
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1271
HeapScanDesc heap_beginscan_parallel(Relation relation, ParallelHeapScanDesc parallel_scan)
Definition: heapam.c:1678
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 305 of file nodeSeqscan.c.

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

Referenced by ExecParallelReInitializeDSM().

307 {
308  HeapScanDesc scan = node->ss.ss_currentScanDesc;
309 
311 }
ScanState ss
Definition: execnodes.h:1281
ParallelHeapScanDesc rs_parallel
Definition: relscan.h:74
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1271
void heap_parallelscan_reinitialize(ParallelHeapScanDesc parallel_scan)
Definition: heapam.c:1666

◆ 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 }
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:404
Snapshot es_snapshot
Definition: execnodes.h:489
ScanState ss
Definition: execnodes.h:1281
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1272
Relation ss_currentRelation
Definition: execnodes.h:1270
EState * state
Definition: execnodes.h:934
ScanDirection es_direction
Definition: execnodes.h:488
PlanState ps
Definition: execnodes.h:1269
ScanDirection
Definition: sdir.h:22
HeapTuple heap_getnext(HeapScanDesc scan, ScanDirection direction)
Definition: heapam.c:1847
TupleTableSlot * ExecStoreBufferHeapTuple(HeapTuple tuple, TupleTableSlot *slot, Buffer buffer)
Definition: execTuples.c:1310
Buffer rs_cbuf
Definition: relscan.h:72
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1271
HeapScanDesc heap_beginscan(Relation relation, Snapshot snapshot, int nkeys, ScanKey key)
Definition: heapam.c:1416

◆ 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 }