PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
fdwapi.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * fdwapi.h
4  * API for foreign-data wrappers
5  *
6  * Copyright (c) 2010-2017, PostgreSQL Global Development Group
7  *
8  * src/include/foreign/fdwapi.h
9  *
10  *-------------------------------------------------------------------------
11  */
12 #ifndef FDWAPI_H
13 #define FDWAPI_H
14 
15 #include "access/parallel.h"
16 #include "nodes/execnodes.h"
17 #include "nodes/relation.h"
18 
19 /* To avoid including explain.h here, reference ExplainState thus: */
20 struct ExplainState;
21 
22 
23 /*
24  * Callback function signatures --- see fdwhandler.sgml for more info.
25  */
26 
27 typedef void (*GetForeignRelSize_function) (PlannerInfo *root,
28  RelOptInfo *baserel,
29  Oid foreigntableid);
30 
31 typedef void (*GetForeignPaths_function) (PlannerInfo *root,
32  RelOptInfo *baserel,
33  Oid foreigntableid);
34 
35 typedef ForeignScan *(*GetForeignPlan_function) (PlannerInfo *root,
36  RelOptInfo *baserel,
37  Oid foreigntableid,
38  ForeignPath *best_path,
39  List *tlist,
40  List *scan_clauses,
41  Plan *outer_plan);
42 
44  int eflags);
45 
46 typedef TupleTableSlot *(*IterateForeignScan_function) (ForeignScanState *node);
47 
49  TupleTableSlot *slot);
50 
52 
53 typedef void (*EndForeignScan_function) (ForeignScanState *node);
54 
56  RelOptInfo *joinrel,
57  RelOptInfo *outerrel,
58  RelOptInfo *innerrel,
59  JoinType jointype,
60  JoinPathExtraData *extra);
61 
63  UpperRelationKind stage,
64  RelOptInfo *input_rel,
65  RelOptInfo *output_rel);
66 
67 typedef void (*AddForeignUpdateTargets_function) (Query *parsetree,
68  RangeTblEntry *target_rte,
69  Relation target_relation);
70 
71 typedef List *(*PlanForeignModify_function) (PlannerInfo *root,
72  ModifyTable *plan,
73  Index resultRelation,
74  int subplan_index);
75 
77  ResultRelInfo *rinfo,
78  List *fdw_private,
79  int subplan_index,
80  int eflags);
81 
82 typedef TupleTableSlot *(*ExecForeignInsert_function) (EState *estate,
83  ResultRelInfo *rinfo,
84  TupleTableSlot *slot,
85  TupleTableSlot *planSlot);
86 
87 typedef TupleTableSlot *(*ExecForeignUpdate_function) (EState *estate,
88  ResultRelInfo *rinfo,
89  TupleTableSlot *slot,
90  TupleTableSlot *planSlot);
91 
92 typedef TupleTableSlot *(*ExecForeignDelete_function) (EState *estate,
93  ResultRelInfo *rinfo,
94  TupleTableSlot *slot,
95  TupleTableSlot *planSlot);
96 
97 typedef void (*EndForeignModify_function) (EState *estate,
98  ResultRelInfo *rinfo);
99 
101 
103  ModifyTable *plan,
104  Index resultRelation,
105  int subplan_index);
106 
108  int eflags);
109 
110 typedef TupleTableSlot *(*IterateDirectModify_function) (ForeignScanState *node);
111 
113 
115  LockClauseStrength strength);
116 
118  ExecRowMark *erm,
119  Datum rowid,
120  bool *updated);
121 
123  struct ExplainState *es);
124 
126  ResultRelInfo *rinfo,
127  List *fdw_private,
128  int subplan_index,
129  struct ExplainState *es);
130 
132  struct ExplainState *es);
133 
134 typedef int (*AcquireSampleRowsFunc) (Relation relation, int elevel,
135  HeapTuple *rows, int targrows,
136  double *totalrows,
137  double *totaldeadrows);
138 
140  AcquireSampleRowsFunc *func,
141  BlockNumber *totalpages);
142 
143 typedef List *(*ImportForeignSchema_function) (ImportForeignSchemaStmt *stmt,
144  Oid serverOid);
145 
147  ParallelContext *pcxt);
149  ParallelContext *pcxt,
150  void *coordinate);
152  shm_toc *toc,
153  void *coordinate);
156  RelOptInfo *rel,
157  RangeTblEntry *rte);
158 
159 /*
160  * FdwRoutine is the struct returned by a foreign-data wrapper's handler
161  * function. It provides pointers to the callback functions needed by the
162  * planner and executor.
163  *
164  * More function pointers are likely to be added in the future. Therefore
165  * it's recommended that the handler initialize the struct with
166  * makeNode(FdwRoutine) so that all fields are set to NULL. This will
167  * ensure that no fields are accidentally left undefined.
168  */
169 typedef struct FdwRoutine
170 {
172 
173  /* Functions for scanning foreign tables */
181 
182  /*
183  * Remaining functions are optional. Set the pointer to NULL for any that
184  * are not provided.
185  */
186 
187  /* Functions for remote-join planning */
189 
190  /* Functions for remote upper-relation (post scan/join) planning */
192 
193  /* Functions for updating foreign tables */
206 
207  /* Functions for SELECT FOR UPDATE/SHARE row locking */
211 
212  /* Support functions for EXPLAIN */
216 
217  /* Support functions for ANALYZE */
219 
220  /* Support functions for IMPORT FOREIGN SCHEMA */
222 
223  /* Support functions for parallelism under Gather node */
229 } FdwRoutine;
230 
231 
232 /* Functions in foreign/foreign.c */
233 extern FdwRoutine *GetFdwRoutine(Oid fdwhandler);
234 extern Oid GetForeignServerIdByRelId(Oid relid);
235 extern FdwRoutine *GetFdwRoutineByServerId(Oid serverid);
236 extern FdwRoutine *GetFdwRoutineByRelId(Oid relid);
237 extern FdwRoutine *GetFdwRoutineForRelation(Relation relation, bool makecopy);
238 extern bool IsImportableForeignTable(const char *tablename,
240 extern Path *GetExistingLocalJoinPath(RelOptInfo *joinrel);
241 
242 #endif /* FDWAPI_H */
GetForeignPlan_function GetForeignPlan
Definition: fdwapi.h:176
BeginForeignScan_function BeginForeignScan
Definition: fdwapi.h:177
GetForeignUpperPaths_function GetForeignUpperPaths
Definition: fdwapi.h:191
ExecForeignDelete_function ExecForeignDelete
Definition: fdwapi.h:199
EndDirectModify_function EndDirectModify
Definition: fdwapi.h:205
void(* ReScanForeignScan_function)(ForeignScanState *node)
Definition: fdwapi.h:51
HeapTupleData * HeapTuple
Definition: htup.h:70
EstimateDSMForeignScan_function EstimateDSMForeignScan
Definition: fdwapi.h:225
Path * GetExistingLocalJoinPath(RelOptInfo *joinrel)
Definition: foreign.c:716
TupleTableSlot *(* ExecForeignDelete_function)(EState *estate, ResultRelInfo *rinfo, TupleTableSlot *slot, TupleTableSlot *planSlot)
Definition: fdwapi.h:92
ExplainForeignScan_function ExplainForeignScan
Definition: fdwapi.h:213
void(* GetForeignUpperPaths_function)(PlannerInfo *root, UpperRelationKind stage, RelOptInfo *input_rel, RelOptInfo *output_rel)
Definition: fdwapi.h:62
AnalyzeForeignTable_function AnalyzeForeignTable
Definition: fdwapi.h:218
void(* GetForeignJoinPaths_function)(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, JoinPathExtraData *extra)
Definition: fdwapi.h:55
InitializeWorkerForeignScan_function InitializeWorkerForeignScan
Definition: fdwapi.h:227
FdwRoutine * GetFdwRoutineForRelation(Relation relation, bool makecopy)
Definition: foreign.c:395
int(* AcquireSampleRowsFunc)(Relation relation, int elevel, HeapTuple *rows, int targrows, double *totalrows, double *totaldeadrows)
Definition: fdwapi.h:134
ExecForeignInsert_function ExecForeignInsert
Definition: fdwapi.h:197
void(* ExplainForeignScan_function)(ForeignScanState *node, struct ExplainState *es)
Definition: fdwapi.h:122
void(* EndForeignModify_function)(EState *estate, ResultRelInfo *rinfo)
Definition: fdwapi.h:97
FdwRoutine * GetFdwRoutine(Oid fdwhandler)
Definition: foreign.c:287
uint32 BlockNumber
Definition: block.h:31
TupleTableSlot *(* ExecForeignUpdate_function)(EState *estate, ResultRelInfo *rinfo, TupleTableSlot *slot, TupleTableSlot *planSlot)
Definition: fdwapi.h:87
bool(* AnalyzeForeignTable_function)(Relation relation, AcquireSampleRowsFunc *func, BlockNumber *totalpages)
Definition: fdwapi.h:139
unsigned int Oid
Definition: postgres_ext.h:31
NodeTag
Definition: nodes.h:26
void(* BeginDirectModify_function)(ForeignScanState *node, int eflags)
Definition: fdwapi.h:107
UpperRelationKind
Definition: relation.h:71
Size(* EstimateDSMForeignScan_function)(ForeignScanState *node, ParallelContext *pcxt)
Definition: fdwapi.h:146
bool IsImportableForeignTable(const char *tablename, ImportForeignSchemaStmt *stmt)
Definition: foreign.c:435
HeapTuple(* RefetchForeignRow_function)(EState *estate, ExecRowMark *erm, Datum rowid, bool *updated)
Definition: fdwapi.h:117
AddForeignUpdateTargets_function AddForeignUpdateTargets
Definition: fdwapi.h:194
char bool
Definition: c.h:202
JoinType
Definition: nodes.h:672
RecheckForeignScan_function RecheckForeignScan
Definition: fdwapi.h:210
IterateDirectModify_function IterateDirectModify
Definition: fdwapi.h:204
List *(* PlanForeignModify_function)(PlannerInfo *root, ModifyTable *plan, Index resultRelation, int subplan_index)
Definition: fdwapi.h:71
int(* IsForeignRelUpdatable_function)(Relation rel)
Definition: fdwapi.h:100
void(* InitializeWorkerForeignScan_function)(ForeignScanState *node, shm_toc *toc, void *coordinate)
Definition: fdwapi.h:151
NodeTag type
Definition: fdwapi.h:171
IsForeignScanParallelSafe_function IsForeignScanParallelSafe
Definition: fdwapi.h:224
GetForeignJoinPaths_function GetForeignJoinPaths
Definition: fdwapi.h:188
void(* EndDirectModify_function)(ForeignScanState *node)
Definition: fdwapi.h:112
GetForeignRelSize_function GetForeignRelSize
Definition: fdwapi.h:174
EndForeignScan_function EndForeignScan
Definition: fdwapi.h:180
ExplainDirectModify_function ExplainDirectModify
Definition: fdwapi.h:215
ImportForeignSchema_function ImportForeignSchema
Definition: fdwapi.h:221
PlanForeignModify_function PlanForeignModify
Definition: fdwapi.h:195
EndForeignModify_function EndForeignModify
Definition: fdwapi.h:200
void(* ExplainForeignModify_function)(ModifyTableState *mtstate, ResultRelInfo *rinfo, List *fdw_private, int subplan_index, struct ExplainState *es)
Definition: fdwapi.h:125
GetForeignPaths_function GetForeignPaths
Definition: fdwapi.h:175
PlanDirectModify_function PlanDirectModify
Definition: fdwapi.h:202
FdwRoutine * GetFdwRoutineByRelId(Oid relid)
Definition: foreign.c:372
static int elevel
Definition: vacuumlazy.c:137
BeginDirectModify_function BeginDirectModify
Definition: fdwapi.h:203
RowMarkType(* GetForeignRowMarkType_function)(RangeTblEntry *rte, LockClauseStrength strength)
Definition: fdwapi.h:114
void(* GetForeignPaths_function)(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid)
Definition: fdwapi.h:31
LockClauseStrength
Definition: lockoptions.h:21
uintptr_t Datum
Definition: postgres.h:372
void(* ShutdownForeignScan_function)(ForeignScanState *node)
Definition: fdwapi.h:154
void(* AddForeignUpdateTargets_function)(Query *parsetree, RangeTblEntry *target_rte, Relation target_relation)
Definition: fdwapi.h:67
GetForeignRowMarkType_function GetForeignRowMarkType
Definition: fdwapi.h:208
List *(* ImportForeignSchema_function)(ImportForeignSchemaStmt *stmt, Oid serverOid)
Definition: fdwapi.h:143
bool(* RecheckForeignScan_function)(ForeignScanState *node, TupleTableSlot *slot)
Definition: fdwapi.h:48
unsigned int Index
Definition: c.h:365
InitializeDSMForeignScan_function InitializeDSMForeignScan
Definition: fdwapi.h:226
ExecForeignUpdate_function ExecForeignUpdate
Definition: fdwapi.h:198
void(* GetForeignRelSize_function)(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid)
Definition: fdwapi.h:27
ForeignScan *(* GetForeignPlan_function)(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid, ForeignPath *best_path, List *tlist, List *scan_clauses, Plan *outer_plan)
Definition: fdwapi.h:35
ReScanForeignScan_function ReScanForeignScan
Definition: fdwapi.h:179
void(* ExplainDirectModify_function)(ForeignScanState *node, struct ExplainState *es)
Definition: fdwapi.h:131
IterateForeignScan_function IterateForeignScan
Definition: fdwapi.h:178
void(* InitializeDSMForeignScan_function)(ForeignScanState *node, ParallelContext *pcxt, void *coordinate)
Definition: fdwapi.h:148
size_t Size
Definition: c.h:356
RowMarkType
Definition: plannodes.h:944
TupleTableSlot *(* IterateDirectModify_function)(ForeignScanState *node)
Definition: fdwapi.h:110
FdwRoutine * GetFdwRoutineByServerId(Oid serverid)
Definition: foreign.c:330
bool(* IsForeignScanParallelSafe_function)(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
Definition: fdwapi.h:155
TupleTableSlot *(* ExecForeignInsert_function)(EState *estate, ResultRelInfo *rinfo, TupleTableSlot *slot, TupleTableSlot *planSlot)
Definition: fdwapi.h:82
struct FdwRoutine FdwRoutine
ShutdownForeignScan_function ShutdownForeignScan
Definition: fdwapi.h:228
ExplainForeignModify_function ExplainForeignModify
Definition: fdwapi.h:214
IsForeignRelUpdatable_function IsForeignRelUpdatable
Definition: fdwapi.h:201
Oid GetForeignServerIdByRelId(Oid relid)
Definition: foreign.c:308
TupleTableSlot *(* IterateForeignScan_function)(ForeignScanState *node)
Definition: fdwapi.h:46
void(* EndForeignScan_function)(ForeignScanState *node)
Definition: fdwapi.h:53
bool(* PlanDirectModify_function)(PlannerInfo *root, ModifyTable *plan, Index resultRelation, int subplan_index)
Definition: fdwapi.h:102
BeginForeignModify_function BeginForeignModify
Definition: fdwapi.h:196
Definition: pg_list.h:45
void(* BeginForeignModify_function)(ModifyTableState *mtstate, ResultRelInfo *rinfo, List *fdw_private, int subplan_index, int eflags)
Definition: fdwapi.h:76
Definition: relation.h:946
void(* BeginForeignScan_function)(ForeignScanState *node, int eflags)
Definition: fdwapi.h:43
RefetchForeignRow_function RefetchForeignRow
Definition: fdwapi.h:209