PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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 pg_attribute_always_inline 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 293 of file nodeSeqscan.c.

294{
296
297 /*
298 * get information from node
299 */
301
302 /*
303 * close heap scan
304 */
305 if (scanDesc != NULL)
307}
static int fb(int x)
struct TableScanDescData * ss_currentScanDesc
Definition execnodes.h:1625
ScanState ss
Definition execnodes.h:1635
static void table_endscan(TableScanDesc scan)
Definition tableam.h:1005

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

Referenced by ExecEndNode().

◆ ExecInitSeqScan()

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

Definition at line 211 of file nodeSeqscan.c.

212{
214
215 /*
216 * Once upon a time it was possible to have an outerPlan of a SeqScan, but
217 * not any more.
218 */
219 Assert(outerPlan(node) == NULL);
220 Assert(innerPlan(node) == NULL);
221
222 /*
223 * create state structure
224 */
226 scanstate->ss.ps.plan = (Plan *) node;
227 scanstate->ss.ps.state = estate;
228
229 /*
230 * Miscellaneous initialization
231 *
232 * create expression context for node
233 */
234 ExecAssignExprContext(estate, &scanstate->ss.ps);
235
236 /*
237 * open the scan relation
238 */
239 scanstate->ss.ss_currentRelation =
241 node->scan.scanrelid,
242 eflags);
243
244 /* and create slot with the appropriate rowtype */
245 ExecInitScanTupleSlot(estate, &scanstate->ss,
246 RelationGetDescr(scanstate->ss.ss_currentRelation),
247 table_slot_callbacks(scanstate->ss.ss_currentRelation));
248
249 /*
250 * Initialize result type and projection.
251 */
254
255 /*
256 * initialize child expressions
257 */
258 scanstate->ss.ps.qual =
259 ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
260
261 /*
262 * When EvalPlanQual() is not in use, assign ExecProcNode for this node
263 * based on the presence of qual and projection. Each ExecSeqScan*()
264 * variant is optimized for the specific combination of these conditions.
265 */
266 if (scanstate->ss.ps.state->es_epq_active != NULL)
267 scanstate->ss.ps.ExecProcNode = ExecSeqScanEPQ;
268 else if (scanstate->ss.ps.qual == NULL)
269 {
270 if (scanstate->ss.ps.ps_ProjInfo == NULL)
271 scanstate->ss.ps.ExecProcNode = ExecSeqScan;
272 else
273 scanstate->ss.ps.ExecProcNode = ExecSeqScanWithProject;
274 }
275 else
276 {
277 if (scanstate->ss.ps.ps_ProjInfo == NULL)
278 scanstate->ss.ps.ExecProcNode = ExecSeqScanWithQual;
279 else
280 scanstate->ss.ps.ExecProcNode = ExecSeqScanWithQualProject;
281 }
282
283 return scanstate;
284}
#define Assert(condition)
Definition c.h:873
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)
void ExecInitResultTypeTL(PlanState *planstate)
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition execUtils.c:485
Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
Definition execUtils.c:742
static TupleTableSlot * ExecSeqScanWithQual(PlanState *pstate)
static TupleTableSlot * ExecSeqScanWithQualProject(PlanState *pstate)
static TupleTableSlot * ExecSeqScan(PlanState *pstate)
static TupleTableSlot * ExecSeqScanEPQ(PlanState *pstate)
static TupleTableSlot * ExecSeqScanWithProject(PlanState *pstate)
#define makeNode(_type_)
Definition nodes.h:161
#define innerPlan(node)
Definition plannodes.h:260
#define outerPlan(node)
Definition plannodes.h:261
#define RelationGetDescr(relation)
Definition rel.h:540
Index scanrelid
Definition plannodes.h:523
Scan scan
Definition plannodes.h:532
const TupleTableSlotOps * table_slot_callbacks(Relation relation)
Definition tableam.c:59

References Assert, ExecAssignExprContext(), ExecAssignScanProjectionInfo(), ExecInitQual(), ExecInitResultTypeTL(), ExecInitScanTupleSlot(), ExecOpenScanRelation(), ExecSeqScan(), ExecSeqScanEPQ(), ExecSeqScanWithProject(), ExecSeqScanWithQual(), ExecSeqScanWithQualProject(), fb(), innerPlan, makeNode, outerPlan, RelationGetDescr, SeqScan::scan, Scan::scanrelid, and table_slot_callbacks().

Referenced by ExecInitNode().

◆ ExecReScanSeqScan()

void ExecReScanSeqScan ( SeqScanState node)

Definition at line 321 of file nodeSeqscan.c.

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

References ExecScanReScan(), fb(), 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:160
bool(* ExecScanRecheckMtd)(ScanState *node, TupleTableSlot *slot)
Definition executor.h:580
TupleTableSlot *(* ExecScanAccessMtd)(ScanState *node)
Definition executor.h:579
static pg_attribute_always_inline 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:182
struct EPQState * es_epq_active
Definition execnodes.h:744
ExprState * qual
Definition execnodes.h:1188
EState * state
Definition execnodes.h:1169
ProjectionInfo * ps_ProjInfo
Definition execnodes.h:1207

References Assert, castNode, EState::es_epq_active, ExecScanExtended(), fb(), 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 197 of file nodeSeqscan.c.

198{
199 SeqScanState *node = castNode(SeqScanState, pstate);
200
201 return ExecScan(&node->ss,
204}
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 347 of file nodeSeqscan.c.

349{
350 EState *estate = node->ss.ps.state;
351
353 estate->es_snapshot);
356}
#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:662
shm_toc_estimator estimator
Definition parallel.h:41
Relation ss_currentRelation
Definition execnodes.h:1624
PlanState ps
Definition execnodes.h:1623
Size table_parallelscan_estimate(Relation rel, Snapshot snapshot)
Definition tableam.c:131

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

367{
368 EState *estate = node->ss.ps.state;
370
371 pscan = shm_toc_allocate(pcxt->toc, node->pscan_len);
373 pscan,
374 estate->es_snapshot);
375 shm_toc_insert(pcxt->toc, node->ss.ps.plan->plan_node_id, pscan);
376 node->ss.ss_currentScanDesc =
378}
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
Plan * plan
Definition execnodes.h:1167
int plan_node_id
Definition plannodes.h:227
TableScanDesc table_beginscan_parallel(Relation relation, ParallelTableScanDesc pscan)
Definition tableam.c:166
void table_parallelscan_initialize(Relation rel, ParallelTableScanDesc pscan, Snapshot snapshot)
Definition tableam.c:146

References EState::es_snapshot, fb(), 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 
)

◆ ExecSeqScanReInitializeDSM()

void ExecSeqScanReInitializeDSM ( SeqScanState node,
ParallelContext pcxt 
)

Definition at line 387 of file nodeSeqscan.c.

389{
391
394}
struct ParallelTableScanDescData * rs_parallel
Definition relscan.h:65
static void table_parallelscan_reinitialize(Relation rel, ParallelTableScanDesc pscan)
Definition tableam.h:1161

References fb(), 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 154 of file nodeSeqscan.c.

155{
156 SeqScanState *node = castNode(SeqScanState, pstate);
157
158 Assert(pstate->state->es_epq_active == NULL);
159 Assert(pstate->qual == NULL);
160 pg_assume(pstate->ps_ProjInfo != NULL);
161
162 return ExecScanExtended(&node->ss,
165 NULL,
166 NULL,
167 pstate->ps_ProjInfo);
168}
#define pg_assume(expr)
Definition c.h:397

References Assert, castNode, EState::es_epq_active, ExecScanExtended(), fb(), pg_assume, 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 /*
135 * Use pg_assume() for != NULL tests to make the compiler realize no
136 * runtime check for the field is needed in ExecScanExtended().
137 */
138 Assert(pstate->state->es_epq_active == NULL);
139 pg_assume(pstate->qual != NULL);
140 Assert(pstate->ps_ProjInfo == NULL);
141
142 return ExecScanExtended(&node->ss,
145 NULL,
146 pstate->qual,
147 NULL);
148}

References Assert, castNode, EState::es_epq_active, ExecScanExtended(), fb(), pg_assume, 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 175 of file nodeSeqscan.c.

176{
177 SeqScanState *node = castNode(SeqScanState, pstate);
178
179 Assert(pstate->state->es_epq_active == NULL);
180 pg_assume(pstate->qual != NULL);
181 pg_assume(pstate->ps_ProjInfo != NULL);
182
183 return ExecScanExtended(&node->ss,
186 NULL,
187 pstate->qual,
188 pstate->ps_ProjInfo);
189}

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

Referenced by ExecInitSeqScan().

◆ SeqNext()

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:661
TupleTableSlot * ss_ScanTupleSlot
Definition execnodes.h:1626
static bool table_scan_getnextslot(TableScanDesc sscan, ScanDirection direction, TupleTableSlot *slot)
Definition tableam.h:1040
static TableScanDesc table_beginscan(Relation rel, Snapshot snapshot, int nkeys, ScanKeyData *key)
Definition tableam.h:897

References EState::es_direction, EState::es_snapshot, fb(), 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 pg_attribute_always_inline 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().