fdwapi.h 10 KB

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