From 6eb9c5a5657d1fe77b55cc261450f3538d35a94d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 4 May 2024 14:19:15 +0200 Subject: Adding upstream version 13.4. Signed-off-by: Daniel Baumann --- src/include/foreign/fdwapi.h | 262 ++++++++++++++++++++++++++++++++++++++++++ src/include/foreign/foreign.h | 84 ++++++++++++++ 2 files changed, 346 insertions(+) create mode 100644 src/include/foreign/fdwapi.h create mode 100644 src/include/foreign/foreign.h (limited to 'src/include/foreign') diff --git a/src/include/foreign/fdwapi.h b/src/include/foreign/fdwapi.h new file mode 100644 index 0000000..95556df --- /dev/null +++ b/src/include/foreign/fdwapi.h @@ -0,0 +1,262 @@ +/*------------------------------------------------------------------------- + * + * fdwapi.h + * API for foreign-data wrappers + * + * Copyright (c) 2010-2020, PostgreSQL Global Development Group + * + * src/include/foreign/fdwapi.h + * + *------------------------------------------------------------------------- + */ +#ifndef FDWAPI_H +#define FDWAPI_H + +#include "access/parallel.h" +#include "nodes/execnodes.h" +#include "nodes/pathnodes.h" + +/* To avoid including explain.h here, reference ExplainState thus: */ +struct ExplainState; + + +/* + * Callback function signatures --- see fdwhandler.sgml for more info. + */ + +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); + +/* + * FdwRoutine is the struct returned by a foreign-data wrapper's handler + * function. It provides pointers to the callback functions needed by the + * planner and executor. + * + * More function pointers are likely to be added in the future. Therefore + * it's recommended that the handler initialize the struct with + * makeNode(FdwRoutine) so that all fields are set to NULL. This will + * ensure that no fields are accidentally left undefined. + */ +typedef struct FdwRoutine +{ + NodeTag type; + + /* Functions for scanning foreign tables */ + GetForeignRelSize_function GetForeignRelSize; + GetForeignPaths_function GetForeignPaths; + GetForeignPlan_function GetForeignPlan; + BeginForeignScan_function BeginForeignScan; + IterateForeignScan_function IterateForeignScan; + ReScanForeignScan_function ReScanForeignScan; + EndForeignScan_function EndForeignScan; + + /* + * Remaining functions are optional. Set the pointer to NULL for any that + * are not provided. + */ + + /* Functions for remote-join planning */ + GetForeignJoinPaths_function GetForeignJoinPaths; + + /* Functions for remote upper-relation (post scan/join) planning */ + GetForeignUpperPaths_function GetForeignUpperPaths; + + /* Functions for updating foreign tables */ + AddForeignUpdateTargets_function AddForeignUpdateTargets; + PlanForeignModify_function PlanForeignModify; + BeginForeignModify_function BeginForeignModify; + ExecForeignInsert_function ExecForeignInsert; + ExecForeignUpdate_function ExecForeignUpdate; + ExecForeignDelete_function ExecForeignDelete; + EndForeignModify_function EndForeignModify; + BeginForeignInsert_function BeginForeignInsert; + EndForeignInsert_function EndForeignInsert; + IsForeignRelUpdatable_function IsForeignRelUpdatable; + PlanDirectModify_function PlanDirectModify; + BeginDirectModify_function BeginDirectModify; + IterateDirectModify_function IterateDirectModify; + EndDirectModify_function EndDirectModify; + + /* Functions for SELECT FOR UPDATE/SHARE row locking */ + GetForeignRowMarkType_function GetForeignRowMarkType; + RefetchForeignRow_function RefetchForeignRow; + RecheckForeignScan_function RecheckForeignScan; + + /* Support functions for EXPLAIN */ + ExplainForeignScan_function ExplainForeignScan; + ExplainForeignModify_function ExplainForeignModify; + ExplainDirectModify_function ExplainDirectModify; + + /* Support functions for ANALYZE */ + AnalyzeForeignTable_function AnalyzeForeignTable; + + /* Support functions for IMPORT FOREIGN SCHEMA */ + ImportForeignSchema_function ImportForeignSchema; + + /* Support functions for parallelism under Gather node */ + IsForeignScanParallelSafe_function IsForeignScanParallelSafe; + EstimateDSMForeignScan_function EstimateDSMForeignScan; + InitializeDSMForeignScan_function InitializeDSMForeignScan; + ReInitializeDSMForeignScan_function ReInitializeDSMForeignScan; + InitializeWorkerForeignScan_function InitializeWorkerForeignScan; + ShutdownForeignScan_function ShutdownForeignScan; + + /* Support functions for path reparameterization. */ + ReparameterizeForeignPathByChild_function ReparameterizeForeignPathByChild; +} FdwRoutine; + + +/* Functions in foreign/foreign.c */ +extern FdwRoutine *GetFdwRoutine(Oid fdwhandler); +extern Oid GetForeignServerIdByRelId(Oid relid); +extern FdwRoutine *GetFdwRoutineByServerId(Oid serverid); +extern FdwRoutine *GetFdwRoutineByRelId(Oid relid); +extern FdwRoutine *GetFdwRoutineForRelation(Relation relation, bool makecopy); +extern bool IsImportableForeignTable(const char *tablename, + ImportForeignSchemaStmt *stmt); +extern Path *GetExistingLocalJoinPath(RelOptInfo *joinrel); + +#endif /* FDWAPI_H */ diff --git a/src/include/foreign/foreign.h b/src/include/foreign/foreign.h new file mode 100644 index 0000000..5e0cf53 --- /dev/null +++ b/src/include/foreign/foreign.h @@ -0,0 +1,84 @@ +/*------------------------------------------------------------------------- + * + * foreign.h + * support for foreign-data wrappers, servers and user mappings. + * + * + * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group + * + * src/include/foreign/foreign.h + * + *------------------------------------------------------------------------- + */ +#ifndef FOREIGN_H +#define FOREIGN_H + +#include "nodes/parsenodes.h" + + +/* Helper for obtaining username for user mapping */ +#define MappingUserName(userid) \ + (OidIsValid(userid) ? GetUserNameFromId(userid, false) : "public") + + +typedef struct ForeignDataWrapper +{ + Oid fdwid; /* FDW Oid */ + Oid owner; /* FDW owner user Oid */ + char *fdwname; /* Name of the FDW */ + Oid fdwhandler; /* Oid of handler function, or 0 */ + Oid fdwvalidator; /* Oid of validator function, or 0 */ + List *options; /* fdwoptions as DefElem list */ +} ForeignDataWrapper; + +typedef struct ForeignServer +{ + Oid serverid; /* server Oid */ + Oid fdwid; /* foreign-data wrapper */ + Oid owner; /* server owner user Oid */ + char *servername; /* name of the server */ + char *servertype; /* server type, optional */ + char *serverversion; /* server version, optional */ + List *options; /* srvoptions as DefElem list */ +} ForeignServer; + +typedef struct UserMapping +{ + Oid umid; /* Oid of user mapping */ + Oid userid; /* local user Oid */ + Oid serverid; /* server Oid */ + List *options; /* useoptions as DefElem list */ +} UserMapping; + +typedef struct ForeignTable +{ + Oid relid; /* relation Oid */ + Oid serverid; /* server Oid */ + List *options; /* ftoptions as DefElem list */ +} ForeignTable; + +/* Flags for GetForeignServerExtended */ +#define FSV_MISSING_OK 0x01 + +/* Flags for GetForeignDataWrapperExtended */ +#define FDW_MISSING_OK 0x01 + + +extern ForeignServer *GetForeignServer(Oid serverid); +extern ForeignServer *GetForeignServerExtended(Oid serverid, + bits16 flags); +extern ForeignServer *GetForeignServerByName(const char *name, bool missing_ok); +extern UserMapping *GetUserMapping(Oid userid, Oid serverid); +extern ForeignDataWrapper *GetForeignDataWrapper(Oid fdwid); +extern ForeignDataWrapper *GetForeignDataWrapperExtended(Oid fdwid, + bits16 flags); +extern ForeignDataWrapper *GetForeignDataWrapperByName(const char *name, + bool missing_ok); +extern ForeignTable *GetForeignTable(Oid relid); + +extern List *GetForeignColumnOptions(Oid relid, AttrNumber attnum); + +extern Oid get_foreign_data_wrapper_oid(const char *fdwname, bool missing_ok); +extern Oid get_foreign_server_oid(const char *servername, bool missing_ok); + +#endif /* FOREIGN_H */ -- cgit v1.2.3