#include "nodes/execnodes.h"#include "nodes/relation.h"

Go to the source code of this file.
| typedef int(* AcquireSampleRowsFunc)(Relation relation, int elevel, HeapTuple *rows, int targrows, double *totalrows, double *totaldeadrows) |
| typedef void(* AddForeignUpdateTargets_function)(Query *parsetree, RangeTblEntry *target_rte, Relation target_relation) |
| typedef bool(* AnalyzeForeignTable_function)(Relation relation, AcquireSampleRowsFunc *func, BlockNumber *totalpages) |
| typedef void(* BeginForeignModify_function)(ModifyTableState *mtstate, ResultRelInfo *rinfo, List *fdw_private, int subplan_index, int eflags) |
| typedef void(* BeginForeignScan_function)(ForeignScanState *node, int eflags) |
| typedef void(* EndForeignModify_function)(EState *estate, ResultRelInfo *rinfo) |
| typedef void(* EndForeignScan_function)(ForeignScanState *node) |
| typedef TupleTableSlot*(* ExecForeignDelete_function)(EState *estate, ResultRelInfo *rinfo, TupleTableSlot *slot, TupleTableSlot *planSlot) |
| 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 void(* ExplainForeignModify_function)(ModifyTableState *mtstate, ResultRelInfo *rinfo, List *fdw_private, int subplan_index, struct ExplainState *es) |
| typedef void(* ExplainForeignScan_function)(ForeignScanState *node, struct ExplainState *es) |
| typedef struct FdwRoutine FdwRoutine |
| 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) |
| typedef void(* GetForeignRelSize_function)(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid) |
| typedef TupleTableSlot*(* IterateForeignScan_function)(ForeignScanState *node) |
| typedef List*(* PlanForeignModify_function)(PlannerInfo *root, ModifyTable *plan, Index resultRelation, int subplan_index) |
| typedef void(* ReScanForeignScan_function)(ForeignScanState *node) |
| FdwRoutine* GetFdwRoutine | ( | Oid | fdwhandler | ) |
Definition at line 290 of file foreign.c.
References DatumGetPointer, elog, ERROR, IsA, NULL, and OidFunctionCall0.
Referenced by GetFdwRoutineByRelId().
{
Datum datum;
FdwRoutine *routine;
datum = OidFunctionCall0(fdwhandler);
routine = (FdwRoutine *) DatumGetPointer(datum);
if (routine == NULL || !IsA(routine, FdwRoutine))
elog(ERROR, "foreign-data wrapper handler function %u did not return an FdwRoutine struct",
fdwhandler);
return routine;
}
| FdwRoutine* GetFdwRoutineByRelId | ( | Oid | relid | ) |
Definition at line 311 of file foreign.c.
References elog, ereport, errcode(), errmsg(), ERROR, FOREIGNDATAWRAPPEROID, FOREIGNSERVEROID, FOREIGNTABLEREL, GetFdwRoutine(), GETSTRUCT, HeapTupleIsValid, NameStr, ObjectIdGetDatum, OidIsValid, ReleaseSysCache(), and SearchSysCache1.
Referenced by GetFdwRoutineForRelation(), and make_modifytable().
{
HeapTuple tp;
Form_pg_foreign_data_wrapper fdwform;
Form_pg_foreign_server serverform;
Form_pg_foreign_table tableform;
Oid serverid;
Oid fdwid;
Oid fdwhandler;
/* Get server OID for the foreign table. */
tp = SearchSysCache1(FOREIGNTABLEREL, ObjectIdGetDatum(relid));
if (!HeapTupleIsValid(tp))
elog(ERROR, "cache lookup failed for foreign table %u", relid);
tableform = (Form_pg_foreign_table) GETSTRUCT(tp);
serverid = tableform->ftserver;
ReleaseSysCache(tp);
/* Get foreign-data wrapper OID for the server. */
tp = SearchSysCache1(FOREIGNSERVEROID, ObjectIdGetDatum(serverid));
if (!HeapTupleIsValid(tp))
elog(ERROR, "cache lookup failed for foreign server %u", serverid);
serverform = (Form_pg_foreign_server) GETSTRUCT(tp);
fdwid = serverform->srvfdw;
ReleaseSysCache(tp);
/* Get handler function OID for the FDW. */
tp = SearchSysCache1(FOREIGNDATAWRAPPEROID, ObjectIdGetDatum(fdwid));
if (!HeapTupleIsValid(tp))
elog(ERROR, "cache lookup failed for foreign-data wrapper %u", fdwid);
fdwform = (Form_pg_foreign_data_wrapper) GETSTRUCT(tp);
fdwhandler = fdwform->fdwhandler;
/* Complain if FDW has been set to NO HANDLER. */
if (!OidIsValid(fdwhandler))
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("foreign-data wrapper \"%s\" has no handler",
NameStr(fdwform->fdwname))));
ReleaseSysCache(tp);
/* And finally, call the handler function. */
return GetFdwRoutine(fdwhandler);
}
| FdwRoutine* GetFdwRoutineForRelation | ( | Relation | relation, | |
| bool | makecopy | |||
| ) |
Definition at line 369 of file foreign.c.
References CacheMemoryContext, GetFdwRoutineByRelId(), MemoryContextAlloc(), NULL, palloc(), RelationData::rd_fdwroutine, and RelationGetRelid.
Referenced by analyze_rel(), CheckValidResultRel(), ExecInitForeignScan(), get_relation_info(), InitResultRelInfo(), and rewriteTargetListUD().
{
FdwRoutine *fdwroutine;
FdwRoutine *cfdwroutine;
if (relation->rd_fdwroutine == NULL)
{
/* Get the info by consulting the catalogs and the FDW code */
fdwroutine = GetFdwRoutineByRelId(RelationGetRelid(relation));
/* Save the data for later reuse in CacheMemoryContext */
cfdwroutine = (FdwRoutine *) MemoryContextAlloc(CacheMemoryContext,
sizeof(FdwRoutine));
memcpy(cfdwroutine, fdwroutine, sizeof(FdwRoutine));
relation->rd_fdwroutine = cfdwroutine;
/* Give back the locally palloc'd copy regardless of makecopy */
return fdwroutine;
}
/* We have valid cached data --- does the caller want a copy? */
if (makecopy)
{
fdwroutine = (FdwRoutine *) palloc(sizeof(FdwRoutine));
memcpy(fdwroutine, relation->rd_fdwroutine, sizeof(FdwRoutine));
return fdwroutine;
}
/* Only a short-lived reference is needed, so just hand back cached copy */
return relation->rd_fdwroutine;
}
1.7.1