PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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 void InitScanRelation (SeqScanState *node, EState *estate, int eflags)
 
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 ExecSeqScanInitializeWorker (SeqScanState *node, shm_toc *toc)
 

Function Documentation

void ExecEndSeqScan ( SeqScanState node)

Definition at line 224 of file nodeSeqscan.c.

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

Referenced by ExecEndNode().

225 {
226  Relation relation;
227  HeapScanDesc scanDesc;
228 
229  /*
230  * get information from node
231  */
232  relation = node->ss.ss_currentRelation;
233  scanDesc = node->ss.ss_currentScanDesc;
234 
235  /*
236  * Free the exprcontext
237  */
238  ExecFreeExprContext(&node->ss.ps);
239 
240  /*
241  * clean out the tuple table
242  */
245 
246  /*
247  * close heap scan
248  */
249  if (scanDesc != NULL)
250  heap_endscan(scanDesc);
251 
252  /*
253  * close the heap relation.
254  */
255  ExecCloseScanRelation(relation);
256 }
void heap_endscan(HeapScanDesc scan)
Definition: heapam.c:1580
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
ScanState ss
Definition: execnodes.h:1110
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1101
Relation ss_currentRelation
Definition: execnodes.h:1099
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:521
PlanState ps
Definition: execnodes.h:1098
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:880
#define NULL
Definition: c.h:229
void ExecCloseScanRelation(Relation scanrel)
Definition: execUtils.c:666
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1100
SeqScanState* ExecInitSeqScan ( SeqScan node,
EState estate,
int  eflags 
)

Definition at line 165 of file nodeSeqscan.c.

References Assert, ExecAssignExprContext(), ExecAssignResultTypeFromTL(), ExecAssignScanProjectionInfo(), ExecInitQual(), ExecInitResultTupleSlot(), ExecInitScanTupleSlot(), PlanState::ExecProcNode, ExecSeqScan(), InitScanRelation(), innerPlan, makeNode, NULL, outerPlan, Scan::plan, PlanState::plan, ScanState::ps, Plan::qual, PlanState::qual, SeqScanState::ss, and PlanState::state.

Referenced by ExecInitNode().

166 {
167  SeqScanState *scanstate;
168 
169  /*
170  * Once upon a time it was possible to have an outerPlan of a SeqScan, but
171  * not any more.
172  */
173  Assert(outerPlan(node) == NULL);
174  Assert(innerPlan(node) == NULL);
175 
176  /*
177  * create state structure
178  */
179  scanstate = makeNode(SeqScanState);
180  scanstate->ss.ps.plan = (Plan *) node;
181  scanstate->ss.ps.state = estate;
182  scanstate->ss.ps.ExecProcNode = ExecSeqScan;
183 
184  /*
185  * Miscellaneous initialization
186  *
187  * create expression context for node
188  */
189  ExecAssignExprContext(estate, &scanstate->ss.ps);
190 
191  /*
192  * initialize child expressions
193  */
194  scanstate->ss.ps.qual =
195  ExecInitQual(node->plan.qual, (PlanState *) scanstate);
196 
197  /*
198  * tuple table initialization
199  */
200  ExecInitResultTupleSlot(estate, &scanstate->ss.ps);
201  ExecInitScanTupleSlot(estate, &scanstate->ss);
202 
203  /*
204  * initialize scan relation
205  */
206  InitScanRelation(scanstate, estate, eflags);
207 
208  /*
209  * Initialize result tuple type and projection info.
210  */
211  ExecAssignResultTypeFromTL(&scanstate->ss.ps);
212  ExecAssignScanProjectionInfo(&scanstate->ss);
213 
214  return scanstate;
215 }
List * qual
Definition: plannodes.h:145
Plan plan
Definition: plannodes.h:328
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate)
Definition: execTuples.c:842
static void InitScanRelation(SeqScanState *node, EState *estate, int eflags)
Definition: nodeSeqscan.c:141
ScanState ss
Definition: execnodes.h:1110
EState * state
Definition: execnodes.h:849
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:160
void ExecAssignResultTypeFromTL(PlanState *planstate)
Definition: execUtils.c:445
PlanState ps
Definition: execnodes.h:1098
static TupleTableSlot * ExecSeqScan(PlanState *pstate)
Definition: nodeSeqscan.c:125
void ExecAssignScanProjectionInfo(ScanState *node)
Definition: execScan.c:235
void ExecInitResultTupleSlot(EState *estate, PlanState *planstate)
Definition: execTuples.c:832
#define innerPlan(node)
Definition: plannodes.h:173
#define outerPlan(node)
Definition: plannodes.h:174
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:853
Plan * plan
Definition: execnodes.h:847
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:676
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:423
ExprState * qual
Definition: execnodes.h:865
void ExecReScanSeqScan ( SeqScanState node)

Definition at line 270 of file nodeSeqscan.c.

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

Referenced by ExecReScan().

271 {
272  HeapScanDesc scan;
273 
274  scan = node->ss.ss_currentScanDesc;
275 
276  if (scan != NULL)
277  heap_rescan(scan, /* scan desc */
278  NULL); /* new scan keys */
279 
280  ExecScanReScan((ScanState *) node);
281 }
ScanState ss
Definition: execnodes.h:1110
void heap_rescan(HeapScanDesc scan, ScanKey key)
Definition: heapam.c:1521
#define NULL
Definition: c.h:229
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1100
void ExecScanReScan(ScanState *node)
Definition: execScan.c:327
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:578
TupleTableSlot * ExecScan(ScanState *node, ExecScanAccessMtd accessMtd, ExecScanRecheckMtd recheckMtd)
Definition: execScan.c:121
ScanState ss
Definition: execnodes.h:1110
static TupleTableSlot * SeqNext(SeqScanState *node)
Definition: nodeSeqscan.c:49
TupleTableSlot *(* ExecScanAccessMtd)(ScanState *node)
Definition: executor.h:408
bool(* ExecScanRecheckMtd)(ScanState *node, TupleTableSlot *slot)
Definition: executor.h:409
static bool SeqRecheck(SeqScanState *node, TupleTableSlot *slot)
Definition: nodeSeqscan.c:106
void ExecSeqScanEstimate ( SeqScanState node,
ParallelContext pcxt 
)

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

297 {
298  EState *estate = node->ss.ps.state;
299 
302  shm_toc_estimate_keys(&pcxt->estimator, 1);
303 }
shm_toc_estimator estimator
Definition: parallel.h:41
Snapshot es_snapshot
Definition: execnodes.h:429
ScanState ss
Definition: execnodes.h:1110
EState * state
Definition: execnodes.h:849
#define shm_toc_estimate_chunk(e, sz)
Definition: shm_toc.h:51
Size pscan_len
Definition: execnodes.h:1111
PlanState ps
Definition: execnodes.h:1098
#define shm_toc_estimate_keys(e, cnt)
Definition: shm_toc.h:53
Size heap_parallelscan_estimate(Snapshot snapshot)
Definition: heapam.c:1615
void ExecSeqScanInitializeDSM ( SeqScanState node,
ParallelContext pcxt 
)

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

314 {
315  EState *estate = node->ss.ps.state;
316  ParallelHeapScanDesc pscan;
317 
318  pscan = shm_toc_allocate(pcxt->toc, node->pscan_len);
320  node->ss.ss_currentRelation,
321  estate->es_snapshot);
322  shm_toc_insert(pcxt->toc, node->ss.ps.plan->plan_node_id, pscan);
323  node->ss.ss_currentScanDesc =
325 }
int plan_node_id
Definition: plannodes.h:143
Snapshot es_snapshot
Definition: execnodes.h:429
ScanState ss
Definition: execnodes.h:1110
Relation ss_currentRelation
Definition: execnodes.h:1099
EState * state
Definition: execnodes.h:849
Size pscan_len
Definition: execnodes.h:1111
PlanState ps
Definition: execnodes.h:1098
void heap_parallelscan_initialize(ParallelHeapScanDesc target, Relation relation, Snapshot snapshot)
Definition: heapam.c:1630
Plan * plan
Definition: execnodes.h:847
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition: shm_toc.c:88
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1100
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:1652
shm_toc * toc
Definition: parallel.h:44
void ExecSeqScanInitializeWorker ( SeqScanState node,
shm_toc toc 
)

Definition at line 334 of file nodeSeqscan.c.

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

Referenced by ExecParallelInitializeWorker().

335 {
336  ParallelHeapScanDesc pscan;
337 
338  pscan = shm_toc_lookup(toc, node->ss.ps.plan->plan_node_id, false);
339  node->ss.ss_currentScanDesc =
341 }
int plan_node_id
Definition: plannodes.h:143
ScanState ss
Definition: execnodes.h:1110
Relation ss_currentRelation
Definition: execnodes.h:1099
PlanState ps
Definition: execnodes.h:1098
Plan * plan
Definition: execnodes.h:847
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1100
HeapScanDesc heap_beginscan_parallel(Relation relation, ParallelHeapScanDesc parallel_scan)
Definition: heapam.c:1652
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232
static void InitScanRelation ( SeqScanState node,
EState estate,
int  eflags 
)
static

Definition at line 141 of file nodeSeqscan.c.

References ExecAssignScanType(), ExecOpenScanRelation(), PlanState::plan, ScanState::ps, RelationGetDescr, SeqScanState::ss, and ScanState::ss_currentRelation.

Referenced by ExecInitSeqScan().

142 {
143  Relation currentRelation;
144 
145  /*
146  * get the relation object id from the relid'th entry in the range table,
147  * open that relation and acquire appropriate lock on it.
148  */
149  currentRelation = ExecOpenScanRelation(estate,
150  ((SeqScan *) node->ss.ps.plan)->scanrelid,
151  eflags);
152 
153  node->ss.ss_currentRelation = currentRelation;
154 
155  /* and report the scan tuple slot's rowtype */
156  ExecAssignScanType(&node->ss, RelationGetDescr(currentRelation));
157 }
#define RelationGetDescr(relation)
Definition: rel.h:428
ScanState ss
Definition: execnodes.h:1110
Relation ss_currentRelation
Definition: execnodes.h:1099
PlanState ps
Definition: execnodes.h:1098
Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
Definition: execUtils.c:608
Plan * plan
Definition: execnodes.h:847
void ExecAssignScanType(ScanState *scanstate, TupleDesc tupDesc)
Definition: execUtils.c:545
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(), NULL, 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:320
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
Snapshot es_snapshot
Definition: execnodes.h:429
ScanState ss
Definition: execnodes.h:1110
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1101
Relation ss_currentRelation
Definition: execnodes.h:1099
EState * state
Definition: execnodes.h:849
ScanDirection es_direction
Definition: execnodes.h:428
PlanState ps
Definition: execnodes.h:1098
ScanDirection
Definition: sdir.h:22
HeapTuple heap_getnext(HeapScanDesc scan, ScanDirection direction)
Definition: heapam.c:1810
Buffer rs_cbuf
Definition: relscan.h:71
#define NULL
Definition: c.h:229
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1100
HeapScanDesc heap_beginscan(Relation relation, Snapshot snapshot, int nkeys, ScanKey key)
Definition: heapam.c:1397
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 }