Header And Logo

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

fdwapi.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * fdwapi.h
00004  *    API for foreign-data wrappers
00005  *
00006  * Copyright (c) 2010-2013, PostgreSQL Global Development Group
00007  *
00008  * src/include/foreign/fdwapi.h
00009  *
00010  *-------------------------------------------------------------------------
00011  */
00012 #ifndef FDWAPI_H
00013 #define FDWAPI_H
00014 
00015 #include "nodes/execnodes.h"
00016 #include "nodes/relation.h"
00017 
00018 /* To avoid including explain.h here, reference ExplainState thus: */
00019 struct ExplainState;
00020 
00021 
00022 /*
00023  * Callback function signatures --- see fdwhandler.sgml for more info.
00024  */
00025 
00026 typedef void (*GetForeignRelSize_function) (PlannerInfo *root,
00027                                                         RelOptInfo *baserel,
00028                                                         Oid foreigntableid);
00029 
00030 typedef void (*GetForeignPaths_function) (PlannerInfo *root,
00031                                                       RelOptInfo *baserel,
00032                                                       Oid foreigntableid);
00033 
00034 typedef ForeignScan *(*GetForeignPlan_function) (PlannerInfo *root,
00035                                                          RelOptInfo *baserel,
00036                                                           Oid foreigntableid,
00037                                                       ForeignPath *best_path,
00038                                                              List *tlist,
00039                                                          List *scan_clauses);
00040 
00041 typedef void (*BeginForeignScan_function) (ForeignScanState *node,
00042                                                        int eflags);
00043 
00044 typedef TupleTableSlot *(*IterateForeignScan_function) (ForeignScanState *node);
00045 
00046 typedef void (*ReScanForeignScan_function) (ForeignScanState *node);
00047 
00048 typedef void (*EndForeignScan_function) (ForeignScanState *node);
00049 
00050 typedef void (*AddForeignUpdateTargets_function) (Query *parsetree,
00051                                                    RangeTblEntry *target_rte,
00052                                                    Relation target_relation);
00053 
00054 typedef List *(*PlanForeignModify_function) (PlannerInfo *root,
00055                                                          ModifyTable *plan,
00056                                                          Index resultRelation,
00057                                                          int subplan_index);
00058 
00059 typedef void (*BeginForeignModify_function) (ModifyTableState *mtstate,
00060                                                          ResultRelInfo *rinfo,
00061                                                          List *fdw_private,
00062                                                          int subplan_index,
00063                                                          int eflags);
00064 
00065 typedef TupleTableSlot *(*ExecForeignInsert_function) (EState *estate,
00066                                                         ResultRelInfo *rinfo,
00067                                                         TupleTableSlot *slot,
00068                                                    TupleTableSlot *planSlot);
00069 
00070 typedef TupleTableSlot *(*ExecForeignUpdate_function) (EState *estate,
00071                                                         ResultRelInfo *rinfo,
00072                                                         TupleTableSlot *slot,
00073                                                    TupleTableSlot *planSlot);
00074 
00075 typedef TupleTableSlot *(*ExecForeignDelete_function) (EState *estate,
00076                                                         ResultRelInfo *rinfo,
00077                                                         TupleTableSlot *slot,
00078                                                    TupleTableSlot *planSlot);
00079 
00080 typedef void (*EndForeignModify_function) (EState *estate,
00081                                                        ResultRelInfo *rinfo);
00082 
00083 typedef void (*ExplainForeignScan_function) (ForeignScanState *node,
00084                                                     struct ExplainState *es);
00085 
00086 typedef void (*ExplainForeignModify_function) (ModifyTableState *mtstate,
00087                                                         ResultRelInfo *rinfo,
00088                                                            List *fdw_private,
00089                                                            int subplan_index,
00090                                                     struct ExplainState *es);
00091 
00092 typedef int (*AcquireSampleRowsFunc) (Relation relation, int elevel,
00093                                                HeapTuple *rows, int targrows,
00094                                                   double *totalrows,
00095                                                   double *totaldeadrows);
00096 
00097 typedef bool (*AnalyzeForeignTable_function) (Relation relation,
00098                                                  AcquireSampleRowsFunc *func,
00099                                                     BlockNumber *totalpages);
00100 
00101 /*
00102  * FdwRoutine is the struct returned by a foreign-data wrapper's handler
00103  * function.  It provides pointers to the callback functions needed by the
00104  * planner and executor.
00105  *
00106  * More function pointers are likely to be added in the future.  Therefore
00107  * it's recommended that the handler initialize the struct with
00108  * makeNode(FdwRoutine) so that all fields are set to NULL.  This will
00109  * ensure that no fields are accidentally left undefined.
00110  */
00111 typedef struct FdwRoutine
00112 {
00113     NodeTag     type;
00114 
00115     /* Functions for scanning foreign tables */
00116     GetForeignRelSize_function GetForeignRelSize;
00117     GetForeignPaths_function GetForeignPaths;
00118     GetForeignPlan_function GetForeignPlan;
00119     BeginForeignScan_function BeginForeignScan;
00120     IterateForeignScan_function IterateForeignScan;
00121     ReScanForeignScan_function ReScanForeignScan;
00122     EndForeignScan_function EndForeignScan;
00123 
00124     /*
00125      * Remaining functions are optional.  Set the pointer to NULL for any that
00126      * are not provided.
00127      */
00128 
00129     /* Functions for updating foreign tables */
00130     AddForeignUpdateTargets_function AddForeignUpdateTargets;
00131     PlanForeignModify_function PlanForeignModify;
00132     BeginForeignModify_function BeginForeignModify;
00133     ExecForeignInsert_function ExecForeignInsert;
00134     ExecForeignUpdate_function ExecForeignUpdate;
00135     ExecForeignDelete_function ExecForeignDelete;
00136     EndForeignModify_function EndForeignModify;
00137 
00138     /* Support functions for EXPLAIN */
00139     ExplainForeignScan_function ExplainForeignScan;
00140     ExplainForeignModify_function ExplainForeignModify;
00141 
00142     /* Support functions for ANALYZE */
00143     AnalyzeForeignTable_function AnalyzeForeignTable;
00144 } FdwRoutine;
00145 
00146 
00147 /* Functions in foreign/foreign.c */
00148 extern FdwRoutine *GetFdwRoutine(Oid fdwhandler);
00149 extern FdwRoutine *GetFdwRoutineByRelId(Oid relid);
00150 extern FdwRoutine *GetFdwRoutineForRelation(Relation relation, bool makecopy);
00151 
00152 #endif   /* FDWAPI_H */