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)
 
TupleTableSlotExecSeqScan (SeqScanState *node)
 
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 227 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().

228 {
229  Relation relation;
230  HeapScanDesc scanDesc;
231 
232  /*
233  * get information from node
234  */
235  relation = node->ss.ss_currentRelation;
236  scanDesc = node->ss.ss_currentScanDesc;
237 
238  /*
239  * Free the exprcontext
240  */
241  ExecFreeExprContext(&node->ss.ps);
242 
243  /*
244  * clean out the tuple table
245  */
248 
249  /*
250  * close heap scan
251  */
252  if (scanDesc != NULL)
253  heap_endscan(scanDesc);
254 
255  /*
256  * close the heap relation.
257  */
258  ExecCloseScanRelation(relation);
259 }
void heap_endscan(HeapScanDesc scan)
Definition: heapam.c:1580
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:442
ScanState ss
Definition: execnodes.h:1306
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1297
Relation ss_currentRelation
Definition: execnodes.h:1295
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:690
PlanState ps
Definition: execnodes.h:1294
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:1081
#define NULL
Definition: c.h:226
void ExecCloseScanRelation(Relation scanrel)
Definition: execUtils.c:835
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1296
SeqScanState* ExecInitSeqScan ( SeqScan node,
EState estate,
int  eflags 
)

Definition at line 163 of file nodeSeqscan.c.

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

Referenced by ExecInitNode().

164 {
165  SeqScanState *scanstate;
166 
167  /*
168  * Once upon a time it was possible to have an outerPlan of a SeqScan, but
169  * not any more.
170  */
171  Assert(outerPlan(node) == NULL);
172  Assert(innerPlan(node) == NULL);
173 
174  /*
175  * create state structure
176  */
177  scanstate = makeNode(SeqScanState);
178  scanstate->ss.ps.plan = (Plan *) node;
179  scanstate->ss.ps.state = estate;
180 
181  /*
182  * Miscellaneous initialization
183  *
184  * create expression context for node
185  */
186  ExecAssignExprContext(estate, &scanstate->ss.ps);
187 
188  /*
189  * initialize child expressions
190  */
191  scanstate->ss.ps.targetlist = (List *)
192  ExecInitExpr((Expr *) node->plan.targetlist,
193  (PlanState *) scanstate);
194  scanstate->ss.ps.qual = (List *)
195  ExecInitExpr((Expr *) node->plan.qual,
196  (PlanState *) scanstate);
197 
198  /*
199  * tuple table initialization
200  */
201  ExecInitResultTupleSlot(estate, &scanstate->ss.ps);
202  ExecInitScanTupleSlot(estate, &scanstate->ss);
203 
204  /*
205  * initialize scan relation
206  */
207  InitScanRelation(scanstate, estate, eflags);
208 
209  scanstate->ss.ps.ps_TupFromTlist = false;
210 
211  /*
212  * Initialize result tuple type and projection info.
213  */
214  ExecAssignResultTypeFromTL(&scanstate->ss.ps);
215  ExecAssignScanProjectionInfo(&scanstate->ss);
216 
217  return scanstate;
218 }
List * qual
Definition: plannodes.h:130
Plan plan
Definition: plannodes.h:305
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate)
Definition: execTuples.c:845
List * qual
Definition: execnodes.h:1066
static void InitScanRelation(SeqScanState *node, EState *estate, int eflags)
Definition: nodeSeqscan.c:139
List * targetlist
Definition: execnodes.h:1065
ScanState ss
Definition: execnodes.h:1306
EState * state
Definition: execnodes.h:1053
void ExecAssignResultTypeFromTL(PlanState *planstate)
Definition: execUtils.c:429
PlanState ps
Definition: execnodes.h:1294
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
Definition: execQual.c:4562
void ExecAssignScanProjectionInfo(ScanState *node)
Definition: execScan.c:259
void ExecInitResultTupleSlot(EState *estate, PlanState *planstate)
Definition: execTuples.c:835
#define innerPlan(node)
Definition: plannodes.h:158
#define outerPlan(node)
Definition: plannodes.h:159
Plan * plan
Definition: execnodes.h:1051
#define makeNode(_type_)
Definition: nodes.h:551
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:667
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:407
List * targetlist
Definition: plannodes.h:129
bool ps_TupFromTlist
Definition: execnodes.h:1084
Definition: pg_list.h:45
void ExecReScanSeqScan ( SeqScanState node)

Definition at line 273 of file nodeSeqscan.c.

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

Referenced by ExecReScan().

274 {
275  HeapScanDesc scan;
276 
277  scan = node->ss.ss_currentScanDesc;
278 
279  if (scan != NULL)
280  heap_rescan(scan, /* scan desc */
281  NULL); /* new scan keys */
282 
283  ExecScanReScan((ScanState *) node);
284 }
ScanState ss
Definition: execnodes.h:1306
void heap_rescan(HeapScanDesc scan, ScanKey key)
Definition: heapam.c:1517
#define NULL
Definition: c.h:226
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1296
void ExecScanReScan(ScanState *node)
Definition: execScan.c:351
TupleTableSlot* ExecSeqScan ( SeqScanState node)

Definition at line 125 of file nodeSeqscan.c.

References ExecScan(), SeqNext(), and SeqRecheck().

Referenced by ExecProcNode().

126 {
127  return ExecScan((ScanState *) node,
130 }
TupleTableSlot * ExecScan(ScanState *node, ExecScanAccessMtd accessMtd, ExecScanRecheckMtd recheckMtd)
Definition: execScan.c:121
static TupleTableSlot * SeqNext(SeqScanState *node)
Definition: nodeSeqscan.c:49
TupleTableSlot *(* ExecScanAccessMtd)(ScanState *node)
Definition: executor.h:273
bool(* ExecScanRecheckMtd)(ScanState *node, TupleTableSlot *slot)
Definition: executor.h:274
static bool SeqRecheck(SeqScanState *node, TupleTableSlot *slot)
Definition: nodeSeqscan.c:106
void ExecSeqScanEstimate ( SeqScanState node,
ParallelContext pcxt 
)

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

300 {
301  EState *estate = node->ss.ps.state;
302 
305  shm_toc_estimate_keys(&pcxt->estimator, 1);
306 }
shm_toc_estimator estimator
Definition: parallel.h:42
Snapshot es_snapshot
Definition: execnodes.h:367
ScanState ss
Definition: execnodes.h:1306
EState * state
Definition: execnodes.h:1053
#define shm_toc_estimate_chunk(e, sz)
Definition: shm_toc.h:49
Size pscan_len
Definition: execnodes.h:1307
PlanState ps
Definition: execnodes.h:1294
#define shm_toc_estimate_keys(e, cnt)
Definition: shm_toc.h:52
Size heap_parallelscan_estimate(Snapshot snapshot)
Definition: heapam.c:1615
void ExecSeqScanInitializeDSM ( SeqScanState node,
ParallelContext pcxt 
)

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

317 {
318  EState *estate = node->ss.ps.state;
319  ParallelHeapScanDesc pscan;
320 
321  pscan = shm_toc_allocate(pcxt->toc, node->pscan_len);
323  node->ss.ss_currentRelation,
324  estate->es_snapshot);
325  shm_toc_insert(pcxt->toc, node->ss.ps.plan->plan_node_id, pscan);
326  node->ss.ss_currentScanDesc =
328 }
int plan_node_id
Definition: plannodes.h:128
Snapshot es_snapshot
Definition: execnodes.h:367
ScanState ss
Definition: execnodes.h:1306
Relation ss_currentRelation
Definition: execnodes.h:1295
EState * state
Definition: execnodes.h:1053
Size pscan_len
Definition: execnodes.h:1307
PlanState ps
Definition: execnodes.h:1294
void heap_parallelscan_initialize(ParallelHeapScanDesc target, Relation relation, Snapshot snapshot)
Definition: heapam.c:1630
Plan * plan
Definition: execnodes.h:1051
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition: shm_toc.c:83
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1296
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
Definition: shm_toc.c:161
HeapScanDesc heap_beginscan_parallel(Relation relation, ParallelHeapScanDesc parallel_scan)
Definition: heapam.c:1652
shm_toc * toc
Definition: parallel.h:45
void ExecSeqScanInitializeWorker ( SeqScanState node,
shm_toc toc 
)

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

338 {
339  ParallelHeapScanDesc pscan;
340 
341  pscan = shm_toc_lookup(toc, node->ss.ps.plan->plan_node_id);
342  node->ss.ss_currentScanDesc =
344 }
int plan_node_id
Definition: plannodes.h:128
ScanState ss
Definition: execnodes.h:1306
Relation ss_currentRelation
Definition: execnodes.h:1295
PlanState ps
Definition: execnodes.h:1294
void * shm_toc_lookup(shm_toc *toc, uint64 key)
Definition: shm_toc.c:218
Plan * plan
Definition: execnodes.h:1051
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1296
HeapScanDesc heap_beginscan_parallel(Relation relation, ParallelHeapScanDesc parallel_scan)
Definition: heapam.c:1652
static void InitScanRelation ( SeqScanState node,
EState estate,
int  eflags 
)
static

Definition at line 139 of file nodeSeqscan.c.

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

Referenced by ExecInitSeqScan().

140 {
141  Relation currentRelation;
142 
143  /*
144  * get the relation object id from the relid'th entry in the range table,
145  * open that relation and acquire appropriate lock on it.
146  */
147  currentRelation = ExecOpenScanRelation(estate,
148  ((SeqScan *) node->ss.ps.plan)->scanrelid,
149  eflags);
150 
151  node->ss.ss_currentRelation = currentRelation;
152 
153  /* and report the scan tuple slot's rowtype */
154  ExecAssignScanType(&node->ss, RelationGetDescr(currentRelation));
155 }
#define RelationGetDescr(relation)
Definition: rel.h:420
ScanState ss
Definition: execnodes.h:1306
Relation ss_currentRelation
Definition: execnodes.h:1295
PlanState ps
Definition: execnodes.h:1294
Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
Definition: execUtils.c:777
Plan * plan
Definition: execnodes.h:1051
void ExecAssignScanType(ScanState *scanstate, TupleDesc tupDesc)
Definition: execUtils.c:714
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:323
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:442
Snapshot es_snapshot
Definition: execnodes.h:367
ScanState ss
Definition: execnodes.h:1306
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1297
Relation ss_currentRelation
Definition: execnodes.h:1295
EState * state
Definition: execnodes.h:1053
ScanDirection es_direction
Definition: execnodes.h:366
PlanState ps
Definition: execnodes.h:1294
ScanDirection
Definition: sdir.h:22
HeapTuple heap_getnext(HeapScanDesc scan, ScanDirection direction)
Definition: heapam.c:1780
Buffer rs_cbuf
Definition: relscan.h:70
#define NULL
Definition: c.h:226
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1296
HeapScanDesc heap_beginscan(Relation relation, Snapshot snapshot, int nkeys, ScanKey key)
Definition: heapam.c:1393
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 }