PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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 struct ExplainState ExplainState
 
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, ExplainState *es)
 
typedef void(* ExplainForeignModify_function) (ModifyTableState *mtstate, ResultRelInfo *rinfo, List *fdw_private, int subplan_index, ExplainState *es)
 
typedef void(* ExplainDirectModify_function) (ForeignScanState *node, 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, 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, ExplainState *es)

Definition at line 142 of file fdwapi.h.

◆ ExplainForeignScan_function

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

Definition at line 139 of file fdwapi.h.

◆ ExplainState

Definition at line 20 of file fdwapi.h.

◆ 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)
extern

Definition at line 830 of file foreign.c.

831{
832 ListCell *lc;
833
834 Assert(IS_JOIN_REL(joinrel));
835
836 foreach(lc, joinrel->pathlist)
837 {
838 Path *path = (Path *) lfirst(lc);
840
841 /* Skip parameterized paths. */
842 if (path->param_info != NULL)
843 continue;
844
845 switch (path->pathtype)
846 {
847 case T_HashJoin:
848 {
850
851 memcpy(hash_path, path, sizeof(HashPath));
853 }
854 break;
855
856 case T_NestLoop:
857 {
859
860 memcpy(nest_path, path, sizeof(NestPath));
862 }
863 break;
864
865 case T_MergeJoin:
866 {
868
869 memcpy(merge_path, path, sizeof(MergePath));
871 }
872 break;
873
874 default:
875
876 /*
877 * Just skip anything else. We don't know if corresponding
878 * plan would build the output row from whole-row references
879 * of base relations and execute the EPQ checks.
880 */
881 break;
882 }
883
884 /* This path isn't good for us, check next. */
885 if (!joinpath)
886 continue;
887
888 /*
889 * If either inner or outer path is a ForeignPath corresponding to a
890 * pushed down join, replace it with the fdw_outerpath, so that we
891 * maintain path for EPQ checks built entirely of local join
892 * strategies.
893 */
894 if (IsA(joinpath->outerjoinpath, ForeignPath))
895 {
897
898 foreign_path = (ForeignPath *) joinpath->outerjoinpath;
899 if (IS_JOIN_REL(foreign_path->path.parent))
900 {
901 joinpath->outerjoinpath = foreign_path->fdw_outerpath;
902
903 if (joinpath->path.pathtype == T_MergeJoin)
904 {
906
907 /*
908 * If the new outer path is already well enough ordered
909 * for the mergejoin, we can skip doing an explicit sort.
910 */
911 if (merge_path->outersortkeys &&
913 joinpath->outerjoinpath->pathkeys,
914 &merge_path->outer_presorted_keys))
916 }
917 }
918 }
919
920 if (IsA(joinpath->innerjoinpath, ForeignPath))
921 {
923
924 foreign_path = (ForeignPath *) joinpath->innerjoinpath;
925 if (IS_JOIN_REL(foreign_path->path.parent))
926 {
927 joinpath->innerjoinpath = foreign_path->fdw_outerpath;
928
929 if (joinpath->path.pathtype == T_MergeJoin)
930 {
932
933 /*
934 * If the new inner path is already well enough ordered
935 * for the mergejoin, we can skip doing an explicit sort.
936 */
937 if (merge_path->innersortkeys &&
938 pathkeys_contained_in(merge_path->innersortkeys,
939 joinpath->innerjoinpath->pathkeys))
941 }
942 }
943 }
944
945 return (Path *) joinpath;
946 }
947 return NULL;
948}
#define Assert(condition)
Definition c.h:945
#define IsA(nodeptr, _type_)
Definition nodes.h:164
#define makeNode(_type_)
Definition nodes.h:161
bool pathkeys_count_contained_in(List *keys1, List *keys2, int *n_common)
Definition pathkeys.c:558
bool pathkeys_contained_in(List *keys1, List *keys2)
Definition pathkeys.c:343
#define IS_JOIN_REL(rel)
Definition pathnodes.h:982
#define lfirst(lc)
Definition pg_list.h:172
#define NIL
Definition pg_list.h:68
static int fb(int x)
List * outersortkeys
Definition pathnodes.h:2458
List * innersortkeys
Definition pathnodes.h:2459
NodeTag pathtype
Definition pathnodes.h:1959
List * pathlist
Definition pathnodes.h:1038

References Assert, fb(), MergePath::innersortkeys, IS_JOIN_REL, IsA, lfirst, makeNode, NIL, MergePath::outersortkeys, pathkeys_contained_in(), pathkeys_count_contained_in(), RelOptInfo::pathlist, and Path::pathtype.

Referenced by postgresGetForeignJoinPaths().

◆ GetFdwRoutine()

FdwRoutine * GetFdwRoutine ( Oid  fdwhandler)
extern

Definition at line 414 of file foreign.c.

415{
416 Datum datum;
417 FdwRoutine *routine;
418
419 /* Check if the access to foreign tables is restricted */
421 {
422 /* there must not be built-in FDW handler */
425 errmsg("access to non-system foreign table is restricted")));
426 }
427
428 datum = OidFunctionCall0(fdwhandler);
429 routine = (FdwRoutine *) DatumGetPointer(datum);
430
431 if (routine == NULL || !IsA(routine, FdwRoutine))
432 elog(ERROR, "foreign-data wrapper handler function %u did not return an FdwRoutine struct",
433 fdwhandler);
434
435 return routine;
436}
#define unlikely(x)
Definition c.h:432
int errcode(int sqlerrcode)
Definition elog.c:874
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
#define ereport(elevel,...)
Definition elog.h:150
#define OidFunctionCall0(functionId)
Definition fmgr.h:720
static char * errmsg
int restrict_nonsystem_relation_kind
Definition postgres.c:108
uint64_t Datum
Definition postgres.h:70
static Pointer DatumGetPointer(Datum X)
Definition postgres.h:332
#define RESTRICT_RELKIND_FOREIGN_TABLE
Definition tcopprot.h:45

References DatumGetPointer(), elog, ereport, errcode(), errmsg, ERROR, fb(), IsA, OidFunctionCall0, restrict_nonsystem_relation_kind, RESTRICT_RELKIND_FOREIGN_TABLE, and unlikely.

Referenced by GetFdwRoutineByServerId(), and ImportForeignSchema().

◆ GetFdwRoutineByRelId()

FdwRoutine * GetFdwRoutineByRelId ( Oid  relid)
extern

Definition at line 508 of file foreign.c.

509{
510 Oid serverid;
511
512 /* Get server OID for the foreign table. */
513 serverid = GetForeignServerIdByRelId(relid);
514
515 /* Now retrieve server's FdwRoutine struct. */
516 return GetFdwRoutineByServerId(serverid);
517}
FdwRoutine * GetFdwRoutineByServerId(Oid serverid)
Definition foreign.c:466
Oid GetForeignServerIdByRelId(Oid relid)
Definition foreign.c:444
unsigned int Oid

References GetFdwRoutineByServerId(), and GetForeignServerIdByRelId().

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

◆ GetFdwRoutineByServerId()

FdwRoutine * GetFdwRoutineByServerId ( Oid  serverid)
extern

Definition at line 466 of file foreign.c.

467{
468 HeapTuple tp;
471 Oid fdwid;
472 Oid fdwhandler;
473
474 /* Get foreign-data wrapper OID for the server. */
476 if (!HeapTupleIsValid(tp))
477 elog(ERROR, "cache lookup failed for foreign server %u", serverid);
479 fdwid = serverform->srvfdw;
480 ReleaseSysCache(tp);
481
482 /* Get handler function OID for the FDW. */
484 if (!HeapTupleIsValid(tp))
485 elog(ERROR, "cache lookup failed for foreign-data wrapper %u", fdwid);
487 fdwhandler = fdwform->fdwhandler;
488
489 /* Complain if FDW has been set to NO HANDLER. */
490 if (!OidIsValid(fdwhandler))
493 errmsg("foreign-data wrapper \"%s\" has no handler",
494 NameStr(fdwform->fdwname))));
495
496 ReleaseSysCache(tp);
497
498 /* And finally, call the handler function. */
499 return GetFdwRoutine(fdwhandler);
500}
#define NameStr(name)
Definition c.h:837
#define OidIsValid(objectId)
Definition c.h:860
FdwRoutine * GetFdwRoutine(Oid fdwhandler)
Definition foreign.c:414
#define HeapTupleIsValid(tuple)
Definition htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
END_CATALOG_STRUCT typedef FormData_pg_foreign_data_wrapper * Form_pg_foreign_data_wrapper
END_CATALOG_STRUCT typedef FormData_pg_foreign_server * Form_pg_foreign_server
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:252
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:264
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:220

References elog, ereport, errcode(), errmsg, ERROR, fb(), Form_pg_foreign_data_wrapper, Form_pg_foreign_server, 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 
)
extern

Definition at line 531 of file foreign.c.

532{
533 FdwRoutine *fdwroutine;
535
536 if (relation->rd_fdwroutine == NULL)
537 {
538 /* Get the info by consulting the catalogs and the FDW code */
539 fdwroutine = GetFdwRoutineByRelId(RelationGetRelid(relation));
540
541 /* Save the data for later reuse in CacheMemoryContext */
543 sizeof(FdwRoutine));
544 memcpy(cfdwroutine, fdwroutine, sizeof(FdwRoutine));
545 relation->rd_fdwroutine = cfdwroutine;
546
547 /* Give back the locally palloc'd copy regardless of makecopy */
548 return fdwroutine;
549 }
550
551 /* We have valid cached data --- does the caller want a copy? */
552 if (makecopy)
553 {
554 fdwroutine = palloc_object(FdwRoutine);
555 memcpy(fdwroutine, relation->rd_fdwroutine, sizeof(FdwRoutine));
556 return fdwroutine;
557 }
558
559 /* Only a short-lived reference is needed, so just hand back cached copy */
560 return relation->rd_fdwroutine;
561}
#define palloc_object(type)
Definition fe_memutils.h:74
FdwRoutine * GetFdwRoutineByRelId(Oid relid)
Definition foreign.c:508
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition mcxt.c:1232
MemoryContext CacheMemoryContext
Definition mcxt.c:169
#define RelationGetRelid(relation)
Definition rel.h:514
struct FdwRoutine * rd_fdwroutine
Definition rel.h:240

References CacheMemoryContext, fb(), GetFdwRoutineByRelId(), MemoryContextAlloc(), palloc_object, 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)
extern

Definition at line 444 of file foreign.c.

445{
446 HeapTuple tp;
448 Oid serverid;
449
451 if (!HeapTupleIsValid(tp))
452 elog(ERROR, "cache lookup failed for foreign table %u", relid);
454 serverid = tableform->ftserver;
455 ReleaseSysCache(tp);
456
457 return serverid;
458}
END_CATALOG_STRUCT typedef FormData_pg_foreign_table * Form_pg_foreign_table

References elog, ERROR, fb(), Form_pg_foreign_table, 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 
)
extern

Definition at line 571 of file foreign.c.

573{
574 ListCell *lc;
575
576 switch (stmt->list_type)
577 {
579 return true;
580
582 foreach(lc, stmt->table_list)
583 {
584 RangeVar *rv = (RangeVar *) lfirst(lc);
585
586 if (strcmp(tablename, rv->relname) == 0)
587 return true;
588 }
589 return false;
590
592 foreach(lc, stmt->table_list)
593 {
594 RangeVar *rv = (RangeVar *) lfirst(lc);
595
596 if (strcmp(tablename, rv->relname) == 0)
597 return false;
598 }
599 return true;
600 }
601 return false; /* shouldn't get here */
602}
#define stmt
@ FDW_IMPORT_SCHEMA_LIMIT_TO
@ FDW_IMPORT_SCHEMA_ALL
@ FDW_IMPORT_SCHEMA_EXCEPT
char * relname
Definition primnodes.h:84

References fb(), FDW_IMPORT_SCHEMA_ALL, FDW_IMPORT_SCHEMA_EXCEPT, FDW_IMPORT_SCHEMA_LIMIT_TO, lfirst, RangeVar::relname, and stmt.

Referenced by ImportForeignSchema().