PostgreSQL Source Code  git master
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, ParallelWorkerContext *pwcxt)
 
void ExecShutdownForeignScan (ForeignScanState *node)
 

Function Documentation

◆ ExecEndForeignScan()

void ExecEndForeignScan ( ForeignScanState node)

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

238 {
239  ForeignScan *plan = (ForeignScan *) node->ss.ps.plan;
240 
241  /* Let the FDW shut down */
242  if (plan->operation != CMD_SELECT)
243  node->fdwroutine->EndDirectModify(node);
244  else
245  node->fdwroutine->EndForeignScan(node);
246 
247  /* Shut down any outer plan. */
248  if (outerPlanState(node))
250 
251  /* Free the exprcontext */
252  ExecFreeExprContext(&node->ss.ps);
253 
254  /* clean out the tuple table */
257 
258  /* close the relation. */
259  if (node->ss.ss_currentRelation)
261 }
EndDirectModify_function EndDirectModify
Definition: fdwapi.h:211
ScanState ss
Definition: execnodes.h:1575
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:539
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
CmdType operation
Definition: plannodes.h:600
PlanState ps
Definition: execnodes.h:1124
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:901
#define outerPlanState(node)
Definition: execnodes.h:914
EndForeignScan_function EndForeignScan
Definition: fdwapi.h:186
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1579
Plan * plan
Definition: execnodes.h:868
void ExecCloseScanRelation(Relation scanrel)
Definition: execUtils.c:696

◆ ExecForeignScanEstimate()

void ExecForeignScanEstimate ( ForeignScanState node,
ParallelContext pcxt 
)

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

295 {
296  FdwRoutine *fdwroutine = node->fdwroutine;
297 
298  if (fdwroutine->EstimateDSMForeignScan)
299  {
300  node->pscan_len = fdwroutine->EstimateDSMForeignScan(node, pcxt);
302  shm_toc_estimate_keys(&pcxt->estimator, 1);
303  }
304 }
EstimateDSMForeignScan_function EstimateDSMForeignScan
Definition: fdwapi.h:231
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:1579
#define shm_toc_estimate_keys(e, cnt)
Definition: shm_toc.h:53

◆ ExecForeignScanInitializeDSM()

void ExecForeignScanInitializeDSM ( ForeignScanState node,
ParallelContext pcxt 
)

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

314 {
315  FdwRoutine *fdwroutine = node->fdwroutine;
316 
317  if (fdwroutine->InitializeDSMForeignScan)
318  {
319  int plan_node_id = node->ss.ps.plan->plan_node_id;
320  void *coordinate;
321 
322  coordinate = shm_toc_allocate(pcxt->toc, node->pscan_len);
323  fdwroutine->InitializeDSMForeignScan(node, pcxt, coordinate);
324  shm_toc_insert(pcxt->toc, plan_node_id, coordinate);
325  }
326 }
ScanState ss
Definition: execnodes.h:1575
int plan_node_id
Definition: plannodes.h:143
PlanState ps
Definition: execnodes.h:1124
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1579
InitializeDSMForeignScan_function InitializeDSMForeignScan
Definition: fdwapi.h:232
Plan * plan
Definition: execnodes.h:868
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

◆ ExecForeignScanInitializeWorker()

void ExecForeignScanInitializeWorker ( ForeignScanState node,
ParallelWorkerContext pwcxt 
)

Definition at line 356 of file nodeForeignscan.c.

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

Referenced by ExecParallelInitializeWorker().

358 {
359  FdwRoutine *fdwroutine = node->fdwroutine;
360 
361  if (fdwroutine->InitializeWorkerForeignScan)
362  {
363  int plan_node_id = node->ss.ps.plan->plan_node_id;
364  void *coordinate;
365 
366  coordinate = shm_toc_lookup(pwcxt->toc, plan_node_id, false);
367  fdwroutine->InitializeWorkerForeignScan(node, pwcxt->toc, coordinate);
368  }
369 }
ScanState ss
Definition: execnodes.h:1575
InitializeWorkerForeignScan_function InitializeWorkerForeignScan
Definition: fdwapi.h:234
int plan_node_id
Definition: plannodes.h:143
PlanState ps
Definition: execnodes.h:1124
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1579
Plan * plan
Definition: execnodes.h:868
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232

◆ ExecForeignScanReInitializeDSM()

void ExecForeignScanReInitializeDSM ( ForeignScanState node,
ParallelContext pcxt 
)

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

336 {
337  FdwRoutine *fdwroutine = node->fdwroutine;
338 
339  if (fdwroutine->ReInitializeDSMForeignScan)
340  {
341  int plan_node_id = node->ss.ps.plan->plan_node_id;
342  void *coordinate;
343 
344  coordinate = shm_toc_lookup(pcxt->toc, plan_node_id, false);
345  fdwroutine->ReInitializeDSMForeignScan(node, pcxt, coordinate);
346  }
347 }
ScanState ss
Definition: execnodes.h:1575
int plan_node_id
Definition: plannodes.h:143
PlanState ps
Definition: execnodes.h:1124
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1579
Plan * plan
Definition: execnodes.h:868
ReInitializeDSMForeignScan_function ReInitializeDSMForeignScan
Definition: fdwapi.h:233
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232
shm_toc * toc
Definition: parallel.h:44

◆ ExecInitForeignScan()

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(), ExecAssignScanProjectionInfoWithVarno(), ExecForeignScan(), ExecInitNode(), ExecInitQual(), ExecInitResultTupleSlotTL(), ExecInitScanTupleSlot(), ExecOpenScanRelation(), PlanState::ExecProcNode, ExecTypeFromTL(), ForeignScan::fdw_recheck_quals, ForeignScan::fdw_scan_tlist, 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  * open the base relation, if any, and acquire an appropriate lock on it;
160  * also acquire function pointers from the FDW's handler
161  */
162  if (scanrelid > 0)
163  {
164  currentRelation = ExecOpenScanRelation(estate, scanrelid, eflags);
165  scanstate->ss.ss_currentRelation = currentRelation;
166  fdwroutine = GetFdwRoutineForRelation(currentRelation, true);
167  }
168  else
169  {
170  /* We can't use the relcache, so get fdwroutine the hard way */
171  fdwroutine = GetFdwRoutineByServerId(node->fs_server);
172  }
173 
174  /*
175  * Determine the scan tuple type. If the FDW provided a targetlist
176  * describing the scan tuples, use that; else use base relation's rowtype.
177  */
178  if (node->fdw_scan_tlist != NIL || currentRelation == NULL)
179  {
180  TupleDesc scan_tupdesc;
181 
182  scan_tupdesc = ExecTypeFromTL(node->fdw_scan_tlist, false);
183  ExecInitScanTupleSlot(estate, &scanstate->ss, scan_tupdesc);
184  /* Node's targetlist will contain Vars with varno = INDEX_VAR */
185  tlistvarno = INDEX_VAR;
186  }
187  else
188  {
189  ExecInitScanTupleSlot(estate, &scanstate->ss, RelationGetDescr(currentRelation));
190  /* Node's targetlist will contain Vars with varno = scanrelid */
191  tlistvarno = scanrelid;
192  }
193 
194  /*
195  * Initialize result slot, type and projection.
196  */
197  ExecInitResultTupleSlotTL(estate, &scanstate->ss.ps);
198  ExecAssignScanProjectionInfoWithVarno(&scanstate->ss, tlistvarno);
199 
200  /*
201  * initialize child expressions
202  */
203  scanstate->ss.ps.qual =
204  ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
205  scanstate->fdw_recheck_quals =
206  ExecInitQual(node->fdw_recheck_quals, (PlanState *) scanstate);
207 
208  /*
209  * Initialize FDW-related state.
210  */
211  scanstate->fdwroutine = fdwroutine;
212  scanstate->fdw_state = NULL;
213 
214  /* Initialize any outer plan. */
215  if (outerPlan(node))
216  outerPlanState(scanstate) =
217  ExecInitNode(outerPlan(node), estate, eflags);
218 
219  /*
220  * Tell the FDW to initialize the scan.
221  */
222  if (node->operation != CMD_SELECT)
223  fdwroutine->BeginDirectModify(scanstate, eflags);
224  else
225  fdwroutine->BeginForeignScan(scanstate, eflags);
226 
227  return scanstate;
228 }
BeginForeignScan_function BeginForeignScan
Definition: fdwapi.h:183
#define NIL
Definition: pg_list.h:69
ScanState ss
Definition: execnodes.h:1575
List * qual
Definition: plannodes.h:145
Plan plan
Definition: plannodes.h:330
Index scanrelid
Definition: plannodes.h:331
Oid fs_server
Definition: plannodes.h:601
#define RelationGetDescr(relation)
Definition: rel.h:437
FdwRoutine * GetFdwRoutineByServerId(Oid serverid)
Definition: foreign.c:330
static TupleTableSlot * ExecForeignScan(PlanState *pstate)
List * fdw_scan_tlist
Definition: plannodes.h:604
Relation ss_currentRelation
Definition: execnodes.h:1125
EState * state
Definition: execnodes.h:870
ExprState * fdw_recheck_quals
Definition: execnodes.h:1576
CmdType operation
Definition: plannodes.h:600
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:204
void ExecAssignScanProjectionInfoWithVarno(ScanState *node, Index varno)
Definition: execScan.c:248
PlanState ps
Definition: execnodes.h:1124
Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
Definition: execUtils.c:638
#define EXEC_FLAG_BACKWARD
Definition: executor.h:61
#define outerPlanState(node)
Definition: execnodes.h:914
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1579
List * fdw_recheck_quals
Definition: plannodes.h:605
TupleDesc ExecTypeFromTL(List *targetList, bool hasoid)
Definition: execTuples.c:944
#define outerPlan(node)
Definition: plannodes.h:174
BeginDirectModify_function BeginDirectModify
Definition: fdwapi.h:209
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:874
unsigned int Index
Definition: c.h:431
void ExecInitResultTupleSlotTL(EState *estate, PlanState *planstate)
Definition: execTuples.c:870
Plan * plan
Definition: execnodes.h:868
#define makeNode(_type_)
Definition: nodes.h:561
#define Assert(condition)
Definition: c.h:688
#define EXEC_FLAG_MARK
Definition: executor.h:62
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:425
ExprState * qual
Definition: execnodes.h:886
FdwRoutine * GetFdwRoutineForRelation(Relation relation, bool makecopy)
Definition: foreign.c:395
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc)
Definition: execTuples.c:895
#define INDEX_VAR
Definition: primnodes.h:155
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:139

◆ ExecReScanForeignScan()

void ExecReScanForeignScan ( ForeignScanState node)

Definition at line 270 of file nodeForeignscan.c.

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

Referenced by ExecReScan().

271 {
273 
274  node->fdwroutine->ReScanForeignScan(node);
275 
276  /*
277  * If chgParam of subnode is not null then plan will be re-scanned by
278  * first ExecProcNode. outerPlan may also be NULL, in which case there is
279  * nothing to rescan at all.
280  */
281  if (outerPlan != NULL && outerPlan->chgParam == NULL)
282  ExecReScan(outerPlan);
283 
284  ExecScanReScan(&node->ss);
285 }
ScanState ss
Definition: execnodes.h:1575
void ExecReScan(PlanState *node)
Definition: execAmi.c:76
#define outerPlanState(node)
Definition: execnodes.h:914
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1579
Bitmapset * chgParam
Definition: execnodes.h:896
#define outerPlan(node)
Definition: plannodes.h:174
ReScanForeignScan_function ReScanForeignScan
Definition: fdwapi.h:185
void ExecScanReScan(ScanState *node)
Definition: execScan.c:262

◆ ExecShutdownForeignScan()

void ExecShutdownForeignScan ( ForeignScanState node)

Definition at line 379 of file nodeForeignscan.c.

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

Referenced by ExecShutdownNode().

380 {
381  FdwRoutine *fdwroutine = node->fdwroutine;
382 
383  if (fdwroutine->ShutdownForeignScan)
384  fdwroutine->ShutdownForeignScan(node);
385 }
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1579
ShutdownForeignScan_function ShutdownForeignScan
Definition: fdwapi.h:235