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 425 of file nodeForeignscan.c.

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

Referenced by ExecAsyncConfigureWait().

426 {
427  ForeignScanState *node = (ForeignScanState *) areq->requestee;
428  FdwRoutine *fdwroutine = node->fdwroutine;
429 
430  Assert(fdwroutine->ForeignAsyncConfigureWait != NULL);
431  fdwroutine->ForeignAsyncConfigureWait(areq);
432 }
struct PlanState * requestee
Definition: execnodes.h:537
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1861
#define Assert(condition)
Definition: c.h:804

◆ ExecAsyncForeignScanNotify()

void ExecAsyncForeignScanNotify ( AsyncRequest areq)

Definition at line 441 of file nodeForeignscan.c.

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

Referenced by ExecAsyncNotify().

442 {
443  ForeignScanState *node = (ForeignScanState *) areq->requestee;
444  FdwRoutine *fdwroutine = node->fdwroutine;
445 
446  Assert(fdwroutine->ForeignAsyncNotify != NULL);
447  fdwroutine->ForeignAsyncNotify(areq);
448 }
struct PlanState * requestee
Definition: execnodes.h:537
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1861
#define Assert(condition)
Definition: c.h:804

◆ ExecAsyncForeignScanRequest()

void ExecAsyncForeignScanRequest ( AsyncRequest areq)

Definition at line 409 of file nodeForeignscan.c.

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

Referenced by ExecAsyncRequest().

410 {
411  ForeignScanState *node = (ForeignScanState *) areq->requestee;
412  FdwRoutine *fdwroutine = node->fdwroutine;
413 
414  Assert(fdwroutine->ForeignAsyncRequest != NULL);
415  fdwroutine->ForeignAsyncRequest(areq);
416 }
struct PlanState * requestee
Definition: execnodes.h:537
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1861
#define Assert(condition)
Definition: c.h:804

◆ ExecEndForeignScan()

void ExecEndForeignScan ( ForeignScanState node)

Definition at line 255 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, and ScanState::ss_ScanTupleSlot.

Referenced by ExecEndNode().

256 {
257  ForeignScan *plan = (ForeignScan *) node->ss.ps.plan;
258 
259  /* Let the FDW shut down */
260  if (plan->operation != CMD_SELECT)
261  node->fdwroutine->EndDirectModify(node);
262  else
263  node->fdwroutine->EndForeignScan(node);
264 
265  /* Shut down any outer plan. */
266  if (outerPlanState(node))
268 
269  /* Free the exprcontext */
270  ExecFreeExprContext(&node->ss.ps);
271 
272  /* clean out the tuple table */
273  if (node->ss.ps.ps_ResultTupleSlot)
276 }
EndDirectModify_function EndDirectModify
Definition: fdwapi.h:244
ScanState ss
Definition: execnodes.h:1856
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:425
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:556
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1379
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:650
CmdType operation
Definition: plannodes.h:634
PlanState ps
Definition: execnodes.h:1376
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:1003
#define outerPlanState(node)
Definition: execnodes.h:1061
EndForeignScan_function EndForeignScan
Definition: fdwapi.h:215
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1861
Plan * plan
Definition: execnodes.h:965

◆ ExecForeignScan()

static TupleTableSlot* ExecForeignScan ( PlanState pstate)
static

Definition at line 111 of file nodeForeignscan.c.

References castNode, ExecScan(), ForeignNext(), ForeignRecheck(), and ForeignScanState::ss.

Referenced by ExecInitForeignScan().

112 {
113  ForeignScanState *node = castNode(ForeignScanState, pstate);
114 
115  return ExecScan(&node->ss,
118 }
ScanState ss
Definition: execnodes.h:1856
#define castNode(_type_, nodeptr)
Definition: nodes.h:608
TupleTableSlot * ExecScan(ScanState *node, ExecScanAccessMtd accessMtd, ExecScanRecheckMtd recheckMtd)
Definition: execScan.c:158
static bool ForeignRecheck(ForeignScanState *node, TupleTableSlot *slot)
bool(* ExecScanRecheckMtd)(ScanState *node, TupleTableSlot *slot)
Definition: executor.h:457
static TupleTableSlot * ForeignNext(ForeignScanState *node)
TupleTableSlot *(* ExecScanAccessMtd)(ScanState *node)
Definition: executor.h:456

◆ ExecForeignScanEstimate()

void ExecForeignScanEstimate ( ForeignScanState node,
ParallelContext pcxt 
)

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

310 {
311  FdwRoutine *fdwroutine = node->fdwroutine;
312 
313  if (fdwroutine->EstimateDSMForeignScan)
314  {
315  node->pscan_len = fdwroutine->EstimateDSMForeignScan(node, pcxt);
317  shm_toc_estimate_keys(&pcxt->estimator, 1);
318  }
319 }
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:1861
#define shm_toc_estimate_keys(e, cnt)
Definition: shm_toc.h:53

◆ ExecForeignScanInitializeDSM()

void ExecForeignScanInitializeDSM ( ForeignScanState node,
ParallelContext pcxt 
)

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

329 {
330  FdwRoutine *fdwroutine = node->fdwroutine;
331 
332  if (fdwroutine->InitializeDSMForeignScan)
333  {
334  int plan_node_id = node->ss.ps.plan->plan_node_id;
335  void *coordinate;
336 
337  coordinate = shm_toc_allocate(pcxt->toc, node->pscan_len);
338  fdwroutine->InitializeDSMForeignScan(node, pcxt, coordinate);
339  shm_toc_insert(pcxt->toc, plan_node_id, coordinate);
340  }
341 }
ScanState ss
Definition: execnodes.h:1856
int plan_node_id
Definition: plannodes.h:140
PlanState ps
Definition: execnodes.h:1376
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1861
InitializeDSMForeignScan_function InitializeDSMForeignScan
Definition: fdwapi.h:268
Plan * plan
Definition: execnodes.h:965
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 371 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().

373 {
374  FdwRoutine *fdwroutine = node->fdwroutine;
375 
376  if (fdwroutine->InitializeWorkerForeignScan)
377  {
378  int plan_node_id = node->ss.ps.plan->plan_node_id;
379  void *coordinate;
380 
381  coordinate = shm_toc_lookup(pwcxt->toc, plan_node_id, false);
382  fdwroutine->InitializeWorkerForeignScan(node, pwcxt->toc, coordinate);
383  }
384 }
ScanState ss
Definition: execnodes.h:1856
InitializeWorkerForeignScan_function InitializeWorkerForeignScan
Definition: fdwapi.h:270
int plan_node_id
Definition: plannodes.h:140
PlanState ps
Definition: execnodes.h:1376
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1861
Plan * plan
Definition: execnodes.h:965
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 350 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().

351 {
352  FdwRoutine *fdwroutine = node->fdwroutine;
353 
354  if (fdwroutine->ReInitializeDSMForeignScan)
355  {
356  int plan_node_id = node->ss.ps.plan->plan_node_id;
357  void *coordinate;
358 
359  coordinate = shm_toc_lookup(pcxt->toc, plan_node_id, false);
360  fdwroutine->ReInitializeDSMForeignScan(node, pcxt, coordinate);
361  }
362 }
ScanState ss
Definition: execnodes.h:1856
int plan_node_id
Definition: plannodes.h:140
PlanState ps
Definition: execnodes.h:1376
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1861
Plan * plan
Definition: execnodes.h:965
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 126 of file nodeForeignscan.c.

References Assert, PlanState::async_capable, FdwRoutine::BeginDirectModify, FdwRoutine::BeginForeignScan, CMD_SELECT, CreateTupleDescCopy(), 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().

127 {
128  ForeignScanState *scanstate;
129  Relation currentRelation = NULL;
130  Index scanrelid = node->scan.scanrelid;
131  Index tlistvarno;
132  FdwRoutine *fdwroutine;
133 
134  /* check for unsupported flags */
135  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
136 
137  /*
138  * create state structure
139  */
140  scanstate = makeNode(ForeignScanState);
141  scanstate->ss.ps.plan = (Plan *) node;
142  scanstate->ss.ps.state = estate;
143  scanstate->ss.ps.ExecProcNode = ExecForeignScan;
144 
145  /*
146  * Miscellaneous initialization
147  *
148  * create expression context for node
149  */
150  ExecAssignExprContext(estate, &scanstate->ss.ps);
151 
152  /*
153  * open the scan relation, if any; also acquire function pointers from the
154  * FDW's handler
155  */
156  if (scanrelid > 0)
157  {
158  currentRelation = ExecOpenScanRelation(estate, scanrelid, eflags);
159  scanstate->ss.ss_currentRelation = currentRelation;
160  fdwroutine = GetFdwRoutineForRelation(currentRelation, true);
161  }
162  else
163  {
164  /* We can't use the relcache, so get fdwroutine the hard way */
165  fdwroutine = GetFdwRoutineByServerId(node->fs_server);
166  }
167 
168  /*
169  * Determine the scan tuple type. If the FDW provided a targetlist
170  * describing the scan tuples, use that; else use base relation's rowtype.
171  */
172  if (node->fdw_scan_tlist != NIL || currentRelation == NULL)
173  {
174  TupleDesc scan_tupdesc;
175 
176  scan_tupdesc = ExecTypeFromTL(node->fdw_scan_tlist);
177  ExecInitScanTupleSlot(estate, &scanstate->ss, scan_tupdesc,
178  &TTSOpsHeapTuple);
179  /* Node's targetlist will contain Vars with varno = INDEX_VAR */
180  tlistvarno = INDEX_VAR;
181  }
182  else
183  {
184  TupleDesc scan_tupdesc;
185 
186  /* don't trust FDWs to return tuples fulfilling NOT NULL constraints */
187  scan_tupdesc = CreateTupleDescCopy(RelationGetDescr(currentRelation));
188  ExecInitScanTupleSlot(estate, &scanstate->ss, scan_tupdesc,
189  &TTSOpsHeapTuple);
190  /* Node's targetlist will contain Vars with varno = scanrelid */
191  tlistvarno = scanrelid;
192  }
193 
194  /* Don't know what an FDW might return */
195  scanstate->ss.ps.scanopsfixed = false;
196  scanstate->ss.ps.scanopsset = true;
197 
198  /*
199  * Initialize result slot, type and projection.
200  */
201  ExecInitResultTypeTL(&scanstate->ss.ps);
202  ExecAssignScanProjectionInfoWithVarno(&scanstate->ss, tlistvarno);
203 
204  /*
205  * initialize child expressions
206  */
207  scanstate->ss.ps.qual =
208  ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
209  scanstate->fdw_recheck_quals =
210  ExecInitQual(node->fdw_recheck_quals, (PlanState *) scanstate);
211 
212  /*
213  * Determine whether to scan the foreign relation asynchronously or not;
214  * this has to be kept in sync with the code in ExecInitAppend().
215  */
216  scanstate->ss.ps.async_capable = (((Plan *) node)->async_capable &&
217  estate->es_epq_active == NULL);
218 
219  /*
220  * Initialize FDW-related state.
221  */
222  scanstate->fdwroutine = fdwroutine;
223  scanstate->fdw_state = NULL;
224 
225  /*
226  * For the FDW's convenience, look up the modification target relation's.
227  * ResultRelInfo.
228  */
229  if (node->resultRelation > 0)
230  scanstate->resultRelInfo = estate->es_result_relations[node->resultRelation - 1];
231 
232  /* Initialize any outer plan. */
233  if (outerPlan(node))
234  outerPlanState(scanstate) =
235  ExecInitNode(outerPlan(node), estate, eflags);
236 
237  /*
238  * Tell the FDW to initialize the scan.
239  */
240  if (node->operation != CMD_SELECT)
241  fdwroutine->BeginDirectModify(scanstate, eflags);
242  else
243  fdwroutine->BeginForeignScan(scanstate, eflags);
244 
245  return scanstate;
246 }
BeginForeignScan_function BeginForeignScan
Definition: fdwapi.h:212
#define NIL
Definition: pg_list.h:65
ScanState ss
Definition: execnodes.h:1856
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:636
#define RelationGetDescr(relation)
Definition: rel.h:495
FdwRoutine * GetFdwRoutineByServerId(Oid serverid)
Definition: foreign.c:362
static TupleTableSlot * ExecForeignScan(PlanState *pstate)
List * fdw_scan_tlist
Definition: plannodes.h:639
Relation ss_currentRelation
Definition: execnodes.h:1377
EState * state
Definition: execnodes.h:967
ExprState * fdw_recheck_quals
Definition: execnodes.h:1857
CmdType operation
Definition: plannodes.h:634
struct EPQState * es_epq_active
Definition: execnodes.h:628
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:209
void ExecAssignScanProjectionInfoWithVarno(ScanState *node, Index varno)
Definition: execScan.c:285
PlanState ps
Definition: execnodes.h:1376
ResultRelInfo * resultRelInfo
Definition: execnodes.h:1859
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:1061
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:1861
List * fdw_recheck_quals
Definition: plannodes.h:640
ResultRelInfo ** es_result_relations
Definition: execnodes.h:574
#define outerPlan(node)
Definition: plannodes.h:171
Index resultRelation
Definition: plannodes.h:635
BeginDirectModify_function BeginDirectModify
Definition: fdwapi.h:242
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:971
unsigned int Index
Definition: c.h:549
Plan * plan
Definition: execnodes.h:965
bool async_capable
Definition: execnodes.h:1007
bool scanopsfixed
Definition: execnodes.h:1043
#define makeNode(_type_)
Definition: nodes.h:587
#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:1047
ExprState * qual
Definition: execnodes.h:986
FdwRoutine * GetFdwRoutineForRelation(Relation relation, bool makecopy)
Definition: foreign.c:427
const TupleTableSlotOps TTSOpsHeapTuple
Definition: execTuples.c:84
#define INDEX_VAR
Definition: primnodes.h:177
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:141

◆ ExecReScanForeignScan()

void ExecReScanForeignScan ( ForeignScanState node)

Definition at line 285 of file nodeForeignscan.c.

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

Referenced by ExecReScan().

286 {
288 
289  node->fdwroutine->ReScanForeignScan(node);
290 
291  /*
292  * If chgParam of subnode is not null then plan will be re-scanned by
293  * first ExecProcNode. outerPlan may also be NULL, in which case there is
294  * nothing to rescan at all.
295  */
296  if (outerPlan != NULL && outerPlan->chgParam == NULL)
297  ExecReScan(outerPlan);
298 
299  ExecScanReScan(&node->ss);
300 }
ScanState ss
Definition: execnodes.h:1856
void ExecReScan(PlanState *node)
Definition: execAmi.c:78
#define outerPlanState(node)
Definition: execnodes.h:1061
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1861
Bitmapset * chgParam
Definition: execnodes.h:997
#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 394 of file nodeForeignscan.c.

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

Referenced by ExecShutdownNode().

395 {
396  FdwRoutine *fdwroutine = node->fdwroutine;
397 
398  if (fdwroutine->ShutdownForeignScan)
399  fdwroutine->ShutdownForeignScan(node);
400 }
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1861
ShutdownForeignScan_function ShutdownForeignScan
Definition: fdwapi.h:271

◆ ForeignNext()

static TupleTableSlot * ForeignNext ( ForeignScanState node)
static

Definition at line 42 of file nodeForeignscan.c.

References CMD_SELECT, ForeignScanState::fdwroutine, ForeignScan::fsSystemCol, FdwRoutine::IterateDirectModify, FdwRoutine::IterateForeignScan, MemoryContextSwitchTo(), ForeignScan::operation, PlanState::plan, ScanState::ps, PlanState::ps_ExprContext, RelationGetRelid, ForeignScanState::ss, ScanState::ss_currentRelation, TupleTableSlot::tts_tableOid, and TupIsNull.

Referenced by ExecForeignScan().

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  slot = node->fdwroutine->IterateDirectModify(node);
53  else
54  slot = node->fdwroutine->IterateForeignScan(node);
55  MemoryContextSwitchTo(oldcontext);
56 
57  /*
58  * Insert valid value into tableoid, the only actually-useful system
59  * column.
60  */
61  if (plan->fsSystemCol && !TupIsNull(slot))
63 
64  return slot;
65 }
Oid tts_tableOid
Definition: tuptable.h:131
ScanState ss
Definition: execnodes.h:1856
ExprContext * ps_ExprContext
Definition: execnodes.h:1004
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
Relation ss_currentRelation
Definition: execnodes.h:1377
CmdType operation
Definition: plannodes.h:634
IterateDirectModify_function IterateDirectModify
Definition: fdwapi.h:243
PlanState ps
Definition: execnodes.h:1376
#define TupIsNull(slot)
Definition: tuptable.h:292
struct FdwRoutine * fdwroutine
Definition: execnodes.h:1861
Plan * plan
Definition: execnodes.h:965
IterateForeignScan_function IterateForeignScan
Definition: fdwapi.h:213
#define RelationGetRelid(relation)
Definition: rel.h:469
bool fsSystemCol
Definition: plannodes.h:642

◆ ForeignRecheck()

static bool ForeignRecheck ( ForeignScanState node,
TupleTableSlot slot 
)
static

Definition at line 71 of file nodeForeignscan.c.

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

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