PostgreSQL Source Code  git master
nodeSeqscan.c File Reference
#include "postgres.h"
#include "access/relscan.h"
#include "access/tableam.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 184 of file nodeSeqscan.c.

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

Referenced by ExecEndNode().

185 {
186  TableScanDesc scanDesc;
187 
188  /*
189  * get information from node
190  */
191  scanDesc = node->ss.ss_currentScanDesc;
192 
193  /*
194  * Free the exprcontext
195  */
196  ExecFreeExprContext(&node->ss.ps);
197 
198  /*
199  * clean out the tuple table
200  */
201  if (node->ss.ps.ps_ResultTupleSlot)
204 
205  /*
206  * close heap scan
207  */
208  if (scanDesc != NULL)
209  table_endscan(scanDesc);
210 }
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:426
struct TableScanDescData * ss_currentScanDesc
Definition: execnodes.h:1282
ScanState ss
Definition: execnodes.h:1292
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1283
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:617
PlanState ps
Definition: execnodes.h:1280
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:983
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:763

◆ ExecInitSeqScan()

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

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

Referenced by ExecInitNode().

124 {
125  SeqScanState *scanstate;
126 
127  /*
128  * Once upon a time it was possible to have an outerPlan of a SeqScan, but
129  * not any more.
130  */
131  Assert(outerPlan(node) == NULL);
132  Assert(innerPlan(node) == NULL);
133 
134  /*
135  * create state structure
136  */
137  scanstate = makeNode(SeqScanState);
138  scanstate->ss.ps.plan = (Plan *) node;
139  scanstate->ss.ps.state = estate;
140  scanstate->ss.ps.ExecProcNode = ExecSeqScan;
141 
142  /*
143  * Miscellaneous initialization
144  *
145  * create expression context for node
146  */
147  ExecAssignExprContext(estate, &scanstate->ss.ps);
148 
149  /*
150  * open the scan relation
151  */
152  scanstate->ss.ss_currentRelation =
153  ExecOpenScanRelation(estate,
154  node->scanrelid,
155  eflags);
156 
157  /* and create slot with the appropriate rowtype */
158  ExecInitScanTupleSlot(estate, &scanstate->ss,
161 
162  /*
163  * Initialize result type and projection.
164  */
165  ExecInitResultTypeTL(&scanstate->ss.ps);
166  ExecAssignScanProjectionInfo(&scanstate->ss);
167 
168  /*
169  * initialize child expressions
170  */
171  scanstate->ss.ps.qual =
172  ExecInitQual(node->plan.qual, (PlanState *) scanstate);
173 
174  return scanstate;
175 }
List * qual
Definition: plannodes.h:141
Plan plan
Definition: plannodes.h:340
Index scanrelid
Definition: plannodes.h:341
#define RelationGetDescr(relation)
Definition: rel.h:440
const TupleTableSlotOps * table_slot_callbacks(Relation relation)
Definition: tableam.c:40
ScanState ss
Definition: execnodes.h:1292
Relation ss_currentRelation
Definition: execnodes.h:1281
EState * state
Definition: execnodes.h:947
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:206
PlanState ps
Definition: execnodes.h:1280
static TupleTableSlot * ExecSeqScan(PlanState *pstate)
Definition: nodeSeqscan.c:108
void ExecAssignScanProjectionInfo(ScanState *node)
Definition: execScan.c:233
Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
Definition: execUtils.c:696
#define innerPlan(node)
Definition: plannodes.h:169
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1774
void ExecInitResultTypeTL(PlanState *planstate)
Definition: execTuples.c:1718
#define outerPlan(node)
Definition: plannodes.h:170
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:951
Plan * plan
Definition: execnodes.h:945
#define makeNode(_type_)
Definition: nodes.h:572
#define Assert(condition)
Definition: c.h:732
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:447
ExprState * qual
Definition: execnodes.h:966

◆ ExecReScanSeqScan()

void ExecReScanSeqScan ( SeqScanState node)

Definition at line 224 of file nodeSeqscan.c.

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

Referenced by ExecReScan().

225 {
226  TableScanDesc scan;
227 
228  scan = node->ss.ss_currentScanDesc;
229 
230  if (scan != NULL)
231  table_rescan(scan, /* scan desc */
232  NULL); /* new scan keys */
233 
234  ExecScanReScan((ScanState *) node);
235 }
struct TableScanDescData * ss_currentScanDesc
Definition: execnodes.h:1282
ScanState ss
Definition: execnodes.h:1292
static void table_rescan(TableScanDesc scan, struct ScanKeyData *key)
Definition: tableam.h:772
void ExecScanReScan(ScanState *node)
Definition: execScan.c:260

◆ ExecSeqScan()

static TupleTableSlot* ExecSeqScan ( PlanState pstate)
static

Definition at line 108 of file nodeSeqscan.c.

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

Referenced by ExecInitSeqScan().

109 {
110  SeqScanState *node = castNode(SeqScanState, pstate);
111 
112  return ExecScan(&node->ss,
115 }
#define castNode(_type_, nodeptr)
Definition: nodes.h:593
TupleTableSlot * ExecScan(ScanState *node, ExecScanAccessMtd accessMtd, ExecScanRecheckMtd recheckMtd)
Definition: execScan.c:119
ScanState ss
Definition: execnodes.h:1292
static TupleTableSlot * SeqNext(SeqScanState *node)
Definition: nodeSeqscan.c:50
bool(* ExecScanRecheckMtd)(ScanState *node, TupleTableSlot *slot)
Definition: executor.h:425
static bool SeqRecheck(SeqScanState *node, TupleTableSlot *slot)
Definition: nodeSeqscan.c:89
TupleTableSlot *(* ExecScanAccessMtd)(ScanState *node)
Definition: executor.h:424

◆ ExecSeqScanEstimate()

void ExecSeqScanEstimate ( SeqScanState node,
ParallelContext pcxt 
)

Definition at line 250 of file nodeSeqscan.c.

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

Referenced by ExecParallelEstimate().

252 {
253  EState *estate = node->ss.ps.state;
254 
256  estate->es_snapshot);
258  shm_toc_estimate_keys(&pcxt->estimator, 1);
259 }
shm_toc_estimator estimator
Definition: parallel.h:41
Snapshot es_snapshot
Definition: execnodes.h:502
ScanState ss
Definition: execnodes.h:1292
Relation ss_currentRelation
Definition: execnodes.h:1281
EState * state
Definition: execnodes.h:947
#define shm_toc_estimate_chunk(e, sz)
Definition: shm_toc.h:51
Size pscan_len
Definition: execnodes.h:1293
PlanState ps
Definition: execnodes.h:1280
Size table_parallelscan_estimate(Relation rel, Snapshot snapshot)
Definition: tableam.c:121
#define shm_toc_estimate_keys(e, cnt)
Definition: shm_toc.h:53

◆ ExecSeqScanInitializeDSM()

void ExecSeqScanInitializeDSM ( SeqScanState node,
ParallelContext pcxt 
)

Definition at line 268 of file nodeSeqscan.c.

References EState::es_snapshot, 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, table_beginscan_parallel(), table_parallelscan_initialize(), and ParallelContext::toc.

Referenced by ExecParallelInitializeDSM().

270 {
271  EState *estate = node->ss.ps.state;
272  ParallelTableScanDesc pscan;
273 
274  pscan = shm_toc_allocate(pcxt->toc, node->pscan_len);
276  pscan,
277  estate->es_snapshot);
278  shm_toc_insert(pcxt->toc, node->ss.ps.plan->plan_node_id, pscan);
279  node->ss.ss_currentScanDesc =
281 }
int plan_node_id
Definition: plannodes.h:139
struct TableScanDescData * ss_currentScanDesc
Definition: execnodes.h:1282
Snapshot es_snapshot
Definition: execnodes.h:502
ScanState ss
Definition: execnodes.h:1292
Relation ss_currentRelation
Definition: execnodes.h:1281
EState * state
Definition: execnodes.h:947
Size pscan_len
Definition: execnodes.h:1293
PlanState ps
Definition: execnodes.h:1280
TableScanDesc table_beginscan_parallel(Relation relation, ParallelTableScanDesc parallel_scan)
Definition: tableam.c:156
Plan * plan
Definition: execnodes.h:945
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition: shm_toc.c:88
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
Definition: shm_toc.c:171
void table_parallelscan_initialize(Relation rel, ParallelTableScanDesc pscan, Snapshot snapshot)
Definition: tableam.c:136
shm_toc * toc
Definition: parallel.h:44

◆ ExecSeqScanInitializeWorker()

void ExecSeqScanInitializeWorker ( SeqScanState node,
ParallelWorkerContext pwcxt 
)

Definition at line 306 of file nodeSeqscan.c.

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

Referenced by ExecParallelInitializeWorker().

308 {
309  ParallelTableScanDesc pscan;
310 
311  pscan = shm_toc_lookup(pwcxt->toc, node->ss.ps.plan->plan_node_id, false);
312  node->ss.ss_currentScanDesc =
314 }
int plan_node_id
Definition: plannodes.h:139
struct TableScanDescData * ss_currentScanDesc
Definition: execnodes.h:1282
ScanState ss
Definition: execnodes.h:1292
Relation ss_currentRelation
Definition: execnodes.h:1281
PlanState ps
Definition: execnodes.h:1280
TableScanDesc table_beginscan_parallel(Relation relation, ParallelTableScanDesc parallel_scan)
Definition: tableam.c:156
Plan * plan
Definition: execnodes.h:945
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 290 of file nodeSeqscan.c.

References TableScanDescData::rs_parallel, SeqScanState::ss, ScanState::ss_currentRelation, ScanState::ss_currentScanDesc, and table_parallelscan_reinitialize().

Referenced by ExecParallelReInitializeDSM().

292 {
293  ParallelTableScanDesc pscan;
294 
295  pscan = node->ss.ss_currentScanDesc->rs_parallel;
297 }
struct TableScanDescData * ss_currentScanDesc
Definition: execnodes.h:1282
ScanState ss
Definition: execnodes.h:1292
Relation ss_currentRelation
Definition: execnodes.h:1281
static void table_parallelscan_reinitialize(Relation rel, ParallelTableScanDesc pscan)
Definition: tableam.h:848
struct ParallelTableScanDescData * rs_parallel
Definition: relscan.h:46

◆ SeqNext()

static TupleTableSlot * SeqNext ( SeqScanState node)
static

Definition at line 50 of file nodeSeqscan.c.

References EState::es_direction, EState::es_snapshot, ScanState::ps, SeqScanState::ss, ScanState::ss_currentRelation, ScanState::ss_currentScanDesc, ScanState::ss_ScanTupleSlot, PlanState::state, table_beginscan(), and table_scan_getnextslot().

Referenced by ExecSeqScan().

51 {
52  TableScanDesc 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 = table_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  if (table_scan_getnextslot(scandesc, direction, slot))
81  return slot;
82  return NULL;
83 }
struct TableScanDescData * ss_currentScanDesc
Definition: execnodes.h:1282
Snapshot es_snapshot
Definition: execnodes.h:502
ScanState ss
Definition: execnodes.h:1292
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1283
Relation ss_currentRelation
Definition: execnodes.h:1281
EState * state
Definition: execnodes.h:947
static bool table_scan_getnextslot(TableScanDesc sscan, ScanDirection direction, TupleTableSlot *slot)
Definition: tableam.h:804
ScanDirection es_direction
Definition: execnodes.h:501
PlanState ps
Definition: execnodes.h:1280
static TableScanDesc table_beginscan(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key)
Definition: tableam.h:683
ScanDirection
Definition: sdir.h:22

◆ SeqRecheck()

static bool SeqRecheck ( SeqScanState node,
TupleTableSlot slot 
)
static

Definition at line 89 of file nodeSeqscan.c.

Referenced by ExecSeqScan().

90 {
91  /*
92  * Note that unlike IndexScan, SeqScan never use keys in heap_beginscan
93  * (and this is very bad) - so, here we do not check are keys ok or not.
94  */
95  return true;
96 }