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)
 
TupleTableSlotExecSampleScan (SampleScanState *node)
 
void ExecEndSampleScan (SampleScanState *node)
 
void ExecReScanSampleScan (SampleScanState *node)
 

Function Documentation

void ExecEndSampleScan ( SampleScanState node)

Definition at line 228 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().

229 {
230  /*
231  * Tell sampling function that we finished the scan.
232  */
233  if (node->tsmroutine->EndSampleScan)
234  node->tsmroutine->EndSampleScan(node);
235 
236  /*
237  * Free the exprcontext
238  */
239  ExecFreeExprContext(&node->ss.ps);
240 
241  /*
242  * clean out the tuple table
243  */
246 
247  /*
248  * close heap scan
249  */
250  if (node->ss.ss_currentScanDesc)
252 
253  /*
254  * close the heap relation.
255  */
257 }
void heap_endscan(HeapScanDesc scan)
Definition: heapam.c:1581
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1291
Relation ss_currentRelation
Definition: execnodes.h:1289
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:685
PlanState ps
Definition: execnodes.h:1288
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:1077
void ExecCloseScanRelation(Relation scanrel)
Definition: execUtils.c:830
struct TsmRoutine * tsmroutine
Definition: execnodes.h:1314
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1290
EndSampleScan_function EndSampleScan
Definition: tsmapi.h:74
ScanState ss
Definition: execnodes.h:1310
SampleScanState* ExecInitSampleScan ( SampleScan node,
EState estate,
int  eflags 
)

Definition at line 141 of file nodeSamplescan.c.

References TableSampleClause::args, SampleScanState::args, Assert, SampleScanState::begun, ExecAssignExprContext(), ExecAssignResultTypeFromTL(), ExecAssignScanProjectionInfo(), ExecInitExpr(), ExecInitResultTupleSlot(), ExecInitScanTupleSlot(), GetTsmRoutine(), TsmRoutine::InitSampleScan, InitScanRelation(), innerPlan, makeNode, NULL, 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, Plan::targetlist, PlanState::targetlist, SampleScanState::tsm_state, TableSampleClause::tsmhandler, and SampleScanState::tsmroutine.

Referenced by ExecInitNode().

142 {
143  SampleScanState *scanstate;
144  TableSampleClause *tsc = node->tablesample;
145  TsmRoutine *tsm;
146 
147  Assert(outerPlan(node) == NULL);
148  Assert(innerPlan(node) == NULL);
149 
150  /*
151  * create state structure
152  */
153  scanstate = makeNode(SampleScanState);
154  scanstate->ss.ps.plan = (Plan *) node;
155  scanstate->ss.ps.state = estate;
156 
157  /*
158  * Miscellaneous initialization
159  *
160  * create expression context for node
161  */
162  ExecAssignExprContext(estate, &scanstate->ss.ps);
163 
164  /*
165  * initialize child expressions
166  */
167  scanstate->ss.ps.targetlist = (List *)
169  (PlanState *) scanstate);
170  scanstate->ss.ps.qual = (List *)
171  ExecInitExpr((Expr *) node->scan.plan.qual,
172  (PlanState *) scanstate);
173 
174  scanstate->args = (List *)
175  ExecInitExpr((Expr *) tsc->args,
176  (PlanState *) scanstate);
177  scanstate->repeatable =
179  (PlanState *) scanstate);
180 
181  /*
182  * tuple table initialization
183  */
184  ExecInitResultTupleSlot(estate, &scanstate->ss.ps);
185  ExecInitScanTupleSlot(estate, &scanstate->ss);
186 
187  /*
188  * initialize scan relation
189  */
190  InitScanRelation(scanstate, estate, eflags);
191 
192  /*
193  * Initialize result tuple type and projection info.
194  */
195  ExecAssignResultTypeFromTL(&scanstate->ss.ps);
196  ExecAssignScanProjectionInfo(&scanstate->ss);
197 
198  /*
199  * If we don't have a REPEATABLE clause, select a random seed. We want to
200  * do this just once, since the seed shouldn't change over rescans.
201  */
202  if (tsc->repeatable == NULL)
203  scanstate->seed = random();
204 
205  /*
206  * Finally, initialize the TABLESAMPLE method handler.
207  */
208  tsm = GetTsmRoutine(tsc->tsmhandler);
209  scanstate->tsmroutine = tsm;
210  scanstate->tsm_state = NULL;
211 
212  if (tsm->InitSampleScan)
213  tsm->InitSampleScan(scanstate, eflags);
214 
215  /* We'll do BeginSampleScan later; we can't evaluate params yet */
216  scanstate->begun = false;
217 
218  return scanstate;
219 }
InitSampleScan_function InitSampleScan
Definition: tsmapi.h:70
List * qual
Definition: plannodes.h:130
Plan plan
Definition: plannodes.h:305
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate)
Definition: execTuples.c:842
long random(void)
Definition: random.c:22
void * tsm_state
Definition: execnodes.h:1315
struct TableSampleClause * tablesample
Definition: plannodes.h:323
List * qual
Definition: execnodes.h:1062
List * targetlist
Definition: execnodes.h:1061
EState * state
Definition: execnodes.h:1049
void ExecAssignResultTypeFromTL(PlanState *planstate)
Definition: execUtils.c:430
PlanState ps
Definition: execnodes.h:1288
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
Definition: execQual.c:4266
void ExecAssignScanProjectionInfo(ScanState *node)
Definition: execScan.c:235
void ExecInitResultTupleSlot(EState *estate, PlanState *planstate)
Definition: execTuples.c:832
Scan scan
Definition: plannodes.h:321
#define innerPlan(node)
Definition: plannodes.h:158
ExprState * repeatable
Definition: execnodes.h:1312
#define outerPlan(node)
Definition: plannodes.h:159
Plan * plan
Definition: execnodes.h:1047
TsmRoutine * GetTsmRoutine(Oid tsmhandler)
Definition: tablesample.c:27
#define makeNode(_type_)
Definition: nodes.h:556
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:670
static void InitScanRelation(SampleScanState *node, EState *estate, int eflags)
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:408
struct TsmRoutine * tsmroutine
Definition: execnodes.h:1314
List * targetlist
Definition: plannodes.h:129
Definition: pg_list.h:45
ScanState ss
Definition: execnodes.h:1310
void ExecReScanSampleScan ( SampleScanState node)

Definition at line 267 of file nodeSamplescan.c.

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

Referenced by ExecReScan().

268 {
269  /* Remember we need to do BeginSampleScan again (if we did it at all) */
270  node->begun = false;
271 
272  ExecScanReScan(&node->ss);
273 }
void ExecScanReScan(ScanState *node)
Definition: execScan.c:327
ScanState ss
Definition: execnodes.h:1310
TupleTableSlot* ExecSampleScan ( SampleScanState node)

Definition at line 100 of file nodeSamplescan.c.

References ExecScan(), SampleNext(), and SampleRecheck().

Referenced by ExecProcNode().

101 {
102  return ExecScan((ScanState *) node,
105 }
TupleTableSlot * ExecScan(ScanState *node, ExecScanAccessMtd accessMtd, ExecScanRecheckMtd recheckMtd)
Definition: execScan.c:121
static TupleTableSlot * SampleNext(SampleScanState *node)
TupleTableSlot *(* ExecScanAccessMtd)(ScanState *node)
Definition: executor.h:271
bool(* ExecScanRecheckMtd)(ScanState *node, TupleTableSlot *slot)
Definition: executor.h:272
static bool SampleRecheck(SampleScanState *node, TupleTableSlot *slot)