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 221 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().

222 {
223  /*
224  * Tell sampling function that we finished the scan.
225  */
226  if (node->tsmroutine->EndSampleScan)
227  node->tsmroutine->EndSampleScan(node);
228 
229  /*
230  * Free the exprcontext
231  */
232  ExecFreeExprContext(&node->ss.ps);
233 
234  /*
235  * clean out the tuple table
236  */
239 
240  /*
241  * close heap scan
242  */
243  if (node->ss.ss_currentScanDesc)
245 
246  /*
247  * close the heap relation.
248  */
250 }
void heap_endscan(HeapScanDesc scan)
Definition: heapam.c:1578
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1061
Relation ss_currentRelation
Definition: execnodes.h:1059
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:516
PlanState ps
Definition: execnodes.h:1058
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:842
void ExecCloseScanRelation(Relation scanrel)
Definition: execUtils.c:661
struct TsmRoutine * tsmroutine
Definition: execnodes.h:1084
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1060
EndSampleScan_function EndSampleScan
Definition: tsmapi.h:74
ScanState ss
Definition: execnodes.h:1080
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(), ExecInitExprList(), ExecInitQual(), 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, 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.qual =
168  ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
169 
170  scanstate->args = ExecInitExprList(tsc->args, (PlanState *) scanstate);
171  scanstate->repeatable =
172  ExecInitExpr(tsc->repeatable, (PlanState *) scanstate);
173 
174  /*
175  * tuple table initialization
176  */
177  ExecInitResultTupleSlot(estate, &scanstate->ss.ps);
178  ExecInitScanTupleSlot(estate, &scanstate->ss);
179 
180  /*
181  * initialize scan relation
182  */
183  InitScanRelation(scanstate, estate, eflags);
184 
185  /*
186  * Initialize result tuple type and projection info.
187  */
188  ExecAssignResultTypeFromTL(&scanstate->ss.ps);
189  ExecAssignScanProjectionInfo(&scanstate->ss);
190 
191  /*
192  * If we don't have a REPEATABLE clause, select a random seed. We want to
193  * do this just once, since the seed shouldn't change over rescans.
194  */
195  if (tsc->repeatable == NULL)
196  scanstate->seed = random();
197 
198  /*
199  * Finally, initialize the TABLESAMPLE method handler.
200  */
201  tsm = GetTsmRoutine(tsc->tsmhandler);
202  scanstate->tsmroutine = tsm;
203  scanstate->tsm_state = NULL;
204 
205  if (tsm->InitSampleScan)
206  tsm->InitSampleScan(scanstate, eflags);
207 
208  /* We'll do BeginSampleScan later; we can't evaluate params yet */
209  scanstate->begun = false;
210 
211  return scanstate;
212 }
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:1085
struct TableSampleClause * tablesample
Definition: plannodes.h:346
EState * state
Definition: execnodes.h:815
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:160
void ExecAssignResultTypeFromTL(PlanState *planstate)
Definition: execUtils.c:440
PlanState ps
Definition: execnodes.h:1058
void ExecAssignScanProjectionInfo(ScanState *node)
Definition: execScan.c:235
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:1082
#define outerPlan(node)
Definition: plannodes.h:174
Plan * plan
Definition: execnodes.h:813
TsmRoutine * GetTsmRoutine(Oid tsmhandler)
Definition: tablesample.c:27
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
static void InitScanRelation(SampleScanState *node, EState *estate, int eflags)
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:418
struct TsmRoutine * tsmroutine
Definition: execnodes.h:1084
ExprState * qual
Definition: execnodes.h:827
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
Definition: execExpr.c:113
ScanState ss
Definition: execnodes.h:1080
void ExecReScanSampleScan ( SampleScanState node)

Definition at line 260 of file nodeSamplescan.c.

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

Referenced by ExecReScan().

261 {
262  /* Remember we need to do BeginSampleScan again (if we did it at all) */
263  node->begun = false;
264 
265  ExecScanReScan(&node->ss);
266 }
void ExecScanReScan(ScanState *node)
Definition: execScan.c:327
ScanState ss
Definition: execnodes.h:1080
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:389
bool(* ExecScanRecheckMtd)(ScanState *node, TupleTableSlot *slot)
Definition: executor.h:390
static bool SampleRecheck(SampleScanState *node, TupleTableSlot *slot)