PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
nodeForeignscan.h File Reference
#include "access/parallel.h"
#include "nodes/execnodes.h"
Include dependency graph for nodeForeignscan.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

ForeignScanStateExecInitForeignScan (ForeignScan *node, EState *estate, int eflags)
 
void ExecEndForeignScan (ForeignScanState *node)
 
void ExecReScanForeignScan (ForeignScanState *node)
 
void ExecForeignScanEstimate (ForeignScanState *node, ParallelContext *pcxt)
 
void ExecForeignScanInitializeDSM (ForeignScanState *node, ParallelContext *pcxt)
 
void ExecForeignScanReInitializeDSM (ForeignScanState *node, ParallelContext *pcxt)
 
void ExecForeignScanInitializeWorker (ForeignScanState *node, shm_toc *toc)
 
void ExecShutdownForeignScan (ForeignScanState *node)
 

Function Documentation

void ExecEndForeignScan ( ForeignScanState node)

Definition at line 243 of file nodeForeignscan.c.

References CMD_SELECT, FdwRoutine::EndDirectModify, FdwRoutine::EndForeignScan, ExecClearTuple(), ExecCloseScanRelation(), ExecEndNode(), ExecFreeExprContext(), ForeignScanState::fdwroutine, ForeignScan::operation, outerPlanState, PlanState::plan, ScanState::ps, PlanState::ps_ResultTupleSlot, ForeignScanState::ss, ScanState::ss_currentRelation, and ScanState::ss_ScanTupleSlot.

Referenced by ExecEndNode().

244 {
245  ForeignScan *plan = (ForeignScan *) node->ss.ps.plan;
246 
247  /* Let the FDW shut down */
248  if (plan->operation != CMD_SELECT)
249  node->fdwroutine->EndDirectModify(node);
250  else
251  node->fdwroutine->EndForeignScan(node);
252 
253  /* Shut down any outer plan. */
254  if (outerPlanState(node))
256 
257  /* Free the exprcontext */
258  ExecFreeExprContext(&node->ss.ps);
259 
260  /* clean out the tuple table */
263 
264  /* close the relation. */
265  if (node->ss.ss_currentRelation)
267 }
EndDirectModify_function EndDirectModify
Definition: fdwapi.h:208
ScanState ss
Definition: execnodes.h:1543
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:523
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
CmdType operation
Definition: plannodes.h:598
PlanState ps
Definition: execnodes.h:1100
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:880
#define outerPlanState(node)
Definition: execnodes.h:893
EndForeignScan_function EndForeignScan
Definition: fdwapi.h:183
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1547
Plan * plan
Definition: execnodes.h:847
void ExecCloseScanRelation(Relation scanrel)
Definition: execUtils.c:666
void ExecForeignScanEstimate ( ForeignScanState node,
ParallelContext pcxt 
)

Definition at line 300 of file nodeForeignscan.c.

References FdwRoutine::EstimateDSMForeignScan, ParallelContext::estimator, ForeignScanState::fdwroutine, ForeignScanState::pscan_len, shm_toc_estimate_chunk, and shm_toc_estimate_keys.

Referenced by ExecParallelEstimate().

301 {
302  FdwRoutine *fdwroutine = node->fdwroutine;
303 
304  if (fdwroutine->EstimateDSMForeignScan)
305  {
306  node->pscan_len = fdwroutine->EstimateDSMForeignScan(node, pcxt);
308  shm_toc_estimate_keys(&pcxt->estimator, 1);
309  }
310 }
EstimateDSMForeignScan_function EstimateDSMForeignScan
Definition: fdwapi.h:228
shm_toc_estimator estimator
Definition: parallel.h:41
#define shm_toc_estimate_chunk(e, sz)
Definition: shm_toc.h:51
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1547
#define shm_toc_estimate_keys(e, cnt)
Definition: shm_toc.h:53
void ExecForeignScanInitializeDSM ( ForeignScanState node,
ParallelContext pcxt 
)

Definition at line 319 of file nodeForeignscan.c.

References ForeignScanState::fdwroutine, FdwRoutine::InitializeDSMForeignScan, PlanState::plan, Plan::plan_node_id, ScanState::ps, ForeignScanState::pscan_len, shm_toc_allocate(), shm_toc_insert(), ForeignScanState::ss, and ParallelContext::toc.

Referenced by ExecParallelInitializeDSM().

320 {
321  FdwRoutine *fdwroutine = node->fdwroutine;
322 
323  if (fdwroutine->InitializeDSMForeignScan)
324  {
325  int plan_node_id = node->ss.ps.plan->plan_node_id;
326  void *coordinate;
327 
328  coordinate = shm_toc_allocate(pcxt->toc, node->pscan_len);
329  fdwroutine->InitializeDSMForeignScan(node, pcxt, coordinate);
330  shm_toc_insert(pcxt->toc, plan_node_id, coordinate);
331  }
332 }
ScanState ss
Definition: execnodes.h:1543
int plan_node_id
Definition: plannodes.h:143
PlanState ps
Definition: execnodes.h:1100
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1547
InitializeDSMForeignScan_function InitializeDSMForeignScan
Definition: fdwapi.h:229
Plan * plan
Definition: execnodes.h:847
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition: shm_toc.c:88
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
Definition: shm_toc.c:171
shm_toc * toc
Definition: parallel.h:44
void ExecForeignScanInitializeWorker ( ForeignScanState node,
shm_toc toc 
)

Definition at line 362 of file nodeForeignscan.c.

References ForeignScanState::fdwroutine, FdwRoutine::InitializeWorkerForeignScan, PlanState::plan, Plan::plan_node_id, ScanState::ps, shm_toc_lookup(), and ForeignScanState::ss.

Referenced by ExecParallelInitializeWorker().

363 {
364  FdwRoutine *fdwroutine = node->fdwroutine;
365 
366  if (fdwroutine->InitializeWorkerForeignScan)
367  {
368  int plan_node_id = node->ss.ps.plan->plan_node_id;
369  void *coordinate;
370 
371  coordinate = shm_toc_lookup(toc, plan_node_id, false);
372  fdwroutine->InitializeWorkerForeignScan(node, toc, coordinate);
373  }
374 }
ScanState ss
Definition: execnodes.h:1543
InitializeWorkerForeignScan_function InitializeWorkerForeignScan
Definition: fdwapi.h:231
int plan_node_id
Definition: plannodes.h:143
PlanState ps
Definition: execnodes.h:1100
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1547
Plan * plan
Definition: execnodes.h:847
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232
void ExecForeignScanReInitializeDSM ( ForeignScanState node,
ParallelContext pcxt 
)

Definition at line 341 of file nodeForeignscan.c.

References ForeignScanState::fdwroutine, PlanState::plan, Plan::plan_node_id, ScanState::ps, FdwRoutine::ReInitializeDSMForeignScan, shm_toc_lookup(), ForeignScanState::ss, and ParallelContext::toc.

Referenced by ExecParallelReInitializeDSM().

342 {
343  FdwRoutine *fdwroutine = node->fdwroutine;
344 
345  if (fdwroutine->ReInitializeDSMForeignScan)
346  {
347  int plan_node_id = node->ss.ps.plan->plan_node_id;
348  void *coordinate;
349 
350  coordinate = shm_toc_lookup(pcxt->toc, plan_node_id, false);
351  fdwroutine->ReInitializeDSMForeignScan(node, pcxt, coordinate);
352  }
353 }
ScanState ss
Definition: execnodes.h:1543
int plan_node_id
Definition: plannodes.h:143
PlanState ps
Definition: execnodes.h:1100
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1547
Plan * plan
Definition: execnodes.h:847
ReInitializeDSMForeignScan_function ReInitializeDSMForeignScan
Definition: fdwapi.h:230
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232
shm_toc * toc
Definition: parallel.h:44
ForeignScanState* ExecInitForeignScan ( ForeignScan node,
EState estate,
int  eflags 
)

Definition at line 132 of file nodeForeignscan.c.

References Assert, FdwRoutine::BeginDirectModify, FdwRoutine::BeginForeignScan, CMD_SELECT, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecAssignExprContext(), ExecAssignResultTypeFromTL(), ExecAssignScanProjectionInfoWithVarno(), ExecAssignScanType(), ExecForeignScan(), ExecInitNode(), ExecInitQual(), ExecInitResultTupleSlot(), ExecInitScanTupleSlot(), ExecOpenScanRelation(), PlanState::ExecProcNode, ExecTypeFromTL(), ForeignScan::fdw_recheck_quals, ForeignScanState::fdw_recheck_quals, ForeignScan::fdw_scan_tlist, ForeignScanState::fdw_state, ForeignScanState::fdwroutine, ForeignScan::fs_server, GetFdwRoutineByServerId(), GetFdwRoutineForRelation(), INDEX_VAR, makeNode, NIL, ForeignScan::operation, outerPlan, outerPlanState, Scan::plan, PlanState::plan, ScanState::ps, Plan::qual, PlanState::qual, RelationGetDescr, ForeignScan::scan, Scan::scanrelid, ForeignScanState::ss, ScanState::ss_currentRelation, and PlanState::state.

Referenced by ExecInitNode().

133 {
134  ForeignScanState *scanstate;
135  Relation currentRelation = NULL;
136  Index scanrelid = node->scan.scanrelid;
137  Index tlistvarno;
138  FdwRoutine *fdwroutine;
139 
140  /* check for unsupported flags */
141  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
142 
143  /*
144  * create state structure
145  */
146  scanstate = makeNode(ForeignScanState);
147  scanstate->ss.ps.plan = (Plan *) node;
148  scanstate->ss.ps.state = estate;
149  scanstate->ss.ps.ExecProcNode = ExecForeignScan;
150 
151  /*
152  * Miscellaneous initialization
153  *
154  * create expression context for node
155  */
156  ExecAssignExprContext(estate, &scanstate->ss.ps);
157 
158  /*
159  * initialize child expressions
160  */
161  scanstate->ss.ps.qual =
162  ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
163  scanstate->fdw_recheck_quals =
164  ExecInitQual(node->fdw_recheck_quals, (PlanState *) scanstate);
165 
166  /*
167  * tuple table initialization
168  */
169  ExecInitResultTupleSlot(estate, &scanstate->ss.ps);
170  ExecInitScanTupleSlot(estate, &scanstate->ss);
171 
172  /*
173  * open the base relation, if any, and acquire an appropriate lock on it;
174  * also acquire function pointers from the FDW's handler
175  */
176  if (scanrelid > 0)
177  {
178  currentRelation = ExecOpenScanRelation(estate, scanrelid, eflags);
179  scanstate->ss.ss_currentRelation = currentRelation;
180  fdwroutine = GetFdwRoutineForRelation(currentRelation, true);
181  }
182  else
183  {
184  /* We can't use the relcache, so get fdwroutine the hard way */
185  fdwroutine = GetFdwRoutineByServerId(node->fs_server);
186  }
187 
188  /*
189  * Determine the scan tuple type. If the FDW provided a targetlist
190  * describing the scan tuples, use that; else use base relation's rowtype.
191  */
192  if (node->fdw_scan_tlist != NIL || currentRelation == NULL)
193  {
194  TupleDesc scan_tupdesc;
195 
196  scan_tupdesc = ExecTypeFromTL(node->fdw_scan_tlist, false);
197  ExecAssignScanType(&scanstate->ss, scan_tupdesc);
198  /* Node's targetlist will contain Vars with varno = INDEX_VAR */
199  tlistvarno = INDEX_VAR;
200  }
201  else
202  {
203  ExecAssignScanType(&scanstate->ss, RelationGetDescr(currentRelation));
204  /* Node's targetlist will contain Vars with varno = scanrelid */
205  tlistvarno = scanrelid;
206  }
207 
208  /*
209  * Initialize result tuple type and projection info.
210  */
211  ExecAssignResultTypeFromTL(&scanstate->ss.ps);
212  ExecAssignScanProjectionInfoWithVarno(&scanstate->ss, tlistvarno);
213 
214  /*
215  * Initialize FDW-related state.
216  */
217  scanstate->fdwroutine = fdwroutine;
218  scanstate->fdw_state = NULL;
219 
220  /* Initialize any outer plan. */
221  if (outerPlan(node))
222  outerPlanState(scanstate) =
223  ExecInitNode(outerPlan(node), estate, eflags);
224 
225  /*
226  * Tell the FDW to initialize the scan.
227  */
228  if (node->operation != CMD_SELECT)
229  fdwroutine->BeginDirectModify(scanstate, eflags);
230  else
231  fdwroutine->BeginForeignScan(scanstate, eflags);
232 
233  return scanstate;
234 }
BeginForeignScan_function BeginForeignScan
Definition: fdwapi.h:180
#define NIL
Definition: pg_list.h:69
ScanState ss
Definition: execnodes.h:1543
List * qual
Definition: plannodes.h:145
Plan plan
Definition: plannodes.h:328
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate)
Definition: execTuples.c:842
Index scanrelid
Definition: plannodes.h:329
Oid fs_server
Definition: plannodes.h:599
#define RelationGetDescr(relation)
Definition: rel.h:428
FdwRoutine * GetFdwRoutineByServerId(Oid serverid)
Definition: foreign.c:330
static TupleTableSlot * ExecForeignScan(PlanState *pstate)
List * fdw_scan_tlist
Definition: plannodes.h:602
Relation ss_currentRelation
Definition: execnodes.h:1101
EState * state
Definition: execnodes.h:849
ExprState * fdw_recheck_quals
Definition: execnodes.h:1544
CmdType operation
Definition: plannodes.h:598
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:160
void ExecAssignResultTypeFromTL(PlanState *planstate)
Definition: execUtils.c:445
void ExecAssignScanProjectionInfoWithVarno(ScanState *node, Index varno)
Definition: execScan.c:249
PlanState ps
Definition: execnodes.h:1100
void ExecInitResultTupleSlot(EState *estate, PlanState *planstate)
Definition: execTuples.c:832
Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
Definition: execUtils.c:608
#define EXEC_FLAG_BACKWARD
Definition: executor.h:60
#define outerPlanState(node)
Definition: execnodes.h:893
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1547
List * fdw_recheck_quals
Definition: plannodes.h:603
TupleDesc ExecTypeFromTL(List *targetList, bool hasoid)
Definition: execTuples.c:888
#define outerPlan(node)
Definition: plannodes.h:174
BeginDirectModify_function BeginDirectModify
Definition: fdwapi.h:206
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:853
unsigned int Index
Definition: c.h:359
Plan * plan
Definition: execnodes.h:847
#define makeNode(_type_)
Definition: nodes.h:557
#define Assert(condition)
Definition: c.h:664
#define EXEC_FLAG_MARK
Definition: executor.h:61
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:423
ExprState * qual
Definition: execnodes.h:865
FdwRoutine * GetFdwRoutineForRelation(Relation relation, bool makecopy)
Definition: foreign.c:395
void ExecAssignScanType(ScanState *scanstate, TupleDesc tupDesc)
Definition: execUtils.c:545
#define INDEX_VAR
Definition: primnodes.h:155
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:139
void ExecReScanForeignScan ( ForeignScanState node)

Definition at line 276 of file nodeForeignscan.c.

References PlanState::chgParam, ExecReScan(), ExecScanReScan(), ForeignScanState::fdwroutine, outerPlan, outerPlanState, FdwRoutine::ReScanForeignScan, and ForeignScanState::ss.

Referenced by ExecReScan().

277 {
279 
280  node->fdwroutine->ReScanForeignScan(node);
281 
282  /*
283  * If chgParam of subnode is not null then plan will be re-scanned by
284  * first ExecProcNode. outerPlan may also be NULL, in which case there is
285  * nothing to rescan at all.
286  */
287  if (outerPlan != NULL && outerPlan->chgParam == NULL)
288  ExecReScan(outerPlan);
289 
290  ExecScanReScan(&node->ss);
291 }
ScanState ss
Definition: execnodes.h:1543
void ExecReScan(PlanState *node)
Definition: execAmi.c:76
#define outerPlanState(node)
Definition: execnodes.h:893
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1547
Bitmapset * chgParam
Definition: execnodes.h:875
#define outerPlan(node)
Definition: plannodes.h:174
ReScanForeignScan_function ReScanForeignScan
Definition: fdwapi.h:182
void ExecScanReScan(ScanState *node)
Definition: execScan.c:329
void ExecShutdownForeignScan ( ForeignScanState node)

Definition at line 384 of file nodeForeignscan.c.

References ForeignScanState::fdwroutine, and FdwRoutine::ShutdownForeignScan.

Referenced by ExecShutdownNode().

385 {
386  FdwRoutine *fdwroutine = node->fdwroutine;
387 
388  if (fdwroutine->ShutdownForeignScan)
389  fdwroutine->ShutdownForeignScan(node);
390 }
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1547
ShutdownForeignScan_function ShutdownForeignScan
Definition: fdwapi.h:232