PostgreSQL Source Code git master
nodeSeqscan.c File Reference
#include "postgres.h"
#include "access/relscan.h"
#include "access/tableam.h"
#include "executor/execScan.h"
#include "executor/executor.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)
 
static TupleTableSlotExecSeqScanWithQual (PlanState *pstate)
 
static TupleTableSlotExecSeqScanWithProject (PlanState *pstate)
 
static TupleTableSlotExecSeqScanWithQualProject (PlanState *pstate)
 
static TupleTableSlotExecSeqScanEPQ (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 289 of file nodeSeqscan.c.

290{
291 TableScanDesc scanDesc;
292
293 /*
294 * get information from node
295 */
296 scanDesc = node->ss.ss_currentScanDesc;
297
298 /*
299 * close heap scan
300 */
301 if (scanDesc != NULL)
302 table_endscan(scanDesc);
303}
struct TableScanDescData * ss_currentScanDesc
Definition: execnodes.h:1605
ScanState ss
Definition: execnodes.h:1615
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:1025

References SeqScanState::ss, ScanState::ss_currentScanDesc, and table_endscan().

Referenced by ExecEndNode().

◆ ExecInitSeqScan()

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

Definition at line 207 of file nodeSeqscan.c.

208{
209 SeqScanState *scanstate;
210
211 /*
212 * Once upon a time it was possible to have an outerPlan of a SeqScan, but
213 * not any more.
214 */
215 Assert(outerPlan(node) == NULL);
216 Assert(innerPlan(node) == NULL);
217
218 /*
219 * create state structure
220 */
221 scanstate = makeNode(SeqScanState);
222 scanstate->ss.ps.plan = (Plan *) node;
223 scanstate->ss.ps.state = estate;
224
225 /*
226 * Miscellaneous initialization
227 *
228 * create expression context for node
229 */
230 ExecAssignExprContext(estate, &scanstate->ss.ps);
231
232 /*
233 * open the scan relation
234 */
235 scanstate->ss.ss_currentRelation =
237 node->scan.scanrelid,
238 eflags);
239
240 /* and create slot with the appropriate rowtype */
241 ExecInitScanTupleSlot(estate, &scanstate->ss,
244
245 /*
246 * Initialize result type and projection.
247 */
248 ExecInitResultTypeTL(&scanstate->ss.ps);
249 ExecAssignScanProjectionInfo(&scanstate->ss);
250
251 /*
252 * initialize child expressions
253 */
254 scanstate->ss.ps.qual =
255 ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
256
257 /*
258 * When EvalPlanQual() is not in use, assign ExecProcNode for this node
259 * based on the presence of qual and projection. Each ExecSeqScan*()
260 * variant is optimized for the specific combination of these conditions.
261 */
262 if (scanstate->ss.ps.state->es_epq_active != NULL)
263 scanstate->ss.ps.ExecProcNode = ExecSeqScanEPQ;
264 else if (scanstate->ss.ps.qual == NULL)
265 {
266 if (scanstate->ss.ps.ps_ProjInfo == NULL)
267 scanstate->ss.ps.ExecProcNode = ExecSeqScan;
268 else
270 }
271 else
272 {
273 if (scanstate->ss.ps.ps_ProjInfo == NULL)
275 else
277 }
278
279 return scanstate;
280}
#define Assert(condition)
Definition: c.h:815
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:229
void ExecAssignScanProjectionInfo(ScanState *node)
Definition: execScan.c:81
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1998
void ExecInitResultTypeTL(PlanState *planstate)
Definition: execTuples.c:1942
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:486
Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
Definition: execUtils.c:743
static TupleTableSlot * ExecSeqScanWithQual(PlanState *pstate)
Definition: nodeSeqscan.c:130
static TupleTableSlot * ExecSeqScanWithQualProject(PlanState *pstate)
Definition: nodeSeqscan.c:171
static TupleTableSlot * ExecSeqScan(PlanState *pstate)
Definition: nodeSeqscan.c:110
static TupleTableSlot * ExecSeqScanEPQ(PlanState *pstate)
Definition: nodeSeqscan.c:193
static TupleTableSlot * ExecSeqScanWithProject(PlanState *pstate)
Definition: nodeSeqscan.c:150
#define makeNode(_type_)
Definition: nodes.h:155
#define innerPlan(node)
Definition: plannodes.h:230
#define outerPlan(node)
Definition: plannodes.h:231
#define RelationGetDescr(relation)
Definition: rel.h:538
struct EPQState * es_epq_active
Definition: execnodes.h:732
ExprState * qual
Definition: execnodes.h:1171
Plan * plan
Definition: execnodes.h:1150
EState * state
Definition: execnodes.h:1152
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:1190
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1156
Relation ss_currentRelation
Definition: execnodes.h:1604
PlanState ps
Definition: execnodes.h:1603
Index scanrelid
Definition: plannodes.h:473
Scan scan
Definition: plannodes.h:482
const TupleTableSlotOps * table_slot_callbacks(Relation relation)
Definition: tableam.c:58

References Assert, EState::es_epq_active, ExecAssignExprContext(), ExecAssignScanProjectionInfo(), ExecInitQual(), ExecInitResultTypeTL(), ExecInitScanTupleSlot(), ExecOpenScanRelation(), PlanState::ExecProcNode, ExecSeqScan(), ExecSeqScanEPQ(), ExecSeqScanWithProject(), ExecSeqScanWithQual(), ExecSeqScanWithQualProject(), innerPlan, makeNode, outerPlan, PlanState::plan, ScanState::ps, PlanState::ps_ProjInfo, PlanState::qual, RelationGetDescr, SeqScan::scan, Scan::scanrelid, SeqScanState::ss, ScanState::ss_currentRelation, PlanState::state, and table_slot_callbacks().

Referenced by ExecInitNode().

◆ ExecReScanSeqScan()

void ExecReScanSeqScan ( SeqScanState node)

Definition at line 317 of file nodeSeqscan.c.

318{
319 TableScanDesc scan;
320
321 scan = node->ss.ss_currentScanDesc;
322
323 if (scan != NULL)
324 table_rescan(scan, /* scan desc */
325 NULL); /* new scan keys */
326
327 ExecScanReScan((ScanState *) node);
328}
void ExecScanReScan(ScanState *node)
Definition: execScan.c:108
static void table_rescan(TableScanDesc scan, struct ScanKeyData *key)
Definition: tableam.h:1034

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

Referenced by ExecReScan().

◆ ExecSeqScan()

static TupleTableSlot * ExecSeqScan ( PlanState pstate)
static

Definition at line 110 of file nodeSeqscan.c.

111{
112 SeqScanState *node = castNode(SeqScanState, pstate);
113
114 Assert(pstate->state->es_epq_active == NULL);
115 Assert(pstate->qual == NULL);
116 Assert(pstate->ps_ProjInfo == NULL);
117
118 return ExecScanExtended(&node->ss,
121 NULL,
122 NULL,
123 NULL);
124}
static pg_attribute_always_inline TupleTableSlot * ExecScanExtended(ScanState *node, ExecScanAccessMtd accessMtd, ExecScanRecheckMtd recheckMtd, EPQState *epqstate, ExprState *qual, ProjectionInfo *projInfo)
Definition: execScan.h:152
bool(* ExecScanRecheckMtd)(ScanState *node, TupleTableSlot *slot)
Definition: executor.h:487
TupleTableSlot *(* ExecScanAccessMtd)(ScanState *node)
Definition: executor.h:486
static bool SeqRecheck(SeqScanState *node, TupleTableSlot *slot)
Definition: nodeSeqscan.c:90
static TupleTableSlot * SeqNext(SeqScanState *node)
Definition: nodeSeqscan.c:51
#define castNode(_type_, nodeptr)
Definition: nodes.h:176

References Assert, castNode, EState::es_epq_active, ExecScanExtended(), PlanState::ps_ProjInfo, PlanState::qual, SeqNext(), SeqRecheck(), SeqScanState::ss, and PlanState::state.

Referenced by ExecInitSeqScan().

◆ ExecSeqScanEPQ()

static TupleTableSlot * ExecSeqScanEPQ ( PlanState pstate)
static

Definition at line 193 of file nodeSeqscan.c.

194{
195 SeqScanState *node = castNode(SeqScanState, pstate);
196
197 return ExecScan(&node->ss,
200}
TupleTableSlot * ExecScan(ScanState *node, ExecScanAccessMtd accessMtd, ExecScanRecheckMtd recheckMtd)
Definition: execScan.c:47

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

Referenced by ExecInitSeqScan().

◆ ExecSeqScanEstimate()

void ExecSeqScanEstimate ( SeqScanState node,
ParallelContext pcxt 
)

Definition at line 343 of file nodeSeqscan.c.

345{
346 EState *estate = node->ss.ps.state;
347
349 estate->es_snapshot);
352}
#define shm_toc_estimate_chunk(e, sz)
Definition: shm_toc.h:51
#define shm_toc_estimate_keys(e, cnt)
Definition: shm_toc.h:53
Snapshot es_snapshot
Definition: execnodes.h:650
shm_toc_estimator estimator
Definition: parallel.h:41
Size pscan_len
Definition: execnodes.h:1616
Size table_parallelscan_estimate(Relation rel, Snapshot snapshot)
Definition: tableam.c:130

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

◆ ExecSeqScanInitializeDSM()

void ExecSeqScanInitializeDSM ( SeqScanState node,
ParallelContext pcxt 
)

Definition at line 361 of file nodeSeqscan.c.

363{
364 EState *estate = node->ss.ps.state;
366
367 pscan = shm_toc_allocate(pcxt->toc, node->pscan_len);
369 pscan,
370 estate->es_snapshot);
371 shm_toc_insert(pcxt->toc, node->ss.ps.plan->plan_node_id, pscan);
372 node->ss.ss_currentScanDesc =
374}
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
shm_toc * toc
Definition: parallel.h:44
int plan_node_id
Definition: plannodes.h:197
TableScanDesc table_beginscan_parallel(Relation relation, ParallelTableScanDesc pscan)
Definition: tableam.c:165
void table_parallelscan_initialize(Relation rel, ParallelTableScanDesc pscan, Snapshot snapshot)
Definition: tableam.c:145

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

◆ ExecSeqScanInitializeWorker()

void ExecSeqScanInitializeWorker ( SeqScanState node,
ParallelWorkerContext pwcxt 
)

Definition at line 399 of file nodeSeqscan.c.

401{
403
404 pscan = shm_toc_lookup(pwcxt->toc, node->ss.ps.plan->plan_node_id, false);
405 node->ss.ss_currentScanDesc =
407}
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232

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

◆ ExecSeqScanReInitializeDSM()

void ExecSeqScanReInitializeDSM ( SeqScanState node,
ParallelContext pcxt 
)

Definition at line 383 of file nodeSeqscan.c.

385{
387
388 pscan = node->ss.ss_currentScanDesc->rs_parallel;
390}
struct ParallelTableScanDescData * rs_parallel
Definition: relscan.h:66
static void table_parallelscan_reinitialize(Relation rel, ParallelTableScanDesc pscan)
Definition: tableam.h:1180

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

Referenced by ExecParallelReInitializeDSM().

◆ ExecSeqScanWithProject()

static TupleTableSlot * ExecSeqScanWithProject ( PlanState pstate)
static

Definition at line 150 of file nodeSeqscan.c.

151{
152 SeqScanState *node = castNode(SeqScanState, pstate);
153
154 Assert(pstate->state->es_epq_active == NULL);
155 Assert(pstate->qual == NULL);
156 Assert(pstate->ps_ProjInfo != NULL);
157
158 return ExecScanExtended(&node->ss,
161 NULL,
162 NULL,
163 pstate->ps_ProjInfo);
164}

References Assert, castNode, EState::es_epq_active, ExecScanExtended(), PlanState::ps_ProjInfo, PlanState::qual, SeqNext(), SeqRecheck(), SeqScanState::ss, and PlanState::state.

Referenced by ExecInitSeqScan().

◆ ExecSeqScanWithQual()

static TupleTableSlot * ExecSeqScanWithQual ( PlanState pstate)
static

Definition at line 130 of file nodeSeqscan.c.

131{
132 SeqScanState *node = castNode(SeqScanState, pstate);
133
134 Assert(pstate->state->es_epq_active == NULL);
135 Assert(pstate->qual != NULL);
136 Assert(pstate->ps_ProjInfo == NULL);
137
138 return ExecScanExtended(&node->ss,
141 NULL,
142 pstate->qual,
143 NULL);
144}

References Assert, castNode, EState::es_epq_active, ExecScanExtended(), PlanState::ps_ProjInfo, PlanState::qual, SeqNext(), SeqRecheck(), SeqScanState::ss, and PlanState::state.

Referenced by ExecInitSeqScan().

◆ ExecSeqScanWithQualProject()

static TupleTableSlot * ExecSeqScanWithQualProject ( PlanState pstate)
static

Definition at line 171 of file nodeSeqscan.c.

172{
173 SeqScanState *node = castNode(SeqScanState, pstate);
174
175 Assert(pstate->state->es_epq_active == NULL);
176 Assert(pstate->qual != NULL);
177 Assert(pstate->ps_ProjInfo != NULL);
178
179 return ExecScanExtended(&node->ss,
182 NULL,
183 pstate->qual,
184 pstate->ps_ProjInfo);
185}

References Assert, castNode, EState::es_epq_active, ExecScanExtended(), PlanState::ps_ProjInfo, PlanState::qual, SeqNext(), SeqRecheck(), SeqScanState::ss, and PlanState::state.

Referenced by ExecInitSeqScan().

◆ SeqNext()

static TupleTableSlot * SeqNext ( SeqScanState node)
static

Definition at line 51 of file nodeSeqscan.c.

52{
53 TableScanDesc scandesc;
54 EState *estate;
55 ScanDirection direction;
56 TupleTableSlot *slot;
57
58 /*
59 * get information from the estate and scan state
60 */
61 scandesc = node->ss.ss_currentScanDesc;
62 estate = node->ss.ps.state;
63 direction = estate->es_direction;
64 slot = node->ss.ss_ScanTupleSlot;
65
66 if (scandesc == NULL)
67 {
68 /*
69 * We reach here if the scan is not parallel, or if we're serially
70 * executing a scan that was planned to be parallel.
71 */
72 scandesc = table_beginscan(node->ss.ss_currentRelation,
73 estate->es_snapshot,
74 0, NULL);
75 node->ss.ss_currentScanDesc = scandesc;
76 }
77
78 /*
79 * get the next tuple from the table
80 */
81 if (table_scan_getnextslot(scandesc, direction, slot))
82 return slot;
83 return NULL;
84}
ScanDirection
Definition: sdir.h:25
ScanDirection es_direction
Definition: execnodes.h:649
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1606
static TableScanDesc table_beginscan(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key)
Definition: tableam.h:913
static bool table_scan_getnextslot(TableScanDesc sscan, ScanDirection direction, TupleTableSlot *slot)
Definition: tableam.h:1061

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(), ExecSeqScanEPQ(), ExecSeqScanWithProject(), ExecSeqScanWithQual(), and ExecSeqScanWithQualProject().

◆ SeqRecheck()

static bool SeqRecheck ( SeqScanState node,
TupleTableSlot slot 
)
static

Definition at line 90 of file nodeSeqscan.c.

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

Referenced by ExecSeqScan(), ExecSeqScanEPQ(), ExecSeqScanWithProject(), ExecSeqScanWithQual(), and ExecSeqScanWithQualProject().