fdwapi.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*-------------------------------------------------------------------------
  2. *
  3. * fdwapi.h
  4. * API for foreign-data wrappers
  5. *
  6. * Copyright (c) 2010-2016, 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/relation.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. typedef void (*AddForeignUpdateTargets_function) (Query *parsetree,
  53. RangeTblEntry *target_rte,
  54. Relation target_relation);
  55. typedef List *(*PlanForeignModify_function) (PlannerInfo *root,
  56. ModifyTable *plan,
  57. Index resultRelation,
  58. int subplan_index);
  59. typedef void (*BeginForeignModify_function) (ModifyTableState *mtstate,
  60. ResultRelInfo *rinfo,
  61. List *fdw_private,
  62. int subplan_index,
  63. int eflags);
  64. typedef TupleTableSlot *(*ExecForeignInsert_function) (EState *estate,
  65. ResultRelInfo *rinfo,
  66. TupleTableSlot *slot,
  67. TupleTableSlot *planSlot);
  68. typedef TupleTableSlot *(*ExecForeignUpdate_function) (EState *estate,
  69. ResultRelInfo *rinfo,
  70. TupleTableSlot *slot,
  71. TupleTableSlot *planSlot);
  72. typedef TupleTableSlot *(*ExecForeignDelete_function) (EState *estate,
  73. ResultRelInfo *rinfo,
  74. TupleTableSlot *slot,
  75. TupleTableSlot *planSlot);
  76. typedef void (*EndForeignModify_function) (EState *estate,
  77. ResultRelInfo *rinfo);
  78. typedef int (*IsForeignRelUpdatable_function) (Relation rel);
  79. typedef bool (*PlanDirectModify_function) (PlannerInfo *root,
  80. ModifyTable *plan,
  81. Index resultRelation,
  82. int subplan_index);
  83. typedef void (*BeginDirectModify_function) (ForeignScanState *node,
  84. int eflags);
  85. typedef TupleTableSlot *(*IterateDirectModify_function) (ForeignScanState *node);
  86. typedef void (*EndDirectModify_function) (ForeignScanState *node);
  87. typedef RowMarkType (*GetForeignRowMarkType_function) (RangeTblEntry *rte,
  88. LockClauseStrength strength);
  89. typedef HeapTuple (*RefetchForeignRow_function) (EState *estate,
  90. ExecRowMark *erm,
  91. Datum rowid,
  92. bool *updated);
  93. typedef void (*ExplainForeignScan_function) (ForeignScanState *node,
  94. struct ExplainState *es);
  95. typedef void (*ExplainForeignModify_function) (ModifyTableState *mtstate,
  96. ResultRelInfo *rinfo,
  97. List *fdw_private,
  98. int subplan_index,
  99. struct ExplainState *es);
  100. typedef void (*ExplainDirectModify_function) (ForeignScanState *node,
  101. struct ExplainState *es);
  102. typedef int (*AcquireSampleRowsFunc) (Relation relation, int elevel,
  103. HeapTuple *rows, int targrows,
  104. double *totalrows,
  105. double *totaldeadrows);
  106. typedef bool (*AnalyzeForeignTable_function) (Relation relation,
  107. AcquireSampleRowsFunc *func,
  108. BlockNumber *totalpages);
  109. typedef List *(*ImportForeignSchema_function) (ImportForeignSchemaStmt *stmt,
  110. Oid serverOid);
  111. typedef Size (*EstimateDSMForeignScan_function) (ForeignScanState *node,
  112. ParallelContext *pcxt);
  113. typedef void (*InitializeDSMForeignScan_function) (ForeignScanState *node,
  114. ParallelContext *pcxt,
  115. void *coordinate);
  116. typedef void (*InitializeWorkerForeignScan_function) (ForeignScanState *node,
  117. shm_toc *toc,
  118. void *coordinate);
  119. typedef bool (*IsForeignScanParallelSafe_function) (PlannerInfo *root,
  120. RelOptInfo *rel,
  121. RangeTblEntry *rte);
  122. /*
  123. * FdwRoutine is the struct returned by a foreign-data wrapper's handler
  124. * function. It provides pointers to the callback functions needed by the
  125. * planner and executor.
  126. *
  127. * More function pointers are likely to be added in the future. Therefore
  128. * it's recommended that the handler initialize the struct with
  129. * makeNode(FdwRoutine) so that all fields are set to NULL. This will
  130. * ensure that no fields are accidentally left undefined.
  131. */
  132. typedef struct FdwRoutine
  133. {
  134. NodeTag type;
  135. /* Functions for scanning foreign tables */
  136. GetForeignRelSize_function GetForeignRelSize;
  137. GetForeignPaths_function GetForeignPaths;
  138. GetForeignPlan_function GetForeignPlan;
  139. BeginForeignScan_function BeginForeignScan;
  140. IterateForeignScan_function IterateForeignScan;
  141. ReScanForeignScan_function ReScanForeignScan;
  142. EndForeignScan_function EndForeignScan;
  143. /*
  144. * Remaining functions are optional. Set the pointer to NULL for any that
  145. * are not provided.
  146. */
  147. /* Functions for remote-join planning */
  148. GetForeignJoinPaths_function GetForeignJoinPaths;
  149. /* Functions for remote upper-relation (post scan/join) planning */
  150. GetForeignUpperPaths_function GetForeignUpperPaths;
  151. /* Functions for updating foreign tables */
  152. AddForeignUpdateTargets_function AddForeignUpdateTargets;
  153. PlanForeignModify_function PlanForeignModify;
  154. BeginForeignModify_function BeginForeignModify;
  155. ExecForeignInsert_function ExecForeignInsert;
  156. ExecForeignUpdate_function ExecForeignUpdate;
  157. ExecForeignDelete_function ExecForeignDelete;
  158. EndForeignModify_function EndForeignModify;
  159. IsForeignRelUpdatable_function IsForeignRelUpdatable;
  160. PlanDirectModify_function PlanDirectModify;
  161. BeginDirectModify_function BeginDirectModify;
  162. IterateDirectModify_function IterateDirectModify;
  163. EndDirectModify_function EndDirectModify;
  164. /* Functions for SELECT FOR UPDATE/SHARE row locking */
  165. GetForeignRowMarkType_function GetForeignRowMarkType;
  166. RefetchForeignRow_function RefetchForeignRow;
  167. RecheckForeignScan_function RecheckForeignScan;
  168. /* Support functions for EXPLAIN */
  169. ExplainForeignScan_function ExplainForeignScan;
  170. ExplainForeignModify_function ExplainForeignModify;
  171. ExplainDirectModify_function ExplainDirectModify;
  172. /* Support functions for ANALYZE */
  173. AnalyzeForeignTable_function AnalyzeForeignTable;
  174. /* Support functions for IMPORT FOREIGN SCHEMA */
  175. ImportForeignSchema_function ImportForeignSchema;
  176. /* Support functions for parallelism under Gather node */
  177. IsForeignScanParallelSafe_function IsForeignScanParallelSafe;
  178. EstimateDSMForeignScan_function EstimateDSMForeignScan;
  179. InitializeDSMForeignScan_function InitializeDSMForeignScan;
  180. InitializeWorkerForeignScan_function InitializeWorkerForeignScan;
  181. } FdwRoutine;
  182. /* Functions in foreign/foreign.c */
  183. extern FdwRoutine *GetFdwRoutine(Oid fdwhandler);
  184. extern Oid GetForeignServerIdByRelId(Oid relid);
  185. extern FdwRoutine *GetFdwRoutineByServerId(Oid serverid);
  186. extern FdwRoutine *GetFdwRoutineByRelId(Oid relid);
  187. extern FdwRoutine *GetFdwRoutineForRelation(Relation relation, bool makecopy);
  188. extern bool IsImportableForeignTable(const char *tablename,
  189. ImportForeignSchemaStmt *stmt);
  190. extern Path *GetExistingLocalJoinPath(RelOptInfo *joinrel);
  191. #endif /* FDWAPI_H */