PostgreSQL Source Code  git master
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-2021, 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/pathnodes.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  void *extra);
67 
68 typedef void (*AddForeignUpdateTargets_function) (Query *parsetree,
69  RangeTblEntry *target_rte,
70  Relation target_relation);
71 
72 typedef List *(*PlanForeignModify_function) (PlannerInfo *root,
73  ModifyTable *plan,
74  Index resultRelation,
75  int subplan_index);
76 
78  ResultRelInfo *rinfo,
79  List *fdw_private,
80  int subplan_index,
81  int eflags);
82 
83 typedef TupleTableSlot *(*ExecForeignInsert_function) (EState *estate,
84  ResultRelInfo *rinfo,
85  TupleTableSlot *slot,
86  TupleTableSlot *planSlot);
87 
88 typedef TupleTableSlot **(*ExecForeignBatchInsert_function) (EState *estate,
89  ResultRelInfo *rinfo,
90  TupleTableSlot **slots,
91  TupleTableSlot **planSlots,
92  int *numSlots);
93 
95 
96 typedef TupleTableSlot *(*ExecForeignUpdate_function) (EState *estate,
97  ResultRelInfo *rinfo,
98  TupleTableSlot *slot,
99  TupleTableSlot *planSlot);
100 
101 typedef TupleTableSlot *(*ExecForeignDelete_function) (EState *estate,
102  ResultRelInfo *rinfo,
103  TupleTableSlot *slot,
104  TupleTableSlot *planSlot);
105 
106 typedef void (*EndForeignModify_function) (EState *estate,
107  ResultRelInfo *rinfo);
108 
110  ResultRelInfo *rinfo);
111 
112 typedef void (*EndForeignInsert_function) (EState *estate,
113  ResultRelInfo *rinfo);
114 
116 
118  ModifyTable *plan,
119  Index resultRelation,
120  int subplan_index);
121 
123  int eflags);
124 
125 typedef TupleTableSlot *(*IterateDirectModify_function) (ForeignScanState *node);
126 
128 
130  LockClauseStrength strength);
131 
132 typedef void (*RefetchForeignRow_function) (EState *estate,
133  ExecRowMark *erm,
134  Datum rowid,
135  TupleTableSlot *slot,
136  bool *updated);
137 
139  struct ExplainState *es);
140 
142  ResultRelInfo *rinfo,
143  List *fdw_private,
144  int subplan_index,
145  struct ExplainState *es);
146 
148  struct ExplainState *es);
149 
150 typedef int (*AcquireSampleRowsFunc) (Relation relation, int elevel,
151  HeapTuple *rows, int targrows,
152  double *totalrows,
153  double *totaldeadrows);
154 
156  AcquireSampleRowsFunc *func,
157  BlockNumber *totalpages);
158 
159 typedef List *(*ImportForeignSchema_function) (ImportForeignSchemaStmt *stmt,
160  Oid serverOid);
161 
163  ParallelContext *pcxt);
165  ParallelContext *pcxt,
166  void *coordinate);
168  ParallelContext *pcxt,
169  void *coordinate);
171  shm_toc *toc,
172  void *coordinate);
175  RelOptInfo *rel,
176  RangeTblEntry *rte);
177 typedef List *(*ReparameterizeForeignPathByChild_function) (PlannerInfo *root,
178  List *fdw_private,
179  RelOptInfo *child_rel);
180 
181 /*
182  * FdwRoutine is the struct returned by a foreign-data wrapper's handler
183  * function. It provides pointers to the callback functions needed by the
184  * planner and executor.
185  *
186  * More function pointers are likely to be added in the future. Therefore
187  * it's recommended that the handler initialize the struct with
188  * makeNode(FdwRoutine) so that all fields are set to NULL. This will
189  * ensure that no fields are accidentally left undefined.
190  */
191 typedef struct FdwRoutine
192 {
194 
195  /* Functions for scanning foreign tables */
203 
204  /*
205  * Remaining functions are optional. Set the pointer to NULL for any that
206  * are not provided.
207  */
208 
209  /* Functions for remote-join planning */
211 
212  /* Functions for remote upper-relation (post scan/join) planning */
214 
215  /* Functions for updating foreign tables */
232 
233  /* Functions for SELECT FOR UPDATE/SHARE row locking */
237 
238  /* Support functions for EXPLAIN */
242 
243  /* Support functions for ANALYZE */
245 
246  /* Support functions for IMPORT FOREIGN SCHEMA */
248 
249  /* Support functions for parallelism under Gather node */
256 
257  /* Support functions for path reparameterization. */
259 } FdwRoutine;
260 
261 
262 /* Functions in foreign/foreign.c */
263 extern FdwRoutine *GetFdwRoutine(Oid fdwhandler);
264 extern Oid GetForeignServerIdByRelId(Oid relid);
265 extern FdwRoutine *GetFdwRoutineByServerId(Oid serverid);
266 extern FdwRoutine *GetFdwRoutineByRelId(Oid relid);
267 extern FdwRoutine *GetFdwRoutineForRelation(Relation relation, bool makecopy);
268 extern bool IsImportableForeignTable(const char *tablename,
270 extern Path *GetExistingLocalJoinPath(RelOptInfo *joinrel);
271 
272 #endif /* FDWAPI_H */
GetForeignPlan_function GetForeignPlan
Definition: fdwapi.h:198
BeginForeignScan_function BeginForeignScan
Definition: fdwapi.h:199
GetForeignUpperPaths_function GetForeignUpperPaths
Definition: fdwapi.h:213
ExecForeignDelete_function ExecForeignDelete
Definition: fdwapi.h:223
EndDirectModify_function EndDirectModify
Definition: fdwapi.h:231
UpperRelationKind
Definition: pathnodes.h:67
void(* GetForeignJoinPaths_function)(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, JoinPathExtraData *extra)
Definition: fdwapi.h:55
void(* EndForeignScan_function)(ForeignScanState *node)
Definition: fdwapi.h:53
EstimateDSMForeignScan_function EstimateDSMForeignScan
Definition: fdwapi.h:251
Path * GetExistingLocalJoinPath(RelOptInfo *joinrel)
Definition: foreign.c:751
ExplainForeignScan_function ExplainForeignScan
Definition: fdwapi.h:239
Size(* EstimateDSMForeignScan_function)(ForeignScanState *node, ParallelContext *pcxt)
Definition: fdwapi.h:162
int(* GetForeignModifyBatchSize_function)(ResultRelInfo *rinfo)
Definition: fdwapi.h:94
TupleTableSlot **(* ExecForeignBatchInsert_function)(EState *estate, ResultRelInfo *rinfo, TupleTableSlot **slots, TupleTableSlot **planSlots, int *numSlots)
Definition: fdwapi.h:88
AnalyzeForeignTable_function AnalyzeForeignTable
Definition: fdwapi.h:244
InitializeWorkerForeignScan_function InitializeWorkerForeignScan
Definition: fdwapi.h:254
void(* AddForeignUpdateTargets_function)(Query *parsetree, RangeTblEntry *target_rte, Relation target_relation)
Definition: fdwapi.h:68
BeginForeignInsert_function BeginForeignInsert
Definition: fdwapi.h:225
FdwRoutine * GetFdwRoutineForRelation(Relation relation, bool makecopy)
Definition: foreign.c:427
ExecForeignInsert_function ExecForeignInsert
Definition: fdwapi.h:219
void(* BeginForeignInsert_function)(ModifyTableState *mtstate, ResultRelInfo *rinfo)
Definition: fdwapi.h:109
FdwRoutine * GetFdwRoutine(Oid fdwhandler)
Definition: foreign.c:319
void(* EndForeignModify_function)(EState *estate, ResultRelInfo *rinfo)
Definition: fdwapi.h:106
void(* BeginForeignScan_function)(ForeignScanState *node, int eflags)
Definition: fdwapi.h:43
uint32 BlockNumber
Definition: block.h:31
void(* ExplainDirectModify_function)(ForeignScanState *node, struct ExplainState *es)
Definition: fdwapi.h:147
void(* ReInitializeDSMForeignScan_function)(ForeignScanState *node, ParallelContext *pcxt, void *coordinate)
Definition: fdwapi.h:167
bool(* RecheckForeignScan_function)(ForeignScanState *node, TupleTableSlot *slot)
Definition: fdwapi.h:48
unsigned int Oid
Definition: postgres_ext.h:31
NodeTag
Definition: nodes.h:26
bool IsImportableForeignTable(const char *tablename, ImportForeignSchemaStmt *stmt)
Definition: foreign.c:467
AddForeignUpdateTargets_function AddForeignUpdateTargets
Definition: fdwapi.h:216
JoinType
Definition: nodes.h:695
List *(* PlanForeignModify_function)(PlannerInfo *root, ModifyTable *plan, Index resultRelation, int subplan_index)
Definition: fdwapi.h:72
RecheckForeignScan_function RecheckForeignScan
Definition: fdwapi.h:236
IterateDirectModify_function IterateDirectModify
Definition: fdwapi.h:230
int(* IsForeignRelUpdatable_function)(Relation rel)
Definition: fdwapi.h:115
ForeignScan *(* GetForeignPlan_function)(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid, ForeignPath *best_path, List *tlist, List *scan_clauses, Plan *outer_plan)
Definition: fdwapi.h:35
void(* BeginDirectModify_function)(ForeignScanState *node, int eflags)
Definition: fdwapi.h:122
NodeTag type
Definition: fdwapi.h:193
IsForeignScanParallelSafe_function IsForeignScanParallelSafe
Definition: fdwapi.h:250
void(* GetForeignRelSize_function)(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid)
Definition: fdwapi.h:27
void(* GetForeignPaths_function)(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid)
Definition: fdwapi.h:31
GetForeignJoinPaths_function GetForeignJoinPaths
Definition: fdwapi.h:210
TupleTableSlot *(* ExecForeignDelete_function)(EState *estate, ResultRelInfo *rinfo, TupleTableSlot *slot, TupleTableSlot *planSlot)
Definition: fdwapi.h:101
TupleTableSlot *(* ExecForeignInsert_function)(EState *estate, ResultRelInfo *rinfo, TupleTableSlot *slot, TupleTableSlot *planSlot)
Definition: fdwapi.h:83
GetForeignRelSize_function GetForeignRelSize
Definition: fdwapi.h:196
EndForeignScan_function EndForeignScan
Definition: fdwapi.h:202
ExplainDirectModify_function ExplainDirectModify
Definition: fdwapi.h:241
void(* EndDirectModify_function)(ForeignScanState *node)
Definition: fdwapi.h:127
bool(* IsForeignScanParallelSafe_function)(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
Definition: fdwapi.h:174
void(* BeginForeignModify_function)(ModifyTableState *mtstate, ResultRelInfo *rinfo, List *fdw_private, int subplan_index, int eflags)
Definition: fdwapi.h:77
ImportForeignSchema_function ImportForeignSchema
Definition: fdwapi.h:247
PlanForeignModify_function PlanForeignModify
Definition: fdwapi.h:217
EndForeignModify_function EndForeignModify
Definition: fdwapi.h:224
TupleTableSlot *(* IterateForeignScan_function)(ForeignScanState *node)
Definition: fdwapi.h:46
GetForeignModifyBatchSize_function GetForeignModifyBatchSize
Definition: fdwapi.h:221
GetForeignPaths_function GetForeignPaths
Definition: fdwapi.h:197
PlanDirectModify_function PlanDirectModify
Definition: fdwapi.h:228
FdwRoutine * GetFdwRoutineByRelId(Oid relid)
Definition: foreign.c:404
static int elevel
Definition: vacuumlazy.c:333
BeginDirectModify_function BeginDirectModify
Definition: fdwapi.h:229
LockClauseStrength
Definition: lockoptions.h:21
uintptr_t Datum
Definition: postgres.h:367
void(* RefetchForeignRow_function)(EState *estate, ExecRowMark *erm, Datum rowid, TupleTableSlot *slot, bool *updated)
Definition: fdwapi.h:132
GetForeignRowMarkType_function GetForeignRowMarkType
Definition: fdwapi.h:234
unsigned int Index
Definition: c.h:537
InitializeDSMForeignScan_function InitializeDSMForeignScan
Definition: fdwapi.h:252
bool(* PlanDirectModify_function)(PlannerInfo *root, ModifyTable *plan, Index resultRelation, int subplan_index)
Definition: fdwapi.h:117
ExecForeignUpdate_function ExecForeignUpdate
Definition: fdwapi.h:222
ExecForeignBatchInsert_function ExecForeignBatchInsert
Definition: fdwapi.h:220
void(* ExplainForeignScan_function)(ForeignScanState *node, struct ExplainState *es)
Definition: fdwapi.h:138
ReScanForeignScan_function ReScanForeignScan
Definition: fdwapi.h:201
bool(* AnalyzeForeignTable_function)(Relation relation, AcquireSampleRowsFunc *func, BlockNumber *totalpages)
Definition: fdwapi.h:155
List *(* ImportForeignSchema_function)(ImportForeignSchemaStmt *stmt, Oid serverOid)
Definition: fdwapi.h:159
IterateForeignScan_function IterateForeignScan
Definition: fdwapi.h:200
size_t Size
Definition: c.h:528
void(* ReScanForeignScan_function)(ForeignScanState *node)
Definition: fdwapi.h:51
void(* GetForeignUpperPaths_function)(PlannerInfo *root, UpperRelationKind stage, RelOptInfo *input_rel, RelOptInfo *output_rel, void *extra)
Definition: fdwapi.h:62
RowMarkType
Definition: plannodes.h:1023
FdwRoutine * GetFdwRoutineByServerId(Oid serverid)
Definition: foreign.c:362
TupleTableSlot *(* IterateDirectModify_function)(ForeignScanState *node)
Definition: fdwapi.h:125
void(* EndForeignInsert_function)(EState *estate, ResultRelInfo *rinfo)
Definition: fdwapi.h:112
struct FdwRoutine FdwRoutine
void(* InitializeWorkerForeignScan_function)(ForeignScanState *node, shm_toc *toc, void *coordinate)
Definition: fdwapi.h:170
ReInitializeDSMForeignScan_function ReInitializeDSMForeignScan
Definition: fdwapi.h:253
ShutdownForeignScan_function ShutdownForeignScan
Definition: fdwapi.h:255
int(* AcquireSampleRowsFunc)(Relation relation, int elevel, HeapTuple *rows, int targrows, double *totalrows, double *totaldeadrows)
Definition: fdwapi.h:150
void(* InitializeDSMForeignScan_function)(ForeignScanState *node, ParallelContext *pcxt, void *coordinate)
Definition: fdwapi.h:164
RowMarkType(* GetForeignRowMarkType_function)(RangeTblEntry *rte, LockClauseStrength strength)
Definition: fdwapi.h:129
ExplainForeignModify_function ExplainForeignModify
Definition: fdwapi.h:240
IsForeignRelUpdatable_function IsForeignRelUpdatable
Definition: fdwapi.h:227
Oid GetForeignServerIdByRelId(Oid relid)
Definition: foreign.c:340
List *(* ReparameterizeForeignPathByChild_function)(PlannerInfo *root, List *fdw_private, RelOptInfo *child_rel)
Definition: fdwapi.h:177
void(* ShutdownForeignScan_function)(ForeignScanState *node)
Definition: fdwapi.h:173
BeginForeignModify_function BeginForeignModify
Definition: fdwapi.h:218
Definition: pg_list.h:50
void(* ExplainForeignModify_function)(ModifyTableState *mtstate, ResultRelInfo *rinfo, List *fdw_private, int subplan_index, struct ExplainState *es)
Definition: fdwapi.h:141
TupleTableSlot *(* ExecForeignUpdate_function)(EState *estate, ResultRelInfo *rinfo, TupleTableSlot *slot, TupleTableSlot *planSlot)
Definition: fdwapi.h:96
EndForeignInsert_function EndForeignInsert
Definition: fdwapi.h:226
RefetchForeignRow_function RefetchForeignRow
Definition: fdwapi.h:235
unsigned char bool
Definition: c.h:379
ReparameterizeForeignPathByChild_function ReparameterizeForeignPathByChild
Definition: fdwapi.h:258