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 182 of file nodeSamplescan.c.

References TsmRoutine::EndSampleScan, ExecClearTuple(), ExecFreeExprContext(), ScanState::ps, PlanState::ps_ResultTupleSlot, SampleScanState::ss, ScanState::ss_currentScanDesc, ScanState::ss_ScanTupleSlot, table_endscan(), and SampleScanState::tsmroutine.

Referenced by ExecEndNode().

183 {
184  /*
185  * Tell sampling function that we finished the scan.
186  */
187  if (node->tsmroutine->EndSampleScan)
188  node->tsmroutine->EndSampleScan(node);
189 
190  /*
191  * Free the exprcontext
192  */
193  ExecFreeExprContext(&node->ss.ps);
194 
195  /*
196  * clean out the tuple table
197  */
198  if (node->ss.ps.ps_ResultTupleSlot)
201 
202  /*
203  * close heap scan
204  */
205  if (node->ss.ss_currentScanDesc)
207 }
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:425
struct TableScanDescData * ss_currentScanDesc
Definition: execnodes.h:1332
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1333
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:614
PlanState ps
Definition: execnodes.h:1330
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:977
struct TsmRoutine * tsmroutine
Definition: execnodes.h:1356
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:831
EndSampleScan_function EndSampleScan
Definition: tsmapi.h:75
ScanState ss
Definition: execnodes.h:1352

◆ ExecInitSampleScan()

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

Definition at line 96 of file nodeSamplescan.c.

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

Referenced by ExecInitNode().

97 {
98  SampleScanState *scanstate;
99  TableSampleClause *tsc = node->tablesample;
100  TsmRoutine *tsm;
101 
102  Assert(outerPlan(node) == NULL);
103  Assert(innerPlan(node) == NULL);
104 
105  /*
106  * create state structure
107  */
108  scanstate = makeNode(SampleScanState);
109  scanstate->ss.ps.plan = (Plan *) node;
110  scanstate->ss.ps.state = estate;
111  scanstate->ss.ps.ExecProcNode = ExecSampleScan;
112 
113  /*
114  * Miscellaneous initialization
115  *
116  * create expression context for node
117  */
118  ExecAssignExprContext(estate, &scanstate->ss.ps);
119 
120  /*
121  * open the scan relation
122  */
123  scanstate->ss.ss_currentRelation =
124  ExecOpenScanRelation(estate,
125  node->scan.scanrelid,
126  eflags);
127 
128  /* we won't set up the HeapScanDesc till later */
129  scanstate->ss.ss_currentScanDesc = NULL;
130 
131  /* and create slot with appropriate rowtype */
132  ExecInitScanTupleSlot(estate, &scanstate->ss,
135 
136  /*
137  * Initialize result type and projection.
138  */
139  ExecInitResultTypeTL(&scanstate->ss.ps);
140  ExecAssignScanProjectionInfo(&scanstate->ss);
141 
142  /*
143  * initialize child expressions
144  */
145  scanstate->ss.ps.qual =
146  ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
147 
148  scanstate->args = ExecInitExprList(tsc->args, (PlanState *) scanstate);
149  scanstate->repeatable =
150  ExecInitExpr(tsc->repeatable, (PlanState *) scanstate);
151 
152  /*
153  * If we don't have a REPEATABLE clause, select a random seed. We want to
154  * do this just once, since the seed shouldn't change over rescans.
155  */
156  if (tsc->repeatable == NULL)
157  scanstate->seed = random();
158 
159  /*
160  * Finally, initialize the TABLESAMPLE method handler.
161  */
162  tsm = GetTsmRoutine(tsc->tsmhandler);
163  scanstate->tsmroutine = tsm;
164  scanstate->tsm_state = NULL;
165 
166  if (tsm->InitSampleScan)
167  tsm->InitSampleScan(scanstate, eflags);
168 
169  /* We'll do BeginSampleScan later; we can't evaluate params yet */
170  scanstate->begun = false;
171 
172  return scanstate;
173 }
InitSampleScan_function InitSampleScan
Definition: tsmapi.h:71
List * qual
Definition: plannodes.h:141
Plan plan
Definition: plannodes.h:340
Index scanrelid
Definition: plannodes.h:341
#define RelationGetDescr(relation)
Definition: rel.h:448
long random(void)
Definition: random.c:22
const TupleTableSlotOps * table_slot_callbacks(Relation relation)
Definition: tableam.c:44
void * tsm_state
Definition: execnodes.h:1357
struct TableSampleClause * tablesample
Definition: plannodes.h:358
struct TableScanDescData * ss_currentScanDesc
Definition: execnodes.h:1332
Relation ss_currentRelation
Definition: execnodes.h:1331
EState * state
Definition: execnodes.h:941
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:207
PlanState ps
Definition: execnodes.h:1330
void ExecAssignScanProjectionInfo(ScanState *node)
Definition: execScan.c:272
Scan scan
Definition: plannodes.h:356
Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
Definition: execUtils.c:693
#define innerPlan(node)
Definition: plannodes.h:169
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1781
void ExecInitResultTypeTL(PlanState *planstate)
Definition: execTuples.c:1725
List * ExecInitExprList(List *nodes, PlanState *parent)
Definition: execExpr.c:316
ExprState * repeatable
Definition: execnodes.h:1354
#define outerPlan(node)
Definition: plannodes.h:170
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:945
Plan * plan
Definition: execnodes.h:939
TsmRoutine * GetTsmRoutine(Oid tsmhandler)
Definition: tablesample.c:27
#define makeNode(_type_)
Definition: nodes.h:573
#define Assert(condition)
Definition: c.h:739
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:444
struct TsmRoutine * tsmroutine
Definition: execnodes.h:1356
ExprState * qual
Definition: execnodes.h:960
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
Definition: execExpr.c:121
static TupleTableSlot * ExecSampleScan(PlanState *pstate)
ScanState ss
Definition: execnodes.h:1352

◆ ExecReScanSampleScan()

void ExecReScanSampleScan ( SampleScanState node)

Definition at line 217 of file nodeSamplescan.c.

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

Referenced by ExecReScan().

218 {
219  /* Remember we need to do BeginSampleScan again (if we did it at all) */
220  node->begun = false;
221  node->done = false;
222  node->haveblock = false;
223  node->donetuples = 0;
224 
225  ExecScanReScan(&node->ss);
226 }
void ExecScanReScan(ScanState *node)
Definition: execScan.c:299
ScanState ss
Definition: execnodes.h:1352