PostgreSQL Source Code  git master
nodeForeignscan.c File Reference
#include "postgres.h"
#include "executor/executor.h"
#include "executor/nodeForeignscan.h"
#include "foreign/fdwapi.h"
#include "utils/memutils.h"
#include "utils/rel.h"
Include dependency graph for nodeForeignscan.c:

Go to the source code of this file.

Functions

static TupleTableSlotForeignNext (ForeignScanState *node)
 
static bool ForeignRecheck (ForeignScanState *node, TupleTableSlot *slot)
 
static TupleTableSlotExecForeignScan (PlanState *pstate)
 
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 481 of file nodeForeignscan.c.

482 {
483  ForeignScanState *node = (ForeignScanState *) areq->requestee;
484  FdwRoutine *fdwroutine = node->fdwroutine;
485 
486  Assert(fdwroutine->ForeignAsyncConfigureWait != NULL);
487  fdwroutine->ForeignAsyncConfigureWait(areq);
488 }
Assert(fmt[strlen(fmt) - 1] !='\n')
struct PlanState * requestee
Definition: execnodes.h:596
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1959

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

Referenced by ExecAsyncConfigureWait().

◆ ExecAsyncForeignScanNotify()

void ExecAsyncForeignScanNotify ( AsyncRequest areq)

Definition at line 497 of file nodeForeignscan.c.

498 {
499  ForeignScanState *node = (ForeignScanState *) areq->requestee;
500  FdwRoutine *fdwroutine = node->fdwroutine;
501 
502  Assert(fdwroutine->ForeignAsyncNotify != NULL);
503  fdwroutine->ForeignAsyncNotify(areq);
504 }

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

Referenced by ExecAsyncNotify().

◆ ExecAsyncForeignScanRequest()

void ExecAsyncForeignScanRequest ( AsyncRequest areq)

Definition at line 465 of file nodeForeignscan.c.

466 {
467  ForeignScanState *node = (ForeignScanState *) areq->requestee;
468  FdwRoutine *fdwroutine = node->fdwroutine;
469 
470  Assert(fdwroutine->ForeignAsyncRequest != NULL);
471  fdwroutine->ForeignAsyncRequest(areq);
472 }

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

Referenced by ExecAsyncRequest().

◆ ExecEndForeignScan()

void ExecEndForeignScan ( ForeignScanState node)

Definition at line 298 of file nodeForeignscan.c.

299 {
300  ForeignScan *plan = (ForeignScan *) node->ss.ps.plan;
301  EState *estate = node->ss.ps.state;
302 
303  /* Let the FDW shut down */
304  if (plan->operation != CMD_SELECT)
305  {
306  if (estate->es_epq_active == NULL)
307  node->fdwroutine->EndDirectModify(node);
308  }
309  else
310  node->fdwroutine->EndForeignScan(node);
311 
312  /* Shut down any outer plan. */
313  if (outerPlanState(node))
315 
316  /* Free the exprcontext */
317  ExecFreeExprContext(&node->ss.ps);
318 
319  /* clean out the tuple table */
320  if (node->ss.ps.ps_ResultTupleSlot)
323 }
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:557
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:658
#define outerPlanState(node)
Definition: execnodes.h:1133
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:77
@ CMD_SELECT
Definition: nodes.h:276
#define plan(x)
Definition: pg_regress.c:154
EndForeignScan_function EndForeignScan
Definition: fdwapi.h:215
EndDirectModify_function EndDirectModify
Definition: fdwapi.h:244
ScanState ss
Definition: execnodes.h:1954
Plan * plan
Definition: execnodes.h:1037
EState * state
Definition: execnodes.h:1039
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:1075
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1477
PlanState ps
Definition: execnodes.h:1474
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:433

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

Referenced by ExecEndNode().

◆ ExecForeignScan()

static TupleTableSlot* ExecForeignScan ( PlanState pstate)
static

Definition at line 119 of file nodeForeignscan.c.

120 {
121  ForeignScanState *node = castNode(ForeignScanState, pstate);
122  ForeignScan *plan = (ForeignScan *) node->ss.ps.plan;
123  EState *estate = node->ss.ps.state;
124 
125  /*
126  * Ignore direct modifications when EvalPlanQual is active --- they are
127  * irrelevant for EvalPlanQual rechecking
128  */
129  if (estate->es_epq_active != NULL && plan->operation != CMD_SELECT)
130  return NULL;
131 
132  return ExecScan(&node->ss,
135 }
TupleTableSlot * ExecScan(ScanState *node, ExecScanAccessMtd accessMtd, ExecScanRecheckMtd recheckMtd)
Definition: execScan.c:157
TupleTableSlot *(* ExecScanAccessMtd)(ScanState *node)
Definition: executor.h:472
bool(* ExecScanRecheckMtd)(ScanState *node, TupleTableSlot *slot)
Definition: executor.h:473
static bool ForeignRecheck(ForeignScanState *node, TupleTableSlot *slot)
static TupleTableSlot * ForeignNext(ForeignScanState *node)
#define castNode(_type_, nodeptr)
Definition: nodes.h:197

References castNode, CMD_SELECT, ExecScan(), ForeignNext(), ForeignRecheck(), if(), PlanState::plan, plan, ScanState::ps, ForeignScanState::ss, and PlanState::state.

Referenced by ExecInitForeignScan().

◆ ExecForeignScanEstimate()

void ExecForeignScanEstimate ( ForeignScanState node,
ParallelContext pcxt 
)

Definition at line 365 of file nodeForeignscan.c.

366 {
367  FdwRoutine *fdwroutine = node->fdwroutine;
368 
369  if (fdwroutine->EstimateDSMForeignScan)
370  {
371  node->pscan_len = fdwroutine->EstimateDSMForeignScan(node, pcxt);
373  shm_toc_estimate_keys(&pcxt->estimator, 1);
374  }
375 }
#define shm_toc_estimate_chunk(e, sz)
Definition: shm_toc.h:51
#define shm_toc_estimate_keys(e, cnt)
Definition: shm_toc.h:53
EstimateDSMForeignScan_function EstimateDSMForeignScan
Definition: fdwapi.h:267
shm_toc_estimator estimator
Definition: parallel.h:42

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

Referenced by ExecParallelEstimate().

◆ ExecForeignScanInitializeDSM()

void ExecForeignScanInitializeDSM ( ForeignScanState node,
ParallelContext pcxt 
)

Definition at line 384 of file nodeForeignscan.c.

385 {
386  FdwRoutine *fdwroutine = node->fdwroutine;
387 
388  if (fdwroutine->InitializeDSMForeignScan)
389  {
390  int plan_node_id = node->ss.ps.plan->plan_node_id;
391  void *coordinate;
392 
393  coordinate = shm_toc_allocate(pcxt->toc, node->pscan_len);
394  fdwroutine->InitializeDSMForeignScan(node, pcxt, coordinate);
395  shm_toc_insert(pcxt->toc, plan_node_id, coordinate);
396  }
397 }
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
Definition: shm_toc.c:171
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition: shm_toc.c:88
InitializeDSMForeignScan_function InitializeDSMForeignScan
Definition: fdwapi.h:268
shm_toc * toc
Definition: parallel.h:45
int plan_node_id
Definition: plannodes.h:152

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

◆ ExecForeignScanInitializeWorker()

void ExecForeignScanInitializeWorker ( ForeignScanState node,
ParallelWorkerContext pwcxt 
)

Definition at line 427 of file nodeForeignscan.c.

429 {
430  FdwRoutine *fdwroutine = node->fdwroutine;
431 
432  if (fdwroutine->InitializeWorkerForeignScan)
433  {
434  int plan_node_id = node->ss.ps.plan->plan_node_id;
435  void *coordinate;
436 
437  coordinate = shm_toc_lookup(pwcxt->toc, plan_node_id, false);
438  fdwroutine->InitializeWorkerForeignScan(node, pwcxt->toc, coordinate);
439  }
440 }
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232
InitializeWorkerForeignScan_function InitializeWorkerForeignScan
Definition: fdwapi.h:270

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

Referenced by ExecParallelInitializeWorker().

◆ ExecForeignScanReInitializeDSM()

void ExecForeignScanReInitializeDSM ( ForeignScanState node,
ParallelContext pcxt 
)

Definition at line 406 of file nodeForeignscan.c.

407 {
408  FdwRoutine *fdwroutine = node->fdwroutine;
409 
410  if (fdwroutine->ReInitializeDSMForeignScan)
411  {
412  int plan_node_id = node->ss.ps.plan->plan_node_id;
413  void *coordinate;
414 
415  coordinate = shm_toc_lookup(pcxt->toc, plan_node_id, false);
416  fdwroutine->ReInitializeDSMForeignScan(node, pcxt, coordinate);
417  }
418 }
ReInitializeDSMForeignScan_function ReInitializeDSMForeignScan
Definition: fdwapi.h:269

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

Referenced by ExecParallelReInitializeDSM().

◆ ExecInitForeignScan()

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

Definition at line 143 of file nodeForeignscan.c.

144 {
145  ForeignScanState *scanstate;
146  Relation currentRelation = NULL;
147  Index scanrelid = node->scan.scanrelid;
148  int tlistvarno;
149  FdwRoutine *fdwroutine;
150 
151  /* check for unsupported flags */
152  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
153 
154  /*
155  * create state structure
156  */
157  scanstate = makeNode(ForeignScanState);
158  scanstate->ss.ps.plan = (Plan *) node;
159  scanstate->ss.ps.state = estate;
160  scanstate->ss.ps.ExecProcNode = ExecForeignScan;
161 
162  /*
163  * Miscellaneous initialization
164  *
165  * create expression context for node
166  */
167  ExecAssignExprContext(estate, &scanstate->ss.ps);
168 
169  /*
170  * open the scan relation, if any; also acquire function pointers from the
171  * FDW's handler
172  */
173  if (scanrelid > 0)
174  {
175  currentRelation = ExecOpenScanRelation(estate, scanrelid, eflags);
176  scanstate->ss.ss_currentRelation = currentRelation;
177  fdwroutine = GetFdwRoutineForRelation(currentRelation, true);
178  }
179  else
180  {
181  /* We can't use the relcache, so get fdwroutine the hard way */
182  fdwroutine = GetFdwRoutineByServerId(node->fs_server);
183  }
184 
185  /*
186  * Determine the scan tuple type. If the FDW provided a targetlist
187  * describing the scan tuples, use that; else use base relation's rowtype.
188  */
189  if (node->fdw_scan_tlist != NIL || currentRelation == NULL)
190  {
191  TupleDesc scan_tupdesc;
192 
193  scan_tupdesc = ExecTypeFromTL(node->fdw_scan_tlist);
194  ExecInitScanTupleSlot(estate, &scanstate->ss, scan_tupdesc,
195  &TTSOpsHeapTuple);
196  /* Node's targetlist will contain Vars with varno = INDEX_VAR */
197  tlistvarno = INDEX_VAR;
198  }
199  else
200  {
201  TupleDesc scan_tupdesc;
202 
203  /* don't trust FDWs to return tuples fulfilling NOT NULL constraints */
204  scan_tupdesc = CreateTupleDescCopy(RelationGetDescr(currentRelation));
205  ExecInitScanTupleSlot(estate, &scanstate->ss, scan_tupdesc,
206  &TTSOpsHeapTuple);
207  /* Node's targetlist will contain Vars with varno = scanrelid */
208  tlistvarno = scanrelid;
209  }
210 
211  /* Don't know what an FDW might return */
212  scanstate->ss.ps.scanopsfixed = false;
213  scanstate->ss.ps.scanopsset = true;
214 
215  /*
216  * Initialize result slot, type and projection.
217  */
218  ExecInitResultTypeTL(&scanstate->ss.ps);
219  ExecAssignScanProjectionInfoWithVarno(&scanstate->ss, tlistvarno);
220 
221  /*
222  * initialize child expressions
223  */
224  scanstate->ss.ps.qual =
225  ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
226  scanstate->fdw_recheck_quals =
227  ExecInitQual(node->fdw_recheck_quals, (PlanState *) scanstate);
228 
229  /*
230  * Determine whether to scan the foreign relation asynchronously or not;
231  * this has to be kept in sync with the code in ExecInitAppend().
232  */
233  scanstate->ss.ps.async_capable = (((Plan *) node)->async_capable &&
234  estate->es_epq_active == NULL);
235 
236  /*
237  * Initialize FDW-related state.
238  */
239  scanstate->fdwroutine = fdwroutine;
240  scanstate->fdw_state = NULL;
241 
242  /*
243  * For the FDW's convenience, look up the modification target relation's
244  * ResultRelInfo. The ModifyTable node should have initialized it for us,
245  * see ExecInitModifyTable.
246  *
247  * Don't try to look up the ResultRelInfo when EvalPlanQual is active,
248  * though. Direct modifications cannot be re-evaluated as part of
249  * EvalPlanQual. The lookup wouldn't work anyway because during
250  * EvalPlanQual processing, EvalPlanQual only initializes the subtree
251  * under the ModifyTable, and doesn't run ExecInitModifyTable.
252  */
253  if (node->resultRelation > 0 && estate->es_epq_active == NULL)
254  {
255  if (estate->es_result_relations == NULL ||
256  estate->es_result_relations[node->resultRelation - 1] == NULL)
257  {
258  elog(ERROR, "result relation not initialized");
259  }
260  scanstate->resultRelInfo = estate->es_result_relations[node->resultRelation - 1];
261  }
262 
263  /* Initialize any outer plan. */
264  if (outerPlan(node))
265  outerPlanState(scanstate) =
266  ExecInitNode(outerPlan(node), estate, eflags);
267 
268  /*
269  * Tell the FDW to initialize the scan.
270  */
271  if (node->operation != CMD_SELECT)
272  {
273  /*
274  * Direct modifications cannot be re-evaluated by EvalPlanQual, so
275  * don't bother preparing the FDW.
276  *
277  * In case of an inherited UPDATE/DELETE with foreign targets there
278  * can be direct-modify ForeignScan nodes in the EvalPlanQual subtree,
279  * so we need to ignore such ForeignScan nodes during EvalPlanQual
280  * processing. See also ExecForeignScan/ExecReScanForeignScan.
281  */
282  if (estate->es_epq_active == NULL)
283  fdwroutine->BeginDirectModify(scanstate, eflags);
284  }
285  else
286  fdwroutine->BeginForeignScan(scanstate, eflags);
287 
288  return scanstate;
289 }
unsigned int Index
Definition: c.h:598
#define ERROR
Definition: elog.h:39
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:213
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:142
void ExecAssignScanProjectionInfoWithVarno(ScanState *node, int varno)
Definition: execScan.c:284
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1812
void ExecInitResultTypeTL(PlanState *planstate)
Definition: execTuples.c:1756
const TupleTableSlotOps TTSOpsHeapTuple
Definition: execTuples.c:84
TupleDesc ExecTypeFromTL(List *targetList)
Definition: execTuples.c:1939
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:488
Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
Definition: execUtils.c:728
#define EXEC_FLAG_BACKWARD
Definition: executor.h:68
#define EXEC_FLAG_MARK
Definition: executor.h:69
FdwRoutine * GetFdwRoutineForRelation(Relation relation, bool makecopy)
Definition: foreign.c:429
FdwRoutine * GetFdwRoutineByServerId(Oid serverid)
Definition: foreign.c:364
static TupleTableSlot * ExecForeignScan(PlanState *pstate)
#define makeNode(_type_)
Definition: nodes.h:176
#define NIL
Definition: pg_list.h:68
#define outerPlan(node)
Definition: plannodes.h:183
#define INDEX_VAR
Definition: primnodes.h:216
#define RelationGetDescr(relation)
Definition: rel.h:530
ResultRelInfo ** es_result_relations
Definition: execnodes.h:634
struct EPQState * es_epq_active
Definition: execnodes.h:691
BeginDirectModify_function BeginDirectModify
Definition: fdwapi.h:242
BeginForeignScan_function BeginForeignScan
Definition: fdwapi.h:212
ExprState * fdw_recheck_quals
Definition: execnodes.h:1955
ResultRelInfo * resultRelInfo
Definition: execnodes.h:1957
CmdType operation
Definition: plannodes.h:708
Oid fs_server
Definition: plannodes.h:712
Index resultRelation
Definition: plannodes.h:709
List * fdw_recheck_quals
Definition: plannodes.h:716
List * fdw_scan_tlist
Definition: plannodes.h:715
ExprState * qual
Definition: execnodes.h:1058
bool scanopsset
Definition: execnodes.h:1119
bool scanopsfixed
Definition: execnodes.h:1115
bool async_capable
Definition: execnodes.h:1079
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1043
Relation ss_currentRelation
Definition: execnodes.h:1475
Index scanrelid
Definition: plannodes.h:387
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:111

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(), ForeignScanState::fdw_recheck_quals, ForeignScan::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, PlanState::plan, ScanState::ps, PlanState::qual, RelationGetDescr, ForeignScan::resultRelation, ForeignScanState::resultRelInfo, ForeignScan::scan, PlanState::scanopsfixed, PlanState::scanopsset, Scan::scanrelid, ForeignScanState::ss, ScanState::ss_currentRelation, PlanState::state, and TTSOpsHeapTuple.

Referenced by ExecInitNode().

◆ ExecReScanForeignScan()

void ExecReScanForeignScan ( ForeignScanState node)

Definition at line 332 of file nodeForeignscan.c.

333 {
334  ForeignScan *plan = (ForeignScan *) node->ss.ps.plan;
335  EState *estate = node->ss.ps.state;
337 
338  /*
339  * Ignore direct modifications when EvalPlanQual is active --- they are
340  * irrelevant for EvalPlanQual rechecking
341  */
342  if (estate->es_epq_active != NULL && plan->operation != CMD_SELECT)
343  return;
344 
345  node->fdwroutine->ReScanForeignScan(node);
346 
347  /*
348  * If chgParam of subnode is not null then plan will be re-scanned by
349  * first ExecProcNode. outerPlan may also be NULL, in which case there is
350  * nothing to rescan at all.
351  */
352  if (outerPlan != NULL && outerPlan->chgParam == NULL)
354 
355  ExecScanReScan(&node->ss);
356 }
void ExecReScan(PlanState *node)
Definition: execAmi.c:78
void ExecScanReScan(ScanState *node)
Definition: execScan.c:298
ReScanForeignScan_function ReScanForeignScan
Definition: fdwapi.h:214

References CMD_SELECT, ExecReScan(), ExecScanReScan(), ForeignScanState::fdwroutine, outerPlan, outerPlanState, PlanState::plan, plan, ScanState::ps, FdwRoutine::ReScanForeignScan, ForeignScanState::ss, and PlanState::state.

Referenced by ExecReScan().

◆ ExecShutdownForeignScan()

void ExecShutdownForeignScan ( ForeignScanState node)

Definition at line 450 of file nodeForeignscan.c.

451 {
452  FdwRoutine *fdwroutine = node->fdwroutine;
453 
454  if (fdwroutine->ShutdownForeignScan)
455  fdwroutine->ShutdownForeignScan(node);
456 }
ShutdownForeignScan_function ShutdownForeignScan
Definition: fdwapi.h:271

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

Referenced by ExecShutdownNode_walker().

◆ ForeignNext()

static TupleTableSlot * ForeignNext ( ForeignScanState node)
static

Definition at line 42 of file nodeForeignscan.c.

43 {
44  TupleTableSlot *slot;
45  ForeignScan *plan = (ForeignScan *) node->ss.ps.plan;
46  ExprContext *econtext = node->ss.ps.ps_ExprContext;
47  MemoryContext oldcontext;
48 
49  /* Call the Iterate function in short-lived context */
50  oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
51  if (plan->operation != CMD_SELECT)
52  {
53  /*
54  * direct modifications cannot be re-evaluated, so shouldn't get here
55  * during EvalPlanQual processing
56  */
57  Assert(node->ss.ps.state->es_epq_active == NULL);
58 
59  slot = node->fdwroutine->IterateDirectModify(node);
60  }
61  else
62  slot = node->fdwroutine->IterateForeignScan(node);
63  MemoryContextSwitchTo(oldcontext);
64 
65  /*
66  * Insert valid value into tableoid, the only actually-useful system
67  * column.
68  */
69  if (plan->fsSystemCol && !TupIsNull(slot))
71 
72  return slot;
73 }
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:138
#define RelationGetRelid(relation)
Definition: rel.h:504
IterateDirectModify_function IterateDirectModify
Definition: fdwapi.h:243
IterateForeignScan_function IterateForeignScan
Definition: fdwapi.h:213
ExprContext * ps_ExprContext
Definition: execnodes.h:1076
Oid tts_tableOid
Definition: tuptable.h:131
#define TupIsNull(slot)
Definition: tuptable.h:300

References Assert(), CMD_SELECT, EState::es_epq_active, ForeignScanState::fdwroutine, FdwRoutine::IterateDirectModify, FdwRoutine::IterateForeignScan, MemoryContextSwitchTo(), PlanState::plan, plan, ScanState::ps, PlanState::ps_ExprContext, RelationGetRelid, ForeignScanState::ss, ScanState::ss_currentRelation, PlanState::state, TupleTableSlot::tts_tableOid, and TupIsNull.

Referenced by ExecForeignScan().

◆ ForeignRecheck()

static bool ForeignRecheck ( ForeignScanState node,
TupleTableSlot slot 
)
static

Definition at line 79 of file nodeForeignscan.c.

80 {
81  FdwRoutine *fdwroutine = node->fdwroutine;
82  ExprContext *econtext;
83 
84  /*
85  * extract necessary information from foreign scan node
86  */
87  econtext = node->ss.ps.ps_ExprContext;
88 
89  /* Does the tuple meet the remote qual condition? */
90  econtext->ecxt_scantuple = slot;
91 
92  ResetExprContext(econtext);
93 
94  /*
95  * If an outer join is pushed down, RecheckForeignScan may need to store a
96  * different tuple in the slot, because a different set of columns may go
97  * to NULL upon recheck. Otherwise, it shouldn't need to change the slot
98  * contents, just return true or false to indicate whether the quals still
99  * pass. For simple cases, setting fdw_recheck_quals may be easier than
100  * providing this callback.
101  */
102  if (fdwroutine->RecheckForeignScan &&
103  !fdwroutine->RecheckForeignScan(node, slot))
104  return false;
105 
106  return ExecQual(node->fdw_recheck_quals, econtext);
107 }
#define ResetExprContext(econtext)
Definition: executor.h:543
static bool ExecQual(ExprState *state, ExprContext *econtext)
Definition: executor.h:412
TupleTableSlot * ecxt_scantuple
Definition: execnodes.h:249
RecheckForeignScan_function RecheckForeignScan
Definition: fdwapi.h:249

References ExprContext::ecxt_scantuple, ExecQual(), ForeignScanState::fdw_recheck_quals, ForeignScanState::fdwroutine, ScanState::ps, PlanState::ps_ExprContext, FdwRoutine::RecheckForeignScan, ResetExprContext, and ForeignScanState::ss.

Referenced by ExecForeignScan().