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) (Query *parsetree, 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 *(* 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 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 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 142 of file fdwapi.h.

◆ AddForeignUpdateTargets_function

typedef void(* AddForeignUpdateTargets_function) (Query *parsetree, 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 147 of file fdwapi.h.

◆ BeginDirectModify_function

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

Definition at line 114 of file fdwapi.h.

◆ BeginForeignInsert_function

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

Definition at line 101 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 77 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 119 of file fdwapi.h.

◆ EndForeignInsert_function

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

Definition at line 104 of file fdwapi.h.

◆ EndForeignModify_function

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

Definition at line 98 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 154 of file fdwapi.h.

◆ ExecForeignDelete_function

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

Definition at line 93 of file fdwapi.h.

◆ ExecForeignInsert_function

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

Definition at line 83 of file fdwapi.h.

◆ ExecForeignUpdate_function

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

Definition at line 88 of file fdwapi.h.

◆ ExplainDirectModify_function

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

Definition at line 139 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 133 of file fdwapi.h.

◆ ExplainForeignScan_function

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

Definition at line 130 of file fdwapi.h.

◆ FdwRoutine

typedef struct FdwRoutine FdwRoutine

◆ 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.

◆ 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 121 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 151 of file fdwapi.h.

◆ InitializeDSMForeignScan_function

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

Definition at line 156 of file fdwapi.h.

◆ InitializeWorkerForeignScan_function

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

Definition at line 162 of file fdwapi.h.

◆ IsForeignRelUpdatable_function

typedef int(* IsForeignRelUpdatable_function) (Relation rel)

Definition at line 107 of file fdwapi.h.

◆ IsForeignScanParallelSafe_function

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

Definition at line 166 of file fdwapi.h.

◆ IterateDirectModify_function

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

Definition at line 117 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 109 of file fdwapi.h.

◆ PlanForeignModify_function

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

Definition at line 72 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 124 of file fdwapi.h.

◆ ReInitializeDSMForeignScan_function

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

Definition at line 159 of file fdwapi.h.

◆ ReparameterizeForeignPathByChild_function

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

Definition at line 169 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 165 of file fdwapi.h.

Function Documentation

◆ GetExistingLocalJoinPath()

Path* GetExistingLocalJoinPath ( RelOptInfo joinrel)

Definition at line 751 of file foreign.c.

References Assert, ForeignPath::fdw_outerpath, 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().

752 {
753  ListCell *lc;
754 
755  Assert(IS_JOIN_REL(joinrel));
756 
757  foreach(lc, joinrel->pathlist)
758  {
759  Path *path = (Path *) lfirst(lc);
760  JoinPath *joinpath = NULL;
761 
762  /* Skip parameterized paths. */
763  if (path->param_info != NULL)
764  continue;
765 
766  switch (path->pathtype)
767  {
768  case T_HashJoin:
769  {
770  HashPath *hash_path = makeNode(HashPath);
771 
772  memcpy(hash_path, path, sizeof(HashPath));
773  joinpath = (JoinPath *) hash_path;
774  }
775  break;
776 
777  case T_NestLoop:
778  {
779  NestPath *nest_path = makeNode(NestPath);
780 
781  memcpy(nest_path, path, sizeof(NestPath));
782  joinpath = (JoinPath *) nest_path;
783  }
784  break;
785 
786  case T_MergeJoin:
787  {
788  MergePath *merge_path = makeNode(MergePath);
789 
790  memcpy(merge_path, path, sizeof(MergePath));
791  joinpath = (JoinPath *) merge_path;
792  }
793  break;
794 
795  default:
796 
797  /*
798  * Just skip anything else. We don't know if corresponding
799  * plan would build the output row from whole-row references
800  * of base relations and execute the EPQ checks.
801  */
802  break;
803  }
804 
805  /* This path isn't good for us, check next. */
806  if (!joinpath)
807  continue;
808 
809  /*
810  * If either inner or outer path is a ForeignPath corresponding to a
811  * pushed down join, replace it with the fdw_outerpath, so that we
812  * maintain path for EPQ checks built entirely of local join
813  * strategies.
814  */
815  if (IsA(joinpath->outerjoinpath, ForeignPath))
816  {
817  ForeignPath *foreign_path;
818 
819  foreign_path = (ForeignPath *) joinpath->outerjoinpath;
820  if (IS_JOIN_REL(foreign_path->path.parent))
821  joinpath->outerjoinpath = foreign_path->fdw_outerpath;
822  }
823 
824  if (IsA(joinpath->innerjoinpath, ForeignPath))
825  {
826  ForeignPath *foreign_path;
827 
828  foreign_path = (ForeignPath *) joinpath->innerjoinpath;
829  if (IS_JOIN_REL(foreign_path->path.parent))
830  joinpath->innerjoinpath = foreign_path->fdw_outerpath;
831  }
832 
833  return (Path *) joinpath;
834  }
835  return NULL;
836 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
Path * fdw_outerpath
Definition: pathnodes.h:1319
Path * innerjoinpath
Definition: pathnodes.h:1496
ParamPathInfo * param_info
Definition: pathnodes.h:1117
#define IS_JOIN_REL(rel)
Definition: pathnodes.h:619
NodeTag pathtype
Definition: pathnodes.h:1112
RelOptInfo * parent
Definition: pathnodes.h:1114
Path * outerjoinpath
Definition: pathnodes.h:1495
#define makeNode(_type_)
Definition: nodes.h:573
#define Assert(condition)
Definition: c.h:732
#define lfirst(lc)
Definition: pg_list.h:190
List * pathlist
Definition: pathnodes.h:655

◆ GetFdwRoutine()

FdwRoutine* GetFdwRoutine ( Oid  fdwhandler)

Definition at line 319 of file foreign.c.

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

Referenced by GetFdwRoutineByServerId(), and ImportForeignSchema().

320 {
321  Datum datum;
322  FdwRoutine *routine;
323 
324  datum = OidFunctionCall0(fdwhandler);
325  routine = (FdwRoutine *) DatumGetPointer(datum);
326 
327  if (routine == NULL || !IsA(routine, FdwRoutine))
328  elog(ERROR, "foreign-data wrapper handler function %u did not return an FdwRoutine struct",
329  fdwhandler);
330 
331  return routine;
332 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
#define ERROR
Definition: elog.h:43
uintptr_t Datum
Definition: postgres.h:367
#define OidFunctionCall0(functionId)
Definition: fmgr.h:653
#define DatumGetPointer(X)
Definition: postgres.h:549
#define elog(elevel,...)
Definition: elog.h:226

◆ GetFdwRoutineByRelId()

FdwRoutine* GetFdwRoutineByRelId ( Oid  relid)

Definition at line 404 of file foreign.c.

References GetFdwRoutineByServerId(), and GetForeignServerIdByRelId().

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

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

◆ GetFdwRoutineByServerId()

FdwRoutine* GetFdwRoutineByServerId ( Oid  serverid)

Definition at line 362 of file foreign.c.

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

Referenced by ExecInitForeignScan(), and GetFdwRoutineByRelId().

363 {
364  HeapTuple tp;
366  Form_pg_foreign_server serverform;
367  Oid fdwid;
368  Oid fdwhandler;
369 
370  /* Get foreign-data wrapper OID for the server. */
372  if (!HeapTupleIsValid(tp))
373  elog(ERROR, "cache lookup failed for foreign server %u", serverid);
374  serverform = (Form_pg_foreign_server) GETSTRUCT(tp);
375  fdwid = serverform->srvfdw;
376  ReleaseSysCache(tp);
377 
378  /* Get handler function OID for the FDW. */
380  if (!HeapTupleIsValid(tp))
381  elog(ERROR, "cache lookup failed for foreign-data wrapper %u", fdwid);
382  fdwform = (Form_pg_foreign_data_wrapper) GETSTRUCT(tp);
383  fdwhandler = fdwform->fdwhandler;
384 
385  /* Complain if FDW has been set to NO HANDLER. */
386  if (!OidIsValid(fdwhandler))
387  ereport(ERROR,
388  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
389  errmsg("foreign-data wrapper \"%s\" has no handler",
390  NameStr(fdwform->fdwname))));
391 
392  ReleaseSysCache(tp);
393 
394  /* And finally, call the handler function. */
395  return GetFdwRoutine(fdwhandler);
396 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
int errcode(int sqlerrcode)
Definition: elog.c:570
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:638
FdwRoutine * GetFdwRoutine(Oid fdwhandler)
Definition: foreign.c:319
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1124
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1172
FormData_pg_foreign_server * Form_pg_foreign_server
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
FormData_pg_foreign_data_wrapper * Form_pg_foreign_data_wrapper
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define elog(elevel,...)
Definition: elog.h:226
#define NameStr(name)
Definition: c.h:609

◆ GetFdwRoutineForRelation()

FdwRoutine* GetFdwRoutineForRelation ( Relation  relation,
bool  makecopy 
)

Definition at line 427 of file foreign.c.

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

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

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

◆ GetForeignServerIdByRelId()

Oid GetForeignServerIdByRelId ( Oid  relid)

Definition at line 340 of file foreign.c.

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

Referenced by get_relation_info(), and GetFdwRoutineByRelId().

341 {
342  HeapTuple tp;
343  Form_pg_foreign_table tableform;
344  Oid serverid;
345 
347  if (!HeapTupleIsValid(tp))
348  elog(ERROR, "cache lookup failed for foreign table %u", relid);
349  tableform = (Form_pg_foreign_table) GETSTRUCT(tp);
350  serverid = tableform->ftserver;
351  ReleaseSysCache(tp);
352 
353  return serverid;
354 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
unsigned int Oid
Definition: postgres_ext.h:31
FormData_pg_foreign_table * Form_pg_foreign_table
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1124
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1172
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define elog(elevel,...)
Definition: elog.h:226

◆ IsImportableForeignTable()

bool IsImportableForeignTable ( const char *  tablename,
ImportForeignSchemaStmt stmt 
)

Definition at line 467 of file foreign.c.

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

469 {
470  ListCell *lc;
471 
472  switch (stmt->list_type)
473  {
475  return true;
476 
478  foreach(lc, stmt->table_list)
479  {
480  RangeVar *rv = (RangeVar *) lfirst(lc);
481 
482  if (strcmp(tablename, rv->relname) == 0)
483  return true;
484  }
485  return false;
486 
488  foreach(lc, stmt->table_list)
489  {
490  RangeVar *rv = (RangeVar *) lfirst(lc);
491 
492  if (strcmp(tablename, rv->relname) == 0)
493  return false;
494  }
495  return true;
496  }
497  return false; /* shouldn't get here */
498 }
char * relname
Definition: primnodes.h:68
#define lfirst(lc)
Definition: pg_list.h:190
ImportForeignSchemaType list_type
Definition: parsenodes.h:2353