PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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

void ExecEndSampleScan ( SampleScanState node)

Definition at line 224 of file nodeSamplescan.c.

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

Referenced by ExecEndNode().

225 {
226  /*
227  * Tell sampling function that we finished the scan.
228  */
229  if (node->tsmroutine->EndSampleScan)
230  node->tsmroutine->EndSampleScan(node);
231 
232  /*
233  * Free the exprcontext
234  */
235  ExecFreeExprContext(&node->ss.ps);
236 
237  /*
238  * clean out the tuple table
239  */
242 
243  /*
244  * close heap scan
245  */
246  if (node->ss.ss_currentScanDesc)
248 
249  /*
250  * close the heap relation.
251  */
253 }
void heap_endscan(HeapScanDesc scan)
Definition: heapam.c:1565
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1103
Relation ss_currentRelation
Definition: execnodes.h:1101
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:521
PlanState ps
Definition: execnodes.h:1100
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:880
void ExecCloseScanRelation(Relation scanrel)
Definition: execUtils.c:666
struct TsmRoutine * tsmroutine
Definition: execnodes.h:1126
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1102
EndSampleScan_function EndSampleScan
Definition: tsmapi.h:74
ScanState ss
Definition: execnodes.h:1122
SampleScanState* ExecInitSampleScan ( SampleScan node,
EState estate,
int  eflags 
)

Definition at line 143 of file nodeSamplescan.c.

References TableSampleClause::args, SampleScanState::args, Assert, SampleScanState::begun, ExecAssignExprContext(), ExecAssignResultTypeFromTL(), ExecAssignScanProjectionInfo(), ExecInitExpr(), ExecInitExprList(), ExecInitQual(), ExecInitResultTupleSlot(), ExecInitScanTupleSlot(), PlanState::ExecProcNode, ExecSampleScan(), GetTsmRoutine(), TsmRoutine::InitSampleScan, InitScanRelation(), innerPlan, makeNode, outerPlan, Scan::plan, PlanState::plan, ScanState::ps, Plan::qual, PlanState::qual, random(), TableSampleClause::repeatable, SampleScanState::repeatable, SampleScan::scan, SampleScanState::seed, SampleScanState::ss, PlanState::state, SampleScan::tablesample, SampleScanState::tsm_state, TableSampleClause::tsmhandler, and SampleScanState::tsmroutine.

Referenced by ExecInitNode().

144 {
145  SampleScanState *scanstate;
146  TableSampleClause *tsc = node->tablesample;
147  TsmRoutine *tsm;
148 
149  Assert(outerPlan(node) == NULL);
150  Assert(innerPlan(node) == NULL);
151 
152  /*
153  * create state structure
154  */
155  scanstate = makeNode(SampleScanState);
156  scanstate->ss.ps.plan = (Plan *) node;
157  scanstate->ss.ps.state = estate;
158  scanstate->ss.ps.ExecProcNode = ExecSampleScan;
159 
160  /*
161  * Miscellaneous initialization
162  *
163  * create expression context for node
164  */
165  ExecAssignExprContext(estate, &scanstate->ss.ps);
166 
167  /*
168  * initialize child expressions
169  */
170  scanstate->ss.ps.qual =
171  ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
172 
173  scanstate->args = ExecInitExprList(tsc->args, (PlanState *) scanstate);
174  scanstate->repeatable =
175  ExecInitExpr(tsc->repeatable, (PlanState *) scanstate);
176 
177  /*
178  * tuple table initialization
179  */
180  ExecInitResultTupleSlot(estate, &scanstate->ss.ps);
181  ExecInitScanTupleSlot(estate, &scanstate->ss);
182 
183  /*
184  * initialize scan relation
185  */
186  InitScanRelation(scanstate, estate, eflags);
187 
188  /*
189  * Initialize result tuple type and projection info.
190  */
191  ExecAssignResultTypeFromTL(&scanstate->ss.ps);
192  ExecAssignScanProjectionInfo(&scanstate->ss);
193 
194  /*
195  * If we don't have a REPEATABLE clause, select a random seed. We want to
196  * do this just once, since the seed shouldn't change over rescans.
197  */
198  if (tsc->repeatable == NULL)
199  scanstate->seed = random();
200 
201  /*
202  * Finally, initialize the TABLESAMPLE method handler.
203  */
204  tsm = GetTsmRoutine(tsc->tsmhandler);
205  scanstate->tsmroutine = tsm;
206  scanstate->tsm_state = NULL;
207 
208  if (tsm->InitSampleScan)
209  tsm->InitSampleScan(scanstate, eflags);
210 
211  /* We'll do BeginSampleScan later; we can't evaluate params yet */
212  scanstate->begun = false;
213 
214  return scanstate;
215 }
InitSampleScan_function InitSampleScan
Definition: tsmapi.h:70
List * qual
Definition: plannodes.h:145
Plan plan
Definition: plannodes.h:328
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate)
Definition: execTuples.c:842
long random(void)
Definition: random.c:22
void * tsm_state
Definition: execnodes.h:1127
struct TableSampleClause * tablesample
Definition: plannodes.h:346
EState * state
Definition: execnodes.h:849
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:160
void ExecAssignResultTypeFromTL(PlanState *planstate)
Definition: execUtils.c:445
PlanState ps
Definition: execnodes.h:1100
void ExecAssignScanProjectionInfo(ScanState *node)
Definition: execScan.c:237
void ExecInitResultTupleSlot(EState *estate, PlanState *planstate)
Definition: execTuples.c:832
Scan scan
Definition: plannodes.h:344
#define innerPlan(node)
Definition: plannodes.h:173
List * ExecInitExprList(List *nodes, PlanState *parent)
Definition: execExpr.c:266
ExprState * repeatable
Definition: execnodes.h:1124
#define outerPlan(node)
Definition: plannodes.h:174
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:853
Plan * plan
Definition: execnodes.h:847
TsmRoutine * GetTsmRoutine(Oid tsmhandler)
Definition: tablesample.c:27
#define makeNode(_type_)
Definition: nodes.h:557
#define Assert(condition)
Definition: c.h:664
static void InitScanRelation(SampleScanState *node, EState *estate, int eflags)
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:423
struct TsmRoutine * tsmroutine
Definition: execnodes.h:1126
ExprState * qual
Definition: execnodes.h:865
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
Definition: execExpr.c:113
static TupleTableSlot * ExecSampleScan(PlanState *pstate)
ScanState ss
Definition: execnodes.h:1122
void ExecReScanSampleScan ( SampleScanState node)

Definition at line 263 of file nodeSamplescan.c.

References SampleScanState::begun, ExecScanReScan(), and SampleScanState::ss.

Referenced by ExecReScan().

264 {
265  /* Remember we need to do BeginSampleScan again (if we did it at all) */
266  node->begun = false;
267 
268  ExecScanReScan(&node->ss);
269 }
void ExecScanReScan(ScanState *node)
Definition: execScan.c:329
ScanState ss
Definition: execnodes.h:1122