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

180 {
181  /*
182  * Tell sampling function that we finished the scan.
183  */
184  if (node->tsmroutine->EndSampleScan)
185  node->tsmroutine->EndSampleScan(node);
186 
187  /*
188  * close heap scan
189  */
190  if (node->ss.ss_currentScanDesc)
192 }
ScanState ss
Definition: execnodes.h:1586
struct TsmRoutine * tsmroutine
Definition: execnodes.h:1590
struct TableScanDescData * ss_currentScanDesc
Definition: execnodes.h:1566
EndSampleScan_function EndSampleScan
Definition: tsmapi.h:75
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:1029

References TsmRoutine::EndSampleScan, SampleScanState::ss, ScanState::ss_currentScanDesc, table_endscan(), and SampleScanState::tsmroutine.

Referenced by ExecEndNode().

◆ ExecInitSampleScan()

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

Definition at line 93 of file nodeSamplescan.c.

94 {
95  SampleScanState *scanstate;
96  TableSampleClause *tsc = node->tablesample;
97  TsmRoutine *tsm;
98 
99  Assert(outerPlan(node) == NULL);
100  Assert(innerPlan(node) == NULL);
101 
102  /*
103  * create state structure
104  */
105  scanstate = makeNode(SampleScanState);
106  scanstate->ss.ps.plan = (Plan *) node;
107  scanstate->ss.ps.state = estate;
108  scanstate->ss.ps.ExecProcNode = ExecSampleScan;
109 
110  /*
111  * Miscellaneous initialization
112  *
113  * create expression context for node
114  */
115  ExecAssignExprContext(estate, &scanstate->ss.ps);
116 
117  /*
118  * open the scan relation
119  */
120  scanstate->ss.ss_currentRelation =
121  ExecOpenScanRelation(estate,
122  node->scan.scanrelid,
123  eflags);
124 
125  /* we won't set up the HeapScanDesc till later */
126  scanstate->ss.ss_currentScanDesc = NULL;
127 
128  /* and create slot with appropriate rowtype */
129  ExecInitScanTupleSlot(estate, &scanstate->ss,
132 
133  /*
134  * Initialize result type and projection.
135  */
136  ExecInitResultTypeTL(&scanstate->ss.ps);
137  ExecAssignScanProjectionInfo(&scanstate->ss);
138 
139  /*
140  * initialize child expressions
141  */
142  scanstate->ss.ps.qual =
143  ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
144 
145  scanstate->args = ExecInitExprList(tsc->args, (PlanState *) scanstate);
146  scanstate->repeatable =
147  ExecInitExpr(tsc->repeatable, (PlanState *) scanstate);
148 
149  /*
150  * If we don't have a REPEATABLE clause, select a random seed. We want to
151  * do this just once, since the seed shouldn't change over rescans.
152  */
153  if (tsc->repeatable == NULL)
155 
156  /*
157  * Finally, initialize the TABLESAMPLE method handler.
158  */
159  tsm = GetTsmRoutine(tsc->tsmhandler);
160  scanstate->tsmroutine = tsm;
161  scanstate->tsm_state = NULL;
162 
163  if (tsm->InitSampleScan)
164  tsm->InitSampleScan(scanstate, eflags);
165 
166  /* We'll do BeginSampleScan later; we can't evaluate params yet */
167  scanstate->begun = false;
168 
169  return scanstate;
170 }
#define Assert(condition)
Definition: c.h:858
List * ExecInitExprList(List *nodes, PlanState *parent)
Definition: execExpr.c:326
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:220
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
Definition: execExpr.c:134
void ExecAssignScanProjectionInfo(ScanState *node)
Definition: execScan.c:270
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1898
void ExecInitResultTypeTL(PlanState *planstate)
Definition: execTuples.c:1842
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:483
Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
Definition: execUtils.c:697
static TupleTableSlot * ExecSampleScan(PlanState *pstate)
#define makeNode(_type_)
Definition: nodes.h:155
uint32 pg_prng_uint32(pg_prng_state *state)
Definition: pg_prng.c:227
pg_prng_state pg_global_prng_state
Definition: pg_prng.c:34
#define innerPlan(node)
Definition: plannodes.h:181
#define outerPlan(node)
Definition: plannodes.h:182
#define RelationGetDescr(relation)
Definition: rel.h:531
ExprState * qual
Definition: execnodes.h:1138
Plan * plan
Definition: execnodes.h:1117
EState * state
Definition: execnodes.h:1119
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1123
ExprState * repeatable
Definition: execnodes.h:1588
void * tsm_state
Definition: execnodes.h:1591
struct TableSampleClause * tablesample
Definition: plannodes.h:409
Scan scan
Definition: plannodes.h:407
Relation ss_currentRelation
Definition: execnodes.h:1565
PlanState ps
Definition: execnodes.h:1564
Index scanrelid
Definition: plannodes.h:389
InitSampleScan_function InitSampleScan
Definition: tsmapi.h:71
const TupleTableSlotOps * table_slot_callbacks(Relation relation)
Definition: tableam.c:58
TsmRoutine * GetTsmRoutine(Oid tsmhandler)
Definition: tablesample.c:27

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

Referenced by ExecInitNode().

◆ ExecReScanSampleScan()

void ExecReScanSampleScan ( SampleScanState node)

Definition at line 202 of file nodeSamplescan.c.

203 {
204  /* Remember we need to do BeginSampleScan again (if we did it at all) */
205  node->begun = false;
206  node->done = false;
207  node->haveblock = false;
208  node->donetuples = 0;
209 
210  ExecScanReScan(&node->ss);
211 }
void ExecScanReScan(ScanState *node)
Definition: execScan.c:297

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

Referenced by ExecReScan().