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)
 
void ExecAsyncForeignScanRequest (AsyncRequest *areq)
 
void ExecAsyncForeignScanConfigureWait (AsyncRequest *areq)
 
void ExecAsyncForeignScanNotify (AsyncRequest *areq)
 

Function Documentation

◆ ExecAsyncForeignScanConfigureWait()

void ExecAsyncForeignScanConfigureWait ( AsyncRequest areq)

Definition at line 462 of file nodeForeignscan.c.

References Assert, ForeignScanState::fdwroutine, and AsyncRequest::requestee.

Referenced by ExecAsyncConfigureWait().

463 {
464  ForeignScanState *node = (ForeignScanState *) areq->requestee;
465  FdwRoutine *fdwroutine = node->fdwroutine;
466 
467  Assert(fdwroutine->ForeignAsyncConfigureWait != NULL);
468  fdwroutine->ForeignAsyncConfigureWait(areq);
469 }
struct PlanState * requestee
Definition: execnodes.h:538
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1862
#define Assert(condition)
Definition: c.h:804

◆ ExecAsyncForeignScanNotify()

void ExecAsyncForeignScanNotify ( AsyncRequest areq)

Definition at line 478 of file nodeForeignscan.c.

References Assert, ForeignScanState::fdwroutine, and AsyncRequest::requestee.

Referenced by ExecAsyncNotify().

479 {
480  ForeignScanState *node = (ForeignScanState *) areq->requestee;
481  FdwRoutine *fdwroutine = node->fdwroutine;
482 
483  Assert(fdwroutine->ForeignAsyncNotify != NULL);
484  fdwroutine->ForeignAsyncNotify(areq);
485 }
struct PlanState * requestee
Definition: execnodes.h:538
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1862
#define Assert(condition)
Definition: c.h:804

◆ ExecAsyncForeignScanRequest()

void ExecAsyncForeignScanRequest ( AsyncRequest areq)

Definition at line 446 of file nodeForeignscan.c.

References Assert, ForeignScanState::fdwroutine, and AsyncRequest::requestee.

Referenced by ExecAsyncRequest().

447 {
448  ForeignScanState *node = (ForeignScanState *) areq->requestee;
449  FdwRoutine *fdwroutine = node->fdwroutine;
450 
451  Assert(fdwroutine->ForeignAsyncRequest != NULL);
452  fdwroutine->ForeignAsyncRequest(areq);
453 }
struct PlanState * requestee
Definition: execnodes.h:538
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1862
#define Assert(condition)
Definition: c.h:804

◆ ExecEndForeignScan()

void ExecEndForeignScan ( ForeignScanState node)

Definition at line 288 of file nodeForeignscan.c.

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

Referenced by ExecEndNode().

289 {
290  ForeignScan *plan = (ForeignScan *) node->ss.ps.plan;
291  EState *estate = node->ss.ps.state;
292 
293  /* Let the FDW shut down */
294  if (plan->operation != CMD_SELECT)
295  {
296  if (estate->es_epq_active == NULL)
297  node->fdwroutine->EndDirectModify(node);
298  }
299  else
300  node->fdwroutine->EndForeignScan(node);
301 
302  /* Shut down any outer plan. */
303  if (outerPlanState(node))
305 
306  /* Free the exprcontext */
307  ExecFreeExprContext(&node->ss.ps);
308 
309  /* clean out the tuple table */
310  if (node->ss.ps.ps_ResultTupleSlot)
313 }
EndDirectModify_function EndDirectModify
Definition: fdwapi.h:244
ScanState ss
Definition: execnodes.h:1857
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:425
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:556
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1380
EState * state
Definition: execnodes.h:968
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:650
CmdType operation
Definition: plannodes.h:637
PlanState ps
Definition: execnodes.h:1377
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:1004
#define outerPlanState(node)
Definition: execnodes.h:1062
EndForeignScan_function EndForeignScan
Definition: fdwapi.h:215
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1862
Plan * plan
Definition: execnodes.h:966

◆ ExecForeignScanEstimate()

void ExecForeignScanEstimate ( ForeignScanState node,
ParallelContext pcxt 
)

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

347 {
348  FdwRoutine *fdwroutine = node->fdwroutine;
349 
350  if (fdwroutine->EstimateDSMForeignScan)
351  {
352  node->pscan_len = fdwroutine->EstimateDSMForeignScan(node, pcxt);
354  shm_toc_estimate_keys(&pcxt->estimator, 1);
355  }
356 }
EstimateDSMForeignScan_function EstimateDSMForeignScan
Definition: fdwapi.h:267
shm_toc_estimator estimator
Definition: parallel.h:42
#define shm_toc_estimate_chunk(e, sz)
Definition: shm_toc.h:51
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1862
#define shm_toc_estimate_keys(e, cnt)
Definition: shm_toc.h:53

◆ ExecForeignScanInitializeDSM()

void ExecForeignScanInitializeDSM ( ForeignScanState node,
ParallelContext pcxt 
)

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

366 {
367  FdwRoutine *fdwroutine = node->fdwroutine;
368 
369  if (fdwroutine->InitializeDSMForeignScan)
370  {
371  int plan_node_id = node->ss.ps.plan->plan_node_id;
372  void *coordinate;
373 
374  coordinate = shm_toc_allocate(pcxt->toc, node->pscan_len);
375  fdwroutine->InitializeDSMForeignScan(node, pcxt, coordinate);
376  shm_toc_insert(pcxt->toc, plan_node_id, coordinate);
377  }
378 }
ScanState ss
Definition: execnodes.h:1857
int plan_node_id
Definition: plannodes.h:140
PlanState ps
Definition: execnodes.h:1377
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1862
InitializeDSMForeignScan_function InitializeDSMForeignScan
Definition: fdwapi.h:268
Plan * plan
Definition: execnodes.h:966
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:45

◆ ExecForeignScanInitializeWorker()

void ExecForeignScanInitializeWorker ( ForeignScanState node,
ParallelWorkerContext pwcxt 
)

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

410 {
411  FdwRoutine *fdwroutine = node->fdwroutine;
412 
413  if (fdwroutine->InitializeWorkerForeignScan)
414  {
415  int plan_node_id = node->ss.ps.plan->plan_node_id;
416  void *coordinate;
417 
418  coordinate = shm_toc_lookup(pwcxt->toc, plan_node_id, false);
419  fdwroutine->InitializeWorkerForeignScan(node, pwcxt->toc, coordinate);
420  }
421 }
ScanState ss
Definition: execnodes.h:1857
InitializeWorkerForeignScan_function InitializeWorkerForeignScan
Definition: fdwapi.h:270
int plan_node_id
Definition: plannodes.h:140
PlanState ps
Definition: execnodes.h:1377
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1862
Plan * plan
Definition: execnodes.h:966
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 387 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().

388 {
389  FdwRoutine *fdwroutine = node->fdwroutine;
390 
391  if (fdwroutine->ReInitializeDSMForeignScan)
392  {
393  int plan_node_id = node->ss.ps.plan->plan_node_id;
394  void *coordinate;
395 
396  coordinate = shm_toc_lookup(pcxt->toc, plan_node_id, false);
397  fdwroutine->ReInitializeDSMForeignScan(node, pcxt, coordinate);
398  }
399 }
ScanState ss
Definition: execnodes.h:1857
int plan_node_id
Definition: plannodes.h:140
PlanState ps
Definition: execnodes.h:1377
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1862
Plan * plan
Definition: execnodes.h:966
ReInitializeDSMForeignScan_function ReInitializeDSMForeignScan
Definition: fdwapi.h:269
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232
shm_toc * toc
Definition: parallel.h:45

◆ ExecInitForeignScan()

ForeignScanState* ExecInitForeignScan ( ForeignScan node,
EState estate,
int  eflags 
)

Definition at line 136 of file nodeForeignscan.c.

References Assert, PlanState::async_capable, FdwRoutine::BeginDirectModify, FdwRoutine::BeginForeignScan, CMD_SELECT, CreateTupleDescCopy(), elog, ERROR, EState::es_epq_active, EState::es_result_relations, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecAssignExprContext(), ExecAssignScanProjectionInfoWithVarno(), ExecForeignScan(), ExecInitNode(), ExecInitQual(), ExecInitResultTypeTL(), 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::resultRelation, ForeignScan::scan, PlanState::scanopsfixed, PlanState::scanopsset, Scan::scanrelid, ForeignScanState::ss, ScanState::ss_currentRelation, PlanState::state, and TTSOpsHeapTuple.

Referenced by ExecInitNode().

137 {
138  ForeignScanState *scanstate;
139  Relation currentRelation = NULL;
140  Index scanrelid = node->scan.scanrelid;
141  int tlistvarno;
142  FdwRoutine *fdwroutine;
143 
144  /* check for unsupported flags */
145  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
146 
147  /*
148  * create state structure
149  */
150  scanstate = makeNode(ForeignScanState);
151  scanstate->ss.ps.plan = (Plan *) node;
152  scanstate->ss.ps.state = estate;
153  scanstate->ss.ps.ExecProcNode = ExecForeignScan;
154 
155  /*
156  * Miscellaneous initialization
157  *
158  * create expression context for node
159  */
160  ExecAssignExprContext(estate, &scanstate->ss.ps);
161 
162  /*
163  * open the scan relation, if any; also acquire function pointers from the
164  * FDW's handler
165  */
166  if (scanrelid > 0)
167  {
168  currentRelation = ExecOpenScanRelation(estate, scanrelid, eflags);
169  scanstate->ss.ss_currentRelation = currentRelation;
170  fdwroutine = GetFdwRoutineForRelation(currentRelation, true);
171  }
172  else
173  {
174  /* We can't use the relcache, so get fdwroutine the hard way */
175  fdwroutine = GetFdwRoutineByServerId(node->fs_server);
176  }
177 
178  /*
179  * Determine the scan tuple type. If the FDW provided a targetlist
180  * describing the scan tuples, use that; else use base relation's rowtype.
181  */
182  if (node->fdw_scan_tlist != NIL || currentRelation == NULL)
183  {
184  TupleDesc scan_tupdesc;
185 
186  scan_tupdesc = ExecTypeFromTL(node->fdw_scan_tlist);
187  ExecInitScanTupleSlot(estate, &scanstate->ss, scan_tupdesc,
188  &TTSOpsHeapTuple);
189  /* Node's targetlist will contain Vars with varno = INDEX_VAR */
190  tlistvarno = INDEX_VAR;
191  }
192  else
193  {
194  TupleDesc scan_tupdesc;
195 
196  /* don't trust FDWs to return tuples fulfilling NOT NULL constraints */
197  scan_tupdesc = CreateTupleDescCopy(RelationGetDescr(currentRelation));
198  ExecInitScanTupleSlot(estate, &scanstate->ss, scan_tupdesc,
199  &TTSOpsHeapTuple);
200  /* Node's targetlist will contain Vars with varno = scanrelid */
201  tlistvarno = scanrelid;
202  }
203 
204  /* Don't know what an FDW might return */
205  scanstate->ss.ps.scanopsfixed = false;
206  scanstate->ss.ps.scanopsset = true;
207 
208  /*
209  * Initialize result slot, type and projection.
210  */
211  ExecInitResultTypeTL(&scanstate->ss.ps);
212  ExecAssignScanProjectionInfoWithVarno(&scanstate->ss, tlistvarno);
213 
214  /*
215  * initialize child expressions
216  */
217  scanstate->ss.ps.qual =
218  ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
219  scanstate->fdw_recheck_quals =
220  ExecInitQual(node->fdw_recheck_quals, (PlanState *) scanstate);
221 
222  /*
223  * Determine whether to scan the foreign relation asynchronously or not;
224  * this has to be kept in sync with the code in ExecInitAppend().
225  */
226  scanstate->ss.ps.async_capable = (((Plan *) node)->async_capable &&
227  estate->es_epq_active == NULL);
228 
229  /*
230  * Initialize FDW-related state.
231  */
232  scanstate->fdwroutine = fdwroutine;
233  scanstate->fdw_state = NULL;
234 
235  /*
236  * For the FDW's convenience, look up the modification target relation's
237  * ResultRelInfo. The ModifyTable node should have initialized it for us,
238  * see ExecInitModifyTable.
239  *
240  * Don't try to look up the ResultRelInfo when EvalPlanQual is active,
241  * though. Direct modififications cannot be re-evaluated as part of
242  * EvalPlanQual. The lookup wouldn't work anyway because during
243  * EvalPlanQual processing, EvalPlanQual only initializes the subtree
244  * under the ModifyTable, and doesn't run ExecInitModifyTable.
245  */
246  if (node->resultRelation > 0 && estate->es_epq_active == NULL)
247  {
248  if (estate->es_result_relations == NULL ||
249  estate->es_result_relations[node->resultRelation - 1] == NULL)
250  {
251  elog(ERROR, "result relation not initialized");
252  }
253  scanstate->resultRelInfo = estate->es_result_relations[node->resultRelation - 1];
254  }
255 
256  /* Initialize any outer plan. */
257  if (outerPlan(node))
258  outerPlanState(scanstate) =
259  ExecInitNode(outerPlan(node), estate, eflags);
260 
261  /*
262  * Tell the FDW to initialize the scan.
263  */
264  if (node->operation != CMD_SELECT)
265  {
266  /*
267  * Direct modifications cannot be re-evaluated by EvalPlanQual, so
268  * don't bother preparing the FDW. There can be ForeignScan nodes in
269  * the EvalPlanQual subtree, but ExecForeignScan should never be
270  * called on them when EvalPlanQual is active.
271  */
272  if (estate->es_epq_active == NULL)
273  fdwroutine->BeginDirectModify(scanstate, eflags);
274  }
275  else
276  fdwroutine->BeginForeignScan(scanstate, eflags);
277 
278  return scanstate;
279 }
BeginForeignScan_function BeginForeignScan
Definition: fdwapi.h:212
#define NIL
Definition: pg_list.h:65
ScanState ss
Definition: execnodes.h:1857
List * qual
Definition: plannodes.h:142
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:111
Plan plan
Definition: plannodes.h:343
Index scanrelid
Definition: plannodes.h:344
Oid fs_server
Definition: plannodes.h:639
#define RelationGetDescr(relation)
Definition: rel.h:503
FdwRoutine * GetFdwRoutineByServerId(Oid serverid)
Definition: foreign.c:362
static TupleTableSlot * ExecForeignScan(PlanState *pstate)
List * fdw_scan_tlist
Definition: plannodes.h:642
Relation ss_currentRelation
Definition: execnodes.h:1378
EState * state
Definition: execnodes.h:968
ExprState * fdw_recheck_quals
Definition: execnodes.h:1858
CmdType operation
Definition: plannodes.h:637
struct EPQState * es_epq_active
Definition: execnodes.h:629
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:209
PlanState ps
Definition: execnodes.h:1377
#define ERROR
Definition: elog.h:46
ResultRelInfo * resultRelInfo
Definition: execnodes.h:1860
Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
Definition: execUtils.c:720
#define EXEC_FLAG_BACKWARD
Definition: executor.h:58
#define outerPlanState(node)
Definition: execnodes.h:1062
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1811
void ExecInitResultTypeTL(PlanState *planstate)
Definition: execTuples.c:1755
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1862
List * fdw_recheck_quals
Definition: plannodes.h:643
ResultRelInfo ** es_result_relations
Definition: execnodes.h:575
#define outerPlan(node)
Definition: plannodes.h:171
Index resultRelation
Definition: plannodes.h:638
BeginDirectModify_function BeginDirectModify
Definition: fdwapi.h:242
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:972
unsigned int Index
Definition: c.h:549
Plan * plan
Definition: execnodes.h:966
bool async_capable
Definition: execnodes.h:1008
bool scanopsfixed
Definition: execnodes.h:1044
#define makeNode(_type_)
Definition: nodes.h:584
#define Assert(condition)
Definition: c.h:804
#define EXEC_FLAG_MARK
Definition: executor.h:59
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:480
TupleDesc ExecTypeFromTL(List *targetList)
Definition: execTuples.c:1938
bool scanopsset
Definition: execnodes.h:1048
ExprState * qual
Definition: execnodes.h:987
FdwRoutine * GetFdwRoutineForRelation(Relation relation, bool makecopy)
Definition: foreign.c:427
#define elog(elevel,...)
Definition: elog.h:232
const TupleTableSlotOps TTSOpsHeapTuple
Definition: execTuples.c:84
#define INDEX_VAR
Definition: primnodes.h:177
void ExecAssignScanProjectionInfoWithVarno(ScanState *node, int varno)
Definition: execScan.c:285
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:141

◆ ExecReScanForeignScan()

void ExecReScanForeignScan ( ForeignScanState node)

Definition at line 322 of file nodeForeignscan.c.

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

Referenced by ExecReScan().

323 {
325 
326  node->fdwroutine->ReScanForeignScan(node);
327 
328  /*
329  * If chgParam of subnode is not null then plan will be re-scanned by
330  * first ExecProcNode. outerPlan may also be NULL, in which case there is
331  * nothing to rescan at all.
332  */
333  if (outerPlan != NULL && outerPlan->chgParam == NULL)
334  ExecReScan(outerPlan);
335 
336  ExecScanReScan(&node->ss);
337 }
ScanState ss
Definition: execnodes.h:1857
void ExecReScan(PlanState *node)
Definition: execAmi.c:78
#define outerPlanState(node)
Definition: execnodes.h:1062
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1862
Bitmapset * chgParam
Definition: execnodes.h:998
#define outerPlan(node)
Definition: plannodes.h:171
ReScanForeignScan_function ReScanForeignScan
Definition: fdwapi.h:214
void ExecScanReScan(ScanState *node)
Definition: execScan.c:299

◆ ExecShutdownForeignScan()

void ExecShutdownForeignScan ( ForeignScanState node)

Definition at line 431 of file nodeForeignscan.c.

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

Referenced by ExecShutdownNode().

432 {
433  FdwRoutine *fdwroutine = node->fdwroutine;
434 
435  if (fdwroutine->ShutdownForeignScan)
436  fdwroutine->ShutdownForeignScan(node);
437 }
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1862
ShutdownForeignScan_function ShutdownForeignScan
Definition: fdwapi.h:271