PostgreSQL Source Code  git master
fdwapi.h File Reference
#include "access/parallel.h"
#include "nodes/execnodes.h"
#include "nodes/pathnodes.h"
Include dependency graph for fdwapi.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  FdwRoutine
 

Typedefs

typedef void(* GetForeignRelSize_function) (PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid)
 
typedef void(* GetForeignPaths_function) (PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid)
 
typedef ForeignScan *(* GetForeignPlan_function) (PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid, ForeignPath *best_path, List *tlist, List *scan_clauses, Plan *outer_plan)
 
typedef void(* BeginForeignScan_function) (ForeignScanState *node, int eflags)
 
typedef TupleTableSlot *(* IterateForeignScan_function) (ForeignScanState *node)
 
typedef bool(* RecheckForeignScan_function) (ForeignScanState *node, TupleTableSlot *slot)
 
typedef void(* ReScanForeignScan_function) (ForeignScanState *node)
 
typedef void(* EndForeignScan_function) (ForeignScanState *node)
 
typedef void(* GetForeignJoinPaths_function) (PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, JoinPathExtraData *extra)
 
typedef void(* GetForeignUpperPaths_function) (PlannerInfo *root, UpperRelationKind stage, RelOptInfo *input_rel, RelOptInfo *output_rel, void *extra)
 
typedef void(* AddForeignUpdateTargets_function) (PlannerInfo *root, Index rtindex, RangeTblEntry *target_rte, Relation target_relation)
 
typedef List *(* PlanForeignModify_function) (PlannerInfo *root, ModifyTable *plan, Index resultRelation, int subplan_index)
 
typedef void(* BeginForeignModify_function) (ModifyTableState *mtstate, ResultRelInfo *rinfo, List *fdw_private, int subplan_index, int eflags)
 
typedef TupleTableSlot *(* ExecForeignInsert_function) (EState *estate, ResultRelInfo *rinfo, TupleTableSlot *slot, TupleTableSlot *planSlot)
 
typedef TupleTableSlot **(* ExecForeignBatchInsert_function) (EState *estate, ResultRelInfo *rinfo, TupleTableSlot **slots, TupleTableSlot **planSlots, int *numSlots)
 
typedef int(* GetForeignModifyBatchSize_function) (ResultRelInfo *rinfo)
 
typedef TupleTableSlot *(* ExecForeignUpdate_function) (EState *estate, ResultRelInfo *rinfo, TupleTableSlot *slot, TupleTableSlot *planSlot)
 
typedef TupleTableSlot *(* ExecForeignDelete_function) (EState *estate, ResultRelInfo *rinfo, TupleTableSlot *slot, TupleTableSlot *planSlot)
 
typedef void(* EndForeignModify_function) (EState *estate, ResultRelInfo *rinfo)
 
typedef void(* BeginForeignInsert_function) (ModifyTableState *mtstate, ResultRelInfo *rinfo)
 
typedef void(* EndForeignInsert_function) (EState *estate, ResultRelInfo *rinfo)
 
typedef int(* IsForeignRelUpdatable_function) (Relation rel)
 
typedef bool(* PlanDirectModify_function) (PlannerInfo *root, ModifyTable *plan, Index resultRelation, int subplan_index)
 
typedef void(* BeginDirectModify_function) (ForeignScanState *node, int eflags)
 
typedef TupleTableSlot *(* IterateDirectModify_function) (ForeignScanState *node)
 
typedef void(* EndDirectModify_function) (ForeignScanState *node)
 
typedef RowMarkType(* GetForeignRowMarkType_function) (RangeTblEntry *rte, LockClauseStrength strength)
 
typedef void(* RefetchForeignRow_function) (EState *estate, ExecRowMark *erm, Datum rowid, TupleTableSlot *slot, bool *updated)
 
typedef void(* ExplainForeignScan_function) (ForeignScanState *node, struct ExplainState *es)
 
typedef void(* ExplainForeignModify_function) (ModifyTableState *mtstate, ResultRelInfo *rinfo, List *fdw_private, int subplan_index, struct ExplainState *es)
 
typedef void(* ExplainDirectModify_function) (ForeignScanState *node, struct ExplainState *es)
 
typedef int(* AcquireSampleRowsFunc) (Relation relation, int elevel, HeapTuple *rows, int targrows, double *totalrows, double *totaldeadrows)
 
typedef bool(* AnalyzeForeignTable_function) (Relation relation, AcquireSampleRowsFunc *func, BlockNumber *totalpages)
 
typedef List *(* ImportForeignSchema_function) (ImportForeignSchemaStmt *stmt, Oid serverOid)
 
typedef void(* ExecForeignTruncate_function) (List *rels, DropBehavior behavior, bool restart_seqs)
 
typedef Size(* EstimateDSMForeignScan_function) (ForeignScanState *node, ParallelContext *pcxt)
 
typedef void(* InitializeDSMForeignScan_function) (ForeignScanState *node, ParallelContext *pcxt, void *coordinate)
 
typedef void(* ReInitializeDSMForeignScan_function) (ForeignScanState *node, ParallelContext *pcxt, void *coordinate)
 
typedef void(* InitializeWorkerForeignScan_function) (ForeignScanState *node, shm_toc *toc, void *coordinate)
 
typedef void(* ShutdownForeignScan_function) (ForeignScanState *node)
 
typedef bool(* IsForeignScanParallelSafe_function) (PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
 
typedef List *(* ReparameterizeForeignPathByChild_function) (PlannerInfo *root, List *fdw_private, RelOptInfo *child_rel)
 
typedef bool(* IsForeignPathAsyncCapable_function) (ForeignPath *path)
 
typedef void(* ForeignAsyncRequest_function) (AsyncRequest *areq)
 
typedef void(* ForeignAsyncConfigureWait_function) (AsyncRequest *areq)
 
typedef void(* ForeignAsyncNotify_function) (AsyncRequest *areq)
 
typedef struct FdwRoutine FdwRoutine
 

Functions

FdwRoutineGetFdwRoutine (Oid fdwhandler)
 
Oid GetForeignServerIdByRelId (Oid relid)
 
FdwRoutineGetFdwRoutineByServerId (Oid serverid)
 
FdwRoutineGetFdwRoutineByRelId (Oid relid)
 
FdwRoutineGetFdwRoutineForRelation (Relation relation, bool makecopy)
 
bool IsImportableForeignTable (const char *tablename, ImportForeignSchemaStmt *stmt)
 
PathGetExistingLocalJoinPath (RelOptInfo *joinrel)
 

Typedef Documentation

◆ AcquireSampleRowsFunc

typedef int(* AcquireSampleRowsFunc) (Relation relation, int elevel, HeapTuple *rows, int targrows, double *totalrows, double *totaldeadrows)

Definition at line 151 of file fdwapi.h.

◆ AddForeignUpdateTargets_function

typedef void(* AddForeignUpdateTargets_function) (PlannerInfo *root, Index rtindex, RangeTblEntry *target_rte, Relation target_relation)

Definition at line 68 of file fdwapi.h.

◆ AnalyzeForeignTable_function

typedef bool(* AnalyzeForeignTable_function) (Relation relation, AcquireSampleRowsFunc *func, BlockNumber *totalpages)

Definition at line 156 of file fdwapi.h.

◆ BeginDirectModify_function

typedef void(* BeginDirectModify_function) (ForeignScanState *node, int eflags)

Definition at line 123 of file fdwapi.h.

◆ BeginForeignInsert_function

typedef void(* BeginForeignInsert_function) (ModifyTableState *mtstate, ResultRelInfo *rinfo)

Definition at line 110 of file fdwapi.h.

◆ BeginForeignModify_function

typedef void(* BeginForeignModify_function) (ModifyTableState *mtstate, ResultRelInfo *rinfo, List *fdw_private, int subplan_index, int eflags)

Definition at line 78 of file fdwapi.h.

◆ BeginForeignScan_function

typedef void(* BeginForeignScan_function) (ForeignScanState *node, int eflags)

Definition at line 43 of file fdwapi.h.

◆ EndDirectModify_function

typedef void(* EndDirectModify_function) (ForeignScanState *node)

Definition at line 128 of file fdwapi.h.

◆ EndForeignInsert_function

typedef void(* EndForeignInsert_function) (EState *estate, ResultRelInfo *rinfo)

Definition at line 113 of file fdwapi.h.

◆ EndForeignModify_function

typedef void(* EndForeignModify_function) (EState *estate, ResultRelInfo *rinfo)

Definition at line 107 of file fdwapi.h.

◆ EndForeignScan_function

typedef void(* EndForeignScan_function) (ForeignScanState *node)

Definition at line 53 of file fdwapi.h.

◆ EstimateDSMForeignScan_function

typedef Size(* EstimateDSMForeignScan_function) (ForeignScanState *node, ParallelContext *pcxt)

Definition at line 167 of file fdwapi.h.

◆ ExecForeignBatchInsert_function

typedef TupleTableSlot**(* ExecForeignBatchInsert_function) (EState *estate, ResultRelInfo *rinfo, TupleTableSlot **slots, TupleTableSlot **planSlots, int *numSlots)

Definition at line 89 of file fdwapi.h.

◆ ExecForeignDelete_function

typedef TupleTableSlot*(* ExecForeignDelete_function) (EState *estate, ResultRelInfo *rinfo, TupleTableSlot *slot, TupleTableSlot *planSlot)

Definition at line 102 of file fdwapi.h.

◆ ExecForeignInsert_function

typedef TupleTableSlot*(* ExecForeignInsert_function) (EState *estate, ResultRelInfo *rinfo, TupleTableSlot *slot, TupleTableSlot *planSlot)

Definition at line 84 of file fdwapi.h.

◆ ExecForeignTruncate_function

typedef void(* ExecForeignTruncate_function) (List *rels, DropBehavior behavior, bool restart_seqs)

Definition at line 163 of file fdwapi.h.

◆ ExecForeignUpdate_function

typedef TupleTableSlot*(* ExecForeignUpdate_function) (EState *estate, ResultRelInfo *rinfo, TupleTableSlot *slot, TupleTableSlot *planSlot)

Definition at line 97 of file fdwapi.h.

◆ ExplainDirectModify_function

typedef void(* ExplainDirectModify_function) (ForeignScanState *node, struct ExplainState *es)

Definition at line 148 of file fdwapi.h.

◆ ExplainForeignModify_function

typedef void(* ExplainForeignModify_function) (ModifyTableState *mtstate, ResultRelInfo *rinfo, List *fdw_private, int subplan_index, struct ExplainState *es)

Definition at line 142 of file fdwapi.h.

◆ ExplainForeignScan_function

typedef void(* ExplainForeignScan_function) (ForeignScanState *node, struct ExplainState *es)

Definition at line 139 of file fdwapi.h.

◆ FdwRoutine

typedef struct FdwRoutine FdwRoutine

◆ ForeignAsyncConfigureWait_function

typedef void(* ForeignAsyncConfigureWait_function) (AsyncRequest *areq)

Definition at line 190 of file fdwapi.h.

◆ ForeignAsyncNotify_function

typedef void(* ForeignAsyncNotify_function) (AsyncRequest *areq)

Definition at line 192 of file fdwapi.h.

◆ ForeignAsyncRequest_function

typedef void(* ForeignAsyncRequest_function) (AsyncRequest *areq)

Definition at line 188 of file fdwapi.h.

◆ GetForeignJoinPaths_function

typedef void(* GetForeignJoinPaths_function) (PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, JoinPathExtraData *extra)

Definition at line 55 of file fdwapi.h.

◆ GetForeignModifyBatchSize_function

typedef int(* GetForeignModifyBatchSize_function) (ResultRelInfo *rinfo)

Definition at line 95 of file fdwapi.h.

◆ GetForeignPaths_function

typedef void(* GetForeignPaths_function) (PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid)

Definition at line 31 of file fdwapi.h.

◆ GetForeignPlan_function

typedef ForeignScan*(* GetForeignPlan_function) (PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid, ForeignPath *best_path, List *tlist, List *scan_clauses, Plan *outer_plan)

Definition at line 35 of file fdwapi.h.

◆ GetForeignRelSize_function

typedef void(* GetForeignRelSize_function) (PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid)

Definition at line 27 of file fdwapi.h.

◆ GetForeignRowMarkType_function

typedef RowMarkType(* GetForeignRowMarkType_function) (RangeTblEntry *rte, LockClauseStrength strength)

Definition at line 130 of file fdwapi.h.

◆ GetForeignUpperPaths_function

typedef void(* GetForeignUpperPaths_function) (PlannerInfo *root, UpperRelationKind stage, RelOptInfo *input_rel, RelOptInfo *output_rel, void *extra)

Definition at line 62 of file fdwapi.h.

◆ ImportForeignSchema_function

typedef List*(* ImportForeignSchema_function) (ImportForeignSchemaStmt *stmt, Oid serverOid)

Definition at line 160 of file fdwapi.h.

◆ InitializeDSMForeignScan_function

typedef void(* InitializeDSMForeignScan_function) (ForeignScanState *node, ParallelContext *pcxt, void *coordinate)

Definition at line 169 of file fdwapi.h.

◆ InitializeWorkerForeignScan_function

typedef void(* InitializeWorkerForeignScan_function) (ForeignScanState *node, shm_toc *toc, void *coordinate)

Definition at line 175 of file fdwapi.h.

◆ IsForeignPathAsyncCapable_function

typedef bool(* IsForeignPathAsyncCapable_function) (ForeignPath *path)

Definition at line 186 of file fdwapi.h.

◆ IsForeignRelUpdatable_function

typedef int(* IsForeignRelUpdatable_function) (Relation rel)

Definition at line 116 of file fdwapi.h.

◆ IsForeignScanParallelSafe_function

typedef bool(* IsForeignScanParallelSafe_function) (PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)

Definition at line 179 of file fdwapi.h.

◆ IterateDirectModify_function

typedef TupleTableSlot*(* IterateDirectModify_function) (ForeignScanState *node)

Definition at line 126 of file fdwapi.h.

◆ IterateForeignScan_function

typedef TupleTableSlot*(* IterateForeignScan_function) (ForeignScanState *node)

Definition at line 46 of file fdwapi.h.

◆ PlanDirectModify_function

typedef bool(* PlanDirectModify_function) (PlannerInfo *root, ModifyTable *plan, Index resultRelation, int subplan_index)

Definition at line 118 of file fdwapi.h.

◆ PlanForeignModify_function

typedef List*(* PlanForeignModify_function) (PlannerInfo *root, ModifyTable *plan, Index resultRelation, int subplan_index)

Definition at line 73 of file fdwapi.h.

◆ RecheckForeignScan_function

typedef bool(* RecheckForeignScan_function) (ForeignScanState *node, TupleTableSlot *slot)

Definition at line 48 of file fdwapi.h.

◆ RefetchForeignRow_function

typedef void(* RefetchForeignRow_function) (EState *estate, ExecRowMark *erm, Datum rowid, TupleTableSlot *slot, bool *updated)

Definition at line 133 of file fdwapi.h.

◆ ReInitializeDSMForeignScan_function

typedef void(* ReInitializeDSMForeignScan_function) (ForeignScanState *node, ParallelContext *pcxt, void *coordinate)

Definition at line 172 of file fdwapi.h.

◆ ReparameterizeForeignPathByChild_function

typedef List*(* ReparameterizeForeignPathByChild_function) (PlannerInfo *root, List *fdw_private, RelOptInfo *child_rel)

Definition at line 182 of file fdwapi.h.

◆ ReScanForeignScan_function

typedef void(* ReScanForeignScan_function) (ForeignScanState *node)

Definition at line 51 of file fdwapi.h.

◆ ShutdownForeignScan_function

typedef void(* ShutdownForeignScan_function) (ForeignScanState *node)

Definition at line 178 of file fdwapi.h.

Function Documentation

◆ GetExistingLocalJoinPath()

Path* GetExistingLocalJoinPath ( RelOptInfo joinrel)

Definition at line 719 of file foreign.c.

720 {
721  ListCell *lc;
722 
723  Assert(IS_JOIN_REL(joinrel));
724 
725  foreach(lc, joinrel->pathlist)
726  {
727  Path *path = (Path *) lfirst(lc);
728  JoinPath *joinpath = NULL;
729 
730  /* Skip parameterized paths. */
731  if (path->param_info != NULL)
732  continue;
733 
734  switch (path->pathtype)
735  {
736  case T_HashJoin:
737  {
738  HashPath *hash_path = makeNode(HashPath);
739 
740  memcpy(hash_path, path, sizeof(HashPath));
741  joinpath = (JoinPath *) hash_path;
742  }
743  break;
744 
745  case T_NestLoop:
746  {
747  NestPath *nest_path = makeNode(NestPath);
748 
749  memcpy(nest_path, path, sizeof(NestPath));
750  joinpath = (JoinPath *) nest_path;
751  }
752  break;
753 
754  case T_MergeJoin:
755  {
756  MergePath *merge_path = makeNode(MergePath);
757 
758  memcpy(merge_path, path, sizeof(MergePath));
759  joinpath = (JoinPath *) merge_path;
760  }
761  break;
762 
763  default:
764 
765  /*
766  * Just skip anything else. We don't know if corresponding
767  * plan would build the output row from whole-row references
768  * of base relations and execute the EPQ checks.
769  */
770  break;
771  }
772 
773  /* This path isn't good for us, check next. */
774  if (!joinpath)
775  continue;
776 
777  /*
778  * If either inner or outer path is a ForeignPath corresponding to a
779  * pushed down join, replace it with the fdw_outerpath, so that we
780  * maintain path for EPQ checks built entirely of local join
781  * strategies.
782  */
783  if (IsA(joinpath->outerjoinpath, ForeignPath))
784  {
785  ForeignPath *foreign_path;
786 
787  foreign_path = (ForeignPath *) joinpath->outerjoinpath;
788  if (IS_JOIN_REL(foreign_path->path.parent))
789  joinpath->outerjoinpath = foreign_path->fdw_outerpath;
790  }
791 
792  if (IsA(joinpath->innerjoinpath, ForeignPath))
793  {
794  ForeignPath *foreign_path;
795 
796  foreign_path = (ForeignPath *) joinpath->innerjoinpath;
797  if (IS_JOIN_REL(foreign_path->path.parent))
798  joinpath->innerjoinpath = foreign_path->fdw_outerpath;
799  }
800 
801  return (Path *) joinpath;
802  }
803  return NULL;
804 }
Assert(fmt[strlen(fmt) - 1] !='\n')
#define IsA(nodeptr, _type_)
Definition: nodes.h:624
@ T_MergeJoin
Definition: nodes.h:75
@ T_NestLoop
Definition: nodes.h:74
@ T_HashJoin
Definition: nodes.h:76
#define makeNode(_type_)
Definition: nodes.h:621
#define IS_JOIN_REL(rel)
Definition: pathnodes.h:660
#define lfirst(lc)
Definition: pg_list.h:169
Path * fdw_outerpath
Definition: pathnodes.h:1411
Path * outerjoinpath
Definition: pathnodes.h:1604
Path * innerjoinpath
Definition: pathnodes.h:1605
NodeTag pathtype
Definition: pathnodes.h:1192
RelOptInfo * parent
Definition: pathnodes.h:1194
ParamPathInfo * param_info
Definition: pathnodes.h:1197
List * pathlist
Definition: pathnodes.h:696

References Assert(), ForeignPath::fdw_outerpath, if(), JoinPath::innerjoinpath, IS_JOIN_REL, IsA, lfirst, makeNode, JoinPath::outerjoinpath, Path::param_info, Path::parent, ForeignPath::path, RelOptInfo::pathlist, Path::pathtype, T_HashJoin, T_MergeJoin, and T_NestLoop.

Referenced by postgresGetForeignJoinPaths().

◆ GetFdwRoutine()

FdwRoutine* GetFdwRoutine ( Oid  fdwhandler)

Definition at line 320 of file foreign.c.

321 {
322  Datum datum;
323  FdwRoutine *routine;
324 
325  datum = OidFunctionCall0(fdwhandler);
326  routine = (FdwRoutine *) DatumGetPointer(datum);
327 
328  if (routine == NULL || !IsA(routine, FdwRoutine))
329  elog(ERROR, "foreign-data wrapper handler function %u did not return an FdwRoutine struct",
330  fdwhandler);
331 
332  return routine;
333 }
#define ERROR
Definition: elog.h:33
#define elog(elevel,...)
Definition: elog.h:218
#define OidFunctionCall0(functionId)
Definition: fmgr.h:667
uintptr_t Datum
Definition: postgres.h:411
#define DatumGetPointer(X)
Definition: postgres.h:593

References DatumGetPointer, elog, ERROR, IsA, and OidFunctionCall0.

Referenced by GetFdwRoutineByServerId(), and ImportForeignSchema().

◆ GetFdwRoutineByRelId()

FdwRoutine* GetFdwRoutineByRelId ( Oid  relid)

Definition at line 405 of file foreign.c.

406 {
407  Oid serverid;
408 
409  /* Get server OID for the foreign table. */
410  serverid = GetForeignServerIdByRelId(relid);
411 
412  /* Now retrieve server's FdwRoutine struct. */
413  return GetFdwRoutineByServerId(serverid);
414 }
Oid GetForeignServerIdByRelId(Oid relid)
Definition: foreign.c:341
FdwRoutine * GetFdwRoutineByServerId(Oid serverid)
Definition: foreign.c:363
unsigned int Oid
Definition: postgres_ext.h:31

References GetFdwRoutineByServerId(), and GetForeignServerIdByRelId().

Referenced by GetFdwRoutineForRelation(), make_modifytable(), and select_rowmark_type().

◆ GetFdwRoutineByServerId()

FdwRoutine* GetFdwRoutineByServerId ( Oid  serverid)

Definition at line 363 of file foreign.c.

364 {
365  HeapTuple tp;
367  Form_pg_foreign_server serverform;
368  Oid fdwid;
369  Oid fdwhandler;
370 
371  /* Get foreign-data wrapper OID for the server. */
373  if (!HeapTupleIsValid(tp))
374  elog(ERROR, "cache lookup failed for foreign server %u", serverid);
375  serverform = (Form_pg_foreign_server) GETSTRUCT(tp);
376  fdwid = serverform->srvfdw;
377  ReleaseSysCache(tp);
378 
379  /* Get handler function OID for the FDW. */
381  if (!HeapTupleIsValid(tp))
382  elog(ERROR, "cache lookup failed for foreign-data wrapper %u", fdwid);
383  fdwform = (Form_pg_foreign_data_wrapper) GETSTRUCT(tp);
384  fdwhandler = fdwform->fdwhandler;
385 
386  /* Complain if FDW has been set to NO HANDLER. */
387  if (!OidIsValid(fdwhandler))
388  ereport(ERROR,
389  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
390  errmsg("foreign-data wrapper \"%s\" has no handler",
391  NameStr(fdwform->fdwname))));
392 
393  ReleaseSysCache(tp);
394 
395  /* And finally, call the handler function. */
396  return GetFdwRoutine(fdwhandler);
397 }
#define NameStr(name)
Definition: c.h:681
#define OidIsValid(objectId)
Definition: c.h:710
int errcode(int sqlerrcode)
Definition: elog.c:693
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define ereport(elevel,...)
Definition: elog.h:143
FdwRoutine * GetFdwRoutine(Oid fdwhandler)
Definition: foreign.c:320
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define GETSTRUCT(TUP)
Definition: htup_details.h:649
FormData_pg_foreign_data_wrapper * Form_pg_foreign_data_wrapper
FormData_pg_foreign_server * Form_pg_foreign_server
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1221
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1173
@ FOREIGNSERVEROID
Definition: syscache.h:64
@ FOREIGNDATAWRAPPEROID
Definition: syscache.h:62

References elog, ereport, errcode(), errmsg(), ERROR, FOREIGNDATAWRAPPEROID, FOREIGNSERVEROID, GetFdwRoutine(), GETSTRUCT, HeapTupleIsValid, NameStr, ObjectIdGetDatum, OidIsValid, ReleaseSysCache(), and SearchSysCache1().

Referenced by ExecInitForeignScan(), ExecuteTruncateGuts(), GetFdwRoutineByRelId(), and truncate_check_rel().

◆ GetFdwRoutineForRelation()

FdwRoutine* GetFdwRoutineForRelation ( Relation  relation,
bool  makecopy 
)

Definition at line 428 of file foreign.c.

429 {
430  FdwRoutine *fdwroutine;
431  FdwRoutine *cfdwroutine;
432 
433  if (relation->rd_fdwroutine == NULL)
434  {
435  /* Get the info by consulting the catalogs and the FDW code */
436  fdwroutine = GetFdwRoutineByRelId(RelationGetRelid(relation));
437 
438  /* Save the data for later reuse in CacheMemoryContext */
440  sizeof(FdwRoutine));
441  memcpy(cfdwroutine, fdwroutine, sizeof(FdwRoutine));
442  relation->rd_fdwroutine = cfdwroutine;
443 
444  /* Give back the locally palloc'd copy regardless of makecopy */
445  return fdwroutine;
446  }
447 
448  /* We have valid cached data --- does the caller want a copy? */
449  if (makecopy)
450  {
451  fdwroutine = (FdwRoutine *) palloc(sizeof(FdwRoutine));
452  memcpy(fdwroutine, relation->rd_fdwroutine, sizeof(FdwRoutine));
453  return fdwroutine;
454  }
455 
456  /* Only a short-lived reference is needed, so just hand back cached copy */
457  return relation->rd_fdwroutine;
458 }
FdwRoutine * GetFdwRoutineByRelId(Oid relid)
Definition: foreign.c:405
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:863
MemoryContext CacheMemoryContext
Definition: mcxt.c:51
void * palloc(Size size)
Definition: mcxt.c:1068
#define RelationGetRelid(relation)
Definition: rel.h:489
struct FdwRoutine * rd_fdwroutine
Definition: rel.h:236

References CacheMemoryContext, GetFdwRoutineByRelId(), MemoryContextAlloc(), palloc(), RelationData::rd_fdwroutine, and RelationGetRelid.

Referenced by acquire_inherited_sample_rows(), add_row_identity_columns(), analyze_rel(), CheckValidRowMarkRel(), EvalPlanQualFetchRowMark(), ExecInitForeignScan(), ExecLockRows(), get_relation_info(), InitResultRelInfo(), and relation_is_updatable().

◆ GetForeignServerIdByRelId()

Oid GetForeignServerIdByRelId ( Oid  relid)

Definition at line 341 of file foreign.c.

342 {
343  HeapTuple tp;
344  Form_pg_foreign_table tableform;
345  Oid serverid;
346 
348  if (!HeapTupleIsValid(tp))
349  elog(ERROR, "cache lookup failed for foreign table %u", relid);
350  tableform = (Form_pg_foreign_table) GETSTRUCT(tp);
351  serverid = tableform->ftserver;
352  ReleaseSysCache(tp);
353 
354  return serverid;
355 }
FormData_pg_foreign_table * Form_pg_foreign_table
@ FOREIGNTABLEREL
Definition: syscache.h:65

References elog, ERROR, FOREIGNTABLEREL, GETSTRUCT, HeapTupleIsValid, ObjectIdGetDatum, ReleaseSysCache(), and SearchSysCache1().

Referenced by ExecuteTruncateGuts(), get_relation_info(), GetFdwRoutineByRelId(), and truncate_check_rel().

◆ IsImportableForeignTable()

bool IsImportableForeignTable ( const char *  tablename,
ImportForeignSchemaStmt stmt 
)

Definition at line 468 of file foreign.c.

470 {
471  ListCell *lc;
472 
473  switch (stmt->list_type)
474  {
476  return true;
477 
479  foreach(lc, stmt->table_list)
480  {
481  RangeVar *rv = (RangeVar *) lfirst(lc);
482 
483  if (strcmp(tablename, rv->relname) == 0)
484  return true;
485  }
486  return false;
487 
489  foreach(lc, stmt->table_list)
490  {
491  RangeVar *rv = (RangeVar *) lfirst(lc);
492 
493  if (strcmp(tablename, rv->relname) == 0)
494  return false;
495  }
496  return true;
497  }
498  return false; /* shouldn't get here */
499 }
@ FDW_IMPORT_SCHEMA_LIMIT_TO
Definition: parsenodes.h:2826
@ FDW_IMPORT_SCHEMA_ALL
Definition: parsenodes.h:2825
@ FDW_IMPORT_SCHEMA_EXCEPT
Definition: parsenodes.h:2827
ImportForeignSchemaType list_type
Definition: parsenodes.h:2836
char * relname
Definition: primnodes.h:68

References FDW_IMPORT_SCHEMA_ALL, FDW_IMPORT_SCHEMA_EXCEPT, FDW_IMPORT_SCHEMA_LIMIT_TO, lfirst, ImportForeignSchemaStmt::list_type, RangeVar::relname, and ImportForeignSchemaStmt::table_list.

Referenced by ImportForeignSchema().