PostgreSQL Source Code  git master
nodeSamplescan.h File Reference
#include "nodes/execnodes.h"
Include dependency graph for nodeSamplescan.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

SampleScanStateExecInitSampleScan (SampleScan *node, EState *estate, int eflags)
 
void ExecEndSampleScan (SampleScanState *node)
 
void ExecReScanSampleScan (SampleScanState *node)
 

Function Documentation

◆ ExecEndSampleScan()

void ExecEndSampleScan ( SampleScanState node)

Definition at line 183 of file nodeSamplescan.c.

184 {
185  /*
186  * Tell sampling function that we finished the scan.
187  */
188  if (node->tsmroutine->EndSampleScan)
189  node->tsmroutine->EndSampleScan(node);
190 
191  /*
192  * close heap scan
193  */
194  if (node->ss.ss_currentScanDesc)
196 }
ScanState ss
Definition: execnodes.h:1495
struct TsmRoutine * tsmroutine
Definition: execnodes.h:1499
struct TableScanDescData * ss_currentScanDesc
Definition: execnodes.h:1475
EndSampleScan_function EndSampleScan
Definition: tsmapi.h:75
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:1009

References TsmRoutine::EndSampleScan, SampleScanState::ss, ScanState::ss_currentScanDesc, table_endscan(), and SampleScanState::tsmroutine.

Referenced by ExecEndNode().

◆ ExecInitSampleScan()

SampleScanState* ExecInitSampleScan ( SampleScan node,
EState estate,
int  eflags 
)

Definition at line 97 of file nodeSamplescan.c.

98 {
99  SampleScanState *scanstate;
100  TableSampleClause *tsc = node->tablesample;
101  TsmRoutine *tsm;
102 
103  Assert(outerPlan(node) == NULL);
104  Assert(innerPlan(node) == NULL);
105 
106  /*
107  * create state structure
108  */
109  scanstate = makeNode(SampleScanState);
110  scanstate->ss.ps.plan = (Plan *) node;
111  scanstate->ss.ps.state = estate;
112  scanstate->ss.ps.ExecProcNode = ExecSampleScan;
113 
114  /*
115  * Miscellaneous initialization
116  *
117  * create expression context for node
118  */
119  ExecAssignExprContext(estate, &scanstate->ss.ps);
120 
121  /*
122  * open the scan relation
123  */
124  scanstate->ss.ss_currentRelation =
125  ExecOpenScanRelation(estate,
126  node->scan.scanrelid,
127  eflags);
128 
129  /* we won't set up the HeapScanDesc till later */
130  scanstate->ss.ss_currentScanDesc = NULL;
131 
132  /* and create slot with appropriate rowtype */
133  ExecInitScanTupleSlot(estate, &scanstate->ss,
136 
137  /*
138  * Initialize result type and projection.
139  */
140  ExecInitResultTypeTL(&scanstate->ss.ps);
141  ExecAssignScanProjectionInfo(&scanstate->ss);
142 
143  /*
144  * initialize child expressions
145  */
146  scanstate->ss.ps.qual =
147  ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
148 
149  scanstate->args = ExecInitExprList(tsc->args, (PlanState *) scanstate);
150  scanstate->repeatable =
151  ExecInitExpr(tsc->repeatable, (PlanState *) scanstate);
152 
153  /*
154  * If we don't have a REPEATABLE clause, select a random seed. We want to
155  * do this just once, since the seed shouldn't change over rescans.
156  */
157  if (tsc->repeatable == NULL)
159 
160  /*
161  * Finally, initialize the TABLESAMPLE method handler.
162  */
163  tsm = GetTsmRoutine(tsc->tsmhandler);
164  scanstate->tsmroutine = tsm;
165  scanstate->tsm_state = NULL;
166 
167  if (tsm->InitSampleScan)
168  tsm->InitSampleScan(scanstate, eflags);
169 
170  /* We'll do BeginSampleScan later; we can't evaluate params yet */
171  scanstate->begun = false;
172 
173  return scanstate;
174 }
List * ExecInitExprList(List *nodes, PlanState *parent)
Definition: execExpr.c:323
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:214
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
Definition: execExpr.c:128
void ExecAssignScanProjectionInfo(ScanState *node)
Definition: execScan.c:271
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1810
void ExecInitResultTypeTL(PlanState *planstate)
Definition: execTuples.c:1754
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:488
Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
Definition: execUtils.c:702
Assert(fmt[strlen(fmt) - 1] !='\n')
static TupleTableSlot * ExecSampleScan(PlanState *pstate)
#define makeNode(_type_)
Definition: nodes.h:176
uint32 pg_prng_uint32(pg_prng_state *state)
Definition: pg_prng.c:191
pg_prng_state pg_global_prng_state
Definition: pg_prng.c:34
#define innerPlan(node)
Definition: plannodes.h:181
#define outerPlan(node)
Definition: plannodes.h:182
#define RelationGetDescr(relation)
Definition: rel.h:530
ExprState * qual
Definition: execnodes.h:1057
Plan * plan
Definition: execnodes.h:1036
EState * state
Definition: execnodes.h:1038
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1042
ExprState * repeatable
Definition: execnodes.h:1497
void * tsm_state
Definition: execnodes.h:1500
struct TableSampleClause * tablesample
Definition: plannodes.h:407
Scan scan
Definition: plannodes.h:405
Relation ss_currentRelation
Definition: execnodes.h:1474
PlanState ps
Definition: execnodes.h:1473
Index scanrelid
Definition: plannodes.h:387
InitSampleScan_function InitSampleScan
Definition: tsmapi.h:71
const TupleTableSlotOps * table_slot_callbacks(Relation relation)
Definition: tableam.c:58
TsmRoutine * GetTsmRoutine(Oid tsmhandler)
Definition: tablesample.c:27

References SampleScanState::args, TableSampleClause::args, Assert(), SampleScanState::begun, ExecAssignExprContext(), ExecAssignScanProjectionInfo(), ExecInitExpr(), ExecInitExprList(), ExecInitQual(), ExecInitResultTypeTL(), ExecInitScanTupleSlot(), ExecOpenScanRelation(), PlanState::ExecProcNode, ExecSampleScan(), GetTsmRoutine(), TsmRoutine::InitSampleScan, innerPlan, makeNode, outerPlan, pg_global_prng_state, pg_prng_uint32(), PlanState::plan, ScanState::ps, PlanState::qual, RelationGetDescr, SampleScanState::repeatable, TableSampleClause::repeatable, SampleScan::scan, Scan::scanrelid, SampleScanState::seed, SampleScanState::ss, ScanState::ss_currentRelation, ScanState::ss_currentScanDesc, PlanState::state, table_slot_callbacks(), SampleScan::tablesample, SampleScanState::tsm_state, TableSampleClause::tsmhandler, and SampleScanState::tsmroutine.

Referenced by ExecInitNode().

◆ ExecReScanSampleScan()

void ExecReScanSampleScan ( SampleScanState node)

Definition at line 206 of file nodeSamplescan.c.

207 {
208  /* Remember we need to do BeginSampleScan again (if we did it at all) */
209  node->begun = false;
210  node->done = false;
211  node->haveblock = false;
212  node->donetuples = 0;
213 
214  ExecScanReScan(&node->ss);
215 }
void ExecScanReScan(ScanState *node)
Definition: execScan.c:298

References SampleScanState::begun, SampleScanState::done, SampleScanState::donetuples, ExecScanReScan(), SampleScanState::haveblock, and SampleScanState::ss.

Referenced by ExecReScan().