You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

postgres_fdw.h 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*-------------------------------------------------------------------------
  2. *
  3. * postgres_fdw.h
  4. * Foreign-data wrapper for remote PostgreSQL servers
  5. *
  6. * Portions Copyright (c) 2012-2019, PostgreSQL Global Development Group
  7. *
  8. * IDENTIFICATION
  9. * contrib/postgres_fdw/postgres_fdw.h
  10. *
  11. *-------------------------------------------------------------------------
  12. */
  13. #ifndef POSTGRES_FDW_H
  14. #define POSTGRES_FDW_H
  15. #include "foreign/foreign.h"
  16. #include "lib/stringinfo.h"
  17. #include "nodes/relation.h"
  18. #include "utils/relcache.h"
  19. #include "libpq-fe.h"
  20. /*
  21. * FDW-specific planner information kept in RelOptInfo.fdw_private for a
  22. * postgres_fdw foreign table. For a baserel, this struct is created by
  23. * postgresGetForeignRelSize, although some fields are not filled till later.
  24. * postgresGetForeignJoinPaths creates it for a joinrel, and
  25. * postgresGetForeignUpperPaths creates it for an upperrel.
  26. */
  27. typedef struct PgFdwRelationInfo
  28. {
  29. /*
  30. * True means that the relation can be pushed down. Always true for simple
  31. * foreign scan.
  32. */
  33. bool pushdown_safe;
  34. /*
  35. * Restriction clauses, divided into safe and unsafe to pushdown subsets.
  36. * All entries in these lists should have RestrictInfo wrappers; that
  37. * improves efficiency of selectivity and cost estimation.
  38. */
  39. List *remote_conds;
  40. List *local_conds;
  41. /* Actual remote restriction clauses for scan (sans RestrictInfos) */
  42. List *final_remote_exprs;
  43. /* Bitmap of attr numbers we need to fetch from the remote server. */
  44. Bitmapset *attrs_used;
  45. /* Cost and selectivity of local_conds. */
  46. QualCost local_conds_cost;
  47. Selectivity local_conds_sel;
  48. /* Selectivity of join conditions */
  49. Selectivity joinclause_sel;
  50. /* Estimated size and cost for a scan or join. */
  51. double rows;
  52. int width;
  53. Cost startup_cost;
  54. Cost total_cost;
  55. /* Costs excluding costs for transferring data from the foreign server */
  56. Cost rel_startup_cost;
  57. Cost rel_total_cost;
  58. /* Options extracted from catalogs. */
  59. bool use_remote_estimate;
  60. Cost fdw_startup_cost;
  61. Cost fdw_tuple_cost;
  62. List *shippable_extensions; /* OIDs of whitelisted extensions */
  63. /* Cached catalog information. */
  64. ForeignTable *table;
  65. ForeignServer *server;
  66. UserMapping *user; /* only set in use_remote_estimate mode */
  67. int fetch_size; /* fetch size for this remote table */
  68. /*
  69. * Name of the relation while EXPLAINing ForeignScan. It is used for join
  70. * relations but is set for all relations. For join relation, the name
  71. * indicates which foreign tables are being joined and the join type used.
  72. */
  73. StringInfo relation_name;
  74. /* Join information */
  75. RelOptInfo *outerrel;
  76. RelOptInfo *innerrel;
  77. JoinType jointype;
  78. /* joinclauses contains only JOIN/ON conditions for an outer join */
  79. List *joinclauses; /* List of RestrictInfo */
  80. /* Grouping information */
  81. List *grouped_tlist;
  82. /* Subquery information */
  83. bool make_outerrel_subquery; /* do we deparse outerrel as a
  84. * subquery? */
  85. bool make_innerrel_subquery; /* do we deparse innerrel as a
  86. * subquery? */
  87. Relids lower_subquery_rels; /* all relids appearing in lower
  88. * subqueries */
  89. /*
  90. * Index of the relation. It is used to create an alias to a subquery
  91. * representing the relation.
  92. */
  93. int relation_index;
  94. } PgFdwRelationInfo;
  95. /* in postgres_fdw.c */
  96. extern int set_transmission_modes(void);
  97. extern void reset_transmission_modes(int nestlevel);
  98. /* in connection.c */
  99. extern PGconn *GetConnection(UserMapping *user, bool will_prep_stmt);
  100. extern void ReleaseConnection(PGconn *conn);
  101. extern unsigned int GetCursorNumber(PGconn *conn);
  102. extern unsigned int GetPrepStmtNumber(PGconn *conn);
  103. extern PGresult *pgfdw_get_result(PGconn *conn, const char *query);
  104. extern PGresult *pgfdw_exec_query(PGconn *conn, const char *query);
  105. extern void pgfdw_report_error(int elevel, PGresult *res, PGconn *conn,
  106. bool clear, const char *sql);
  107. /* in option.c */
  108. extern int ExtractConnectionOptions(List *defelems,
  109. const char **keywords,
  110. const char **values);
  111. extern List *ExtractExtensionList(const char *extensionsString,
  112. bool warnOnMissing);
  113. /* in deparse.c */
  114. extern void classifyConditions(PlannerInfo *root,
  115. RelOptInfo *baserel,
  116. List *input_conds,
  117. List **remote_conds,
  118. List **local_conds);
  119. extern bool is_foreign_expr(PlannerInfo *root,
  120. RelOptInfo *baserel,
  121. Expr *expr);
  122. extern void deparseInsertSql(StringInfo buf, RangeTblEntry *rte,
  123. Index rtindex, Relation rel,
  124. List *targetAttrs, bool doNothing,
  125. List *withCheckOptionList, List *returningList,
  126. List **retrieved_attrs);
  127. extern void deparseUpdateSql(StringInfo buf, RangeTblEntry *rte,
  128. Index rtindex, Relation rel,
  129. List *targetAttrs,
  130. List *withCheckOptionList, List *returningList,
  131. List **retrieved_attrs);
  132. extern void deparseDirectUpdateSql(StringInfo buf, PlannerInfo *root,
  133. Index rtindex, Relation rel,
  134. RelOptInfo *foreignrel,
  135. List *targetlist,
  136. List *targetAttrs,
  137. List *remote_conds,
  138. List **params_list,
  139. List *returningList,
  140. List **retrieved_attrs);
  141. extern void deparseDeleteSql(StringInfo buf, RangeTblEntry *rte,
  142. Index rtindex, Relation rel,
  143. List *returningList,
  144. List **retrieved_attrs);
  145. extern void deparseDirectDeleteSql(StringInfo buf, PlannerInfo *root,
  146. Index rtindex, Relation rel,
  147. RelOptInfo *foreignrel,
  148. List *remote_conds,
  149. List **params_list,
  150. List *returningList,
  151. List **retrieved_attrs);
  152. extern void deparseAnalyzeSizeSql(StringInfo buf, Relation rel);
  153. extern void deparseAnalyzeSql(StringInfo buf, Relation rel,
  154. List **retrieved_attrs);
  155. extern void deparseStringLiteral(StringInfo buf, const char *val);
  156. extern Expr *find_em_expr_for_rel(EquivalenceClass *ec, RelOptInfo *rel);
  157. extern List *build_tlist_to_deparse(RelOptInfo *foreignrel);
  158. extern void deparseSelectStmtForRel(StringInfo buf, PlannerInfo *root,
  159. RelOptInfo *foreignrel, List *tlist,
  160. List *remote_conds, List *pathkeys, bool is_subquery,
  161. List **retrieved_attrs, List **params_list);
  162. extern const char *get_jointype_name(JoinType jointype);
  163. /* in shippable.c */
  164. extern bool is_builtin(Oid objectId);
  165. extern bool is_shippable(Oid objectId, Oid classId, PgFdwRelationInfo *fpinfo);
  166. #endif /* POSTGRES_FDW_H */