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

203 {
204  /*
205  * Tell sampling function that we finished the scan.
206  */
207  if (node->tsmroutine->EndSampleScan)
208  node->tsmroutine->EndSampleScan(node);
209 
210  /*
211  * Free the exprcontext
212  */
213  ExecFreeExprContext(&node->ss.ps);
214 
215  /*
216  * clean out the tuple table
217  */
220 
221  /*
222  * close heap scan
223  */
224  if (node->ss.ss_currentScanDesc)
226 
227  /*
228  * close the heap relation.
229  */
231 }
void heap_endscan(HeapScanDesc scan)
Definition: heapam.c:1568
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:475
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1127
Relation ss_currentRelation
Definition: execnodes.h:1125
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:561
PlanState ps
Definition: execnodes.h:1124
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:901
void ExecCloseScanRelation(Relation scanrel)
Definition: execUtils.c:696
struct TsmRoutine * tsmroutine
Definition: execnodes.h:1150
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1126
EndSampleScan_function EndSampleScan
Definition: tsmapi.h:74
ScanState ss
Definition: execnodes.h:1146

◆ ExecInitSampleScan()

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

Definition at line 113 of file nodeSamplescan.c.

References TableSampleClause::args, Assert, ExecAssignExprContext(), ExecAssignScanProjectionInfo(), ExecInitExpr(), ExecInitExprList(), ExecInitQual(), ExecInitResultTupleSlotTL(), 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, SampleScan::tablesample, and TableSampleClause::tsmhandler.

Referenced by ExecInitNode().

114 {
115  SampleScanState *scanstate;
116  TableSampleClause *tsc = node->tablesample;
117  TsmRoutine *tsm;
118 
119  Assert(outerPlan(node) == NULL);
120  Assert(innerPlan(node) == NULL);
121 
122  /*
123  * create state structure
124  */
125  scanstate = makeNode(SampleScanState);
126  scanstate->ss.ps.plan = (Plan *) node;
127  scanstate->ss.ps.state = estate;
128  scanstate->ss.ps.ExecProcNode = ExecSampleScan;
129 
130  /*
131  * Miscellaneous initialization
132  *
133  * create expression context for node
134  */
135  ExecAssignExprContext(estate, &scanstate->ss.ps);
136 
137  /*
138  * Initialize scan relation.
139  *
140  * Get the relation object id from the relid'th entry in the range table,
141  * open that relation and acquire appropriate lock on it.
142  */
143  scanstate->ss.ss_currentRelation =
144  ExecOpenScanRelation(estate,
145  node->scan.scanrelid,
146  eflags);
147 
148  /* we won't set up the HeapScanDesc till later */
149  scanstate->ss.ss_currentScanDesc = NULL;
150 
151  /* and create slot with appropriate rowtype */
152  ExecInitScanTupleSlot(estate, &scanstate->ss,
154 
155  /*
156  * Initialize result slot, type and projection.
157  * tuple table and result tuple initialization
158  */
159  ExecInitResultTupleSlotTL(estate, &scanstate->ss.ps);
160  ExecAssignScanProjectionInfo(&scanstate->ss);
161 
162  /*
163  * initialize child expressions
164  */
165  scanstate->ss.ps.qual =
166  ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
167 
168  scanstate->args = ExecInitExprList(tsc->args, (PlanState *) scanstate);
169  scanstate->repeatable =
170  ExecInitExpr(tsc->repeatable, (PlanState *) scanstate);
171 
172  /*
173  * If we don't have a REPEATABLE clause, select a random seed. We want to
174  * do this just once, since the seed shouldn't change over rescans.
175  */
176  if (tsc->repeatable == NULL)
177  scanstate->seed = random();
178 
179  /*
180  * Finally, initialize the TABLESAMPLE method handler.
181  */
182  tsm = GetTsmRoutine(tsc->tsmhandler);
183  scanstate->tsmroutine = tsm;
184  scanstate->tsm_state = NULL;
185 
186  if (tsm->InitSampleScan)
187  tsm->InitSampleScan(scanstate, eflags);
188 
189  /* We'll do BeginSampleScan later; we can't evaluate params yet */
190  scanstate->begun = false;
191 
192  return scanstate;
193 }
InitSampleScan_function InitSampleScan
Definition: tsmapi.h:70
List * qual
Definition: plannodes.h:145
Plan plan
Definition: plannodes.h:330
Index scanrelid
Definition: plannodes.h:331
#define RelationGetDescr(relation)
Definition: rel.h:437
long random(void)
Definition: random.c:22
void * tsm_state
Definition: execnodes.h:1151
struct TableSampleClause * tablesample
Definition: plannodes.h:348
Relation ss_currentRelation
Definition: execnodes.h:1125
EState * state
Definition: execnodes.h:870
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:204
PlanState ps
Definition: execnodes.h:1124
void ExecAssignScanProjectionInfo(ScanState *node)
Definition: execScan.c:235
Scan scan
Definition: plannodes.h:346
Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
Definition: execUtils.c:638
#define innerPlan(node)
Definition: plannodes.h:173
List * ExecInitExprList(List *nodes, PlanState *parent)
Definition: execExpr.c:313
ExprState * repeatable
Definition: execnodes.h:1148
#define outerPlan(node)
Definition: plannodes.h:174
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:874
void ExecInitResultTupleSlotTL(EState *estate, PlanState *planstate)
Definition: execTuples.c:870
Plan * plan
Definition: execnodes.h:868
TsmRoutine * GetTsmRoutine(Oid tsmhandler)
Definition: tablesample.c:27
#define makeNode(_type_)
Definition: nodes.h:561
#define Assert(condition)
Definition: c.h:688
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:425
struct TsmRoutine * tsmroutine
Definition: execnodes.h:1150
ExprState * qual
Definition: execnodes.h:886
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1126
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc)
Definition: execTuples.c:895
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
Definition: execExpr.c:118
static TupleTableSlot * ExecSampleScan(PlanState *pstate)
ScanState ss
Definition: execnodes.h:1146

◆ ExecReScanSampleScan()

void ExecReScanSampleScan ( SampleScanState node)

Definition at line 241 of file nodeSamplescan.c.

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

Referenced by ExecReScan().

242 {
243  /* Remember we need to do BeginSampleScan again (if we did it at all) */
244  node->begun = false;
245 
246  ExecScanReScan(&node->ss);
247 }
void ExecScanReScan(ScanState *node)
Definition: execScan.c:262
ScanState ss
Definition: execnodes.h:1146