Header And Logo

PostgreSQL
| The world's most advanced open source database.

Data Structures | Typedefs | Functions

fdwapi.h File Reference

#include "nodes/execnodes.h"
#include "nodes/relation.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)
typedef void(* BeginForeignScan_function )(ForeignScanState *node, int eflags)
typedef TupleTableSlot *(* IterateForeignScan_function )(ForeignScanState *node)
typedef void(* ReScanForeignScan_function )(ForeignScanState *node)
typedef void(* EndForeignScan_function )(ForeignScanState *node)
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(* 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 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 struct FdwRoutine FdwRoutine

Functions

FdwRoutineGetFdwRoutine (Oid fdwhandler)
FdwRoutineGetFdwRoutineByRelId (Oid relid)
FdwRoutineGetFdwRoutineForRelation (Relation relation, bool makecopy)

Typedef Documentation

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

Definition at line 92 of file fdwapi.h.

typedef void(* AddForeignUpdateTargets_function)(Query *parsetree, RangeTblEntry *target_rte, Relation target_relation)

Definition at line 50 of file fdwapi.h.

Definition at line 97 of file fdwapi.h.

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

Definition at line 59 of file fdwapi.h.

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

Definition at line 41 of file fdwapi.h.

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

Definition at line 80 of file fdwapi.h.

typedef void(* EndForeignScan_function)(ForeignScanState *node)

Definition at line 48 of file fdwapi.h.

Definition at line 75 of file fdwapi.h.

Definition at line 65 of file fdwapi.h.

Definition at line 70 of file fdwapi.h.

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

Definition at line 86 of file fdwapi.h.

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

Definition at line 83 of file fdwapi.h.

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

Definition at line 30 of file fdwapi.h.

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

Definition at line 34 of file fdwapi.h.

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

Definition at line 26 of file fdwapi.h.

Definition at line 44 of file fdwapi.h.

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

Definition at line 54 of file fdwapi.h.

Definition at line 46 of file fdwapi.h.


Function Documentation

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;
}