PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
postgres_fdw.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * postgres_fdw.h
4  * Foreign-data wrapper for remote PostgreSQL servers
5  *
6  * Portions Copyright (c) 2012-2017, 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 
16 #include "foreign/foreign.h"
17 #include "lib/stringinfo.h"
18 #include "nodes/relation.h"
19 #include "utils/relcache.h"
20 
21 #include "libpq-fe.h"
22 
23 /*
24  * FDW-specific planner information kept in RelOptInfo.fdw_private for a
25  * foreign table. This information is collected by postgresGetForeignRelSize.
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  */
34 
35  /*
36  * Restriction clauses, divided into safe and unsafe to pushdown subsets.
37  *
38  * For a base foreign relation this is a list of clauses along-with
39  * RestrictInfo wrapper. Keeping RestrictInfo wrapper helps while dividing
40  * scan_clauses in postgresGetForeignPlan into safe and unsafe subsets.
41  * Also it helps in estimating costs since RestrictInfo caches the
42  * selectivity and qual cost for the clause in it.
43  *
44  * For a join relation, however, they are part of otherclause list
45  * obtained from extract_actual_join_clauses, which strips RestrictInfo
46  * construct. So, for a join relation they are list of bare clauses.
47  */
50 
51  /* Bitmap of attr numbers we need to fetch from the remote server. */
53 
54  /* Cost and selectivity of local_conds. */
57 
58  /* Selectivity of join conditions */
60 
61  /* Estimated size and cost for a scan or join. */
62  double rows;
63  int width;
66  /* Costs excluding costs for transferring data from the foreign server */
69 
70  /* Options extracted from catalogs. */
74  List *shippable_extensions; /* OIDs of whitelisted extensions */
75 
76  /* Cached catalog information. */
79  UserMapping *user; /* only set in use_remote_estimate mode */
80 
81  int fetch_size; /* fetch size for this remote table */
82 
83  /*
84  * Name of the relation while EXPLAINing ForeignScan. It is used for join
85  * relations but is set for all relations. For join relation, the name
86  * indicates which foreign tables are being joined and the join type used.
87  */
89 
90  /* Join information */
95 
96  /* Grouping information */
98 
99  /* Subquery information */
100  bool make_outerrel_subquery; /* do we deparse outerrel as a
101  * subquery? */
102  bool make_innerrel_subquery; /* do we deparse innerrel as a
103  * subquery? */
104  Relids lower_subquery_rels; /* all relids appearing in lower
105  * subqueries */
106 
107  /*
108  * Index of the relation. It is used to create an alias to a subquery
109  * representing the relation.
110  */
113 
114 /* in postgres_fdw.c */
115 extern int set_transmission_modes(void);
116 extern void reset_transmission_modes(int nestlevel);
117 
118 /* in connection.c */
119 extern PGconn *GetConnection(UserMapping *user, bool will_prep_stmt);
120 extern void ReleaseConnection(PGconn *conn);
121 extern unsigned int GetCursorNumber(PGconn *conn);
122 extern unsigned int GetPrepStmtNumber(PGconn *conn);
123 extern PGresult *pgfdw_get_result(PGconn *conn, const char *query);
124 extern PGresult *pgfdw_exec_query(PGconn *conn, const char *query);
125 extern void pgfdw_report_error(int elevel, PGresult *res, PGconn *conn,
126  bool clear, const char *sql);
127 
128 /* in option.c */
129 extern int ExtractConnectionOptions(List *defelems,
130  const char **keywords,
131  const char **values);
132 extern List *ExtractExtensionList(const char *extensionsString,
133  bool warnOnMissing);
134 
135 /* in deparse.c */
136 extern void classifyConditions(PlannerInfo *root,
137  RelOptInfo *baserel,
138  List *input_conds,
139  List **remote_conds,
140  List **local_conds);
141 extern bool is_foreign_expr(PlannerInfo *root,
142  RelOptInfo *baserel,
143  Expr *expr);
144 extern void deparseInsertSql(StringInfo buf, PlannerInfo *root,
145  Index rtindex, Relation rel,
146  List *targetAttrs, bool doNothing, List *returningList,
147  List **retrieved_attrs);
148 extern void deparseUpdateSql(StringInfo buf, PlannerInfo *root,
149  Index rtindex, Relation rel,
150  List *targetAttrs, List *returningList,
151  List **retrieved_attrs);
153  Index rtindex, Relation rel,
154  List *targetlist,
155  List *targetAttrs,
156  List *remote_conds,
157  List **params_list,
158  List *returningList,
159  List **retrieved_attrs);
160 extern void deparseDeleteSql(StringInfo buf, PlannerInfo *root,
161  Index rtindex, Relation rel,
162  List *returningList,
163  List **retrieved_attrs);
165  Index rtindex, Relation rel,
166  List *remote_conds,
167  List **params_list,
168  List *returningList,
169  List **retrieved_attrs);
170 extern void deparseAnalyzeSizeSql(StringInfo buf, Relation rel);
171 extern void deparseAnalyzeSql(StringInfo buf, Relation rel,
172  List **retrieved_attrs);
173 extern void deparseStringLiteral(StringInfo buf, const char *val);
175 extern List *build_tlist_to_deparse(RelOptInfo *foreignrel);
177  RelOptInfo *foreignrel, List *tlist,
178  List *remote_conds, List *pathkeys, bool is_subquery,
179  List **retrieved_attrs, List **params_list);
180 
181 /* in shippable.c */
182 extern bool is_builtin(Oid objectId);
183 extern bool is_shippable(Oid objectId, Oid classId, PgFdwRelationInfo *fpinfo);
184 extern const char *get_jointype_name(JoinType jointype);
185 
186 #endif /* POSTGRES_FDW_H */
bool is_builtin(Oid objectId)
Definition: shippable.c:155
void reset_transmission_modes(int nestlevel)
void deparseUpdateSql(StringInfo buf, PlannerInfo *root, Index rtindex, Relation rel, List *targetAttrs, List *returningList, List **retrieved_attrs)
Definition: deparse.c:1616
List * build_tlist_to_deparse(RelOptInfo *foreignrel)
Definition: deparse.c:868
PGconn * GetConnection(UserMapping *user, bool will_prep_stmt)
Definition: connection.c:97
void deparseInsertSql(StringInfo buf, PlannerInfo *root, Index rtindex, Relation rel, List *targetAttrs, bool doNothing, List *returningList, List **retrieved_attrs)
Definition: deparse.c:1553
bool is_foreign_expr(PlannerInfo *root, RelOptInfo *baserel, Expr *expr)
Definition: deparse.c:226
ForeignServer * server
Definition: postgres_fdw.h:78
int ExtractConnectionOptions(List *defelems, const char **keywords, const char **values)
Definition: option.c:297
Relids lower_subquery_rels
Definition: postgres_fdw.h:104
void classifyConditions(PlannerInfo *root, RelOptInfo *baserel, List *input_conds, List **remote_conds, List **local_conds)
Definition: deparse.c:200
double Selectivity
Definition: nodes.h:627
unsigned int Oid
Definition: postgres_ext.h:31
bool is_shippable(Oid objectId, Oid classId, PgFdwRelationInfo *fpinfo)
Definition: shippable.c:165
RelOptInfo * outerrel
Definition: postgres_fdw.h:91
JoinType
Definition: nodes.h:661
const char * get_jointype_name(JoinType jointype)
Definition: deparse.c:1314
unsigned int GetPrepStmtNumber(PGconn *conn)
Definition: connection.c:437
PGconn * conn
Definition: streamutil.c:42
Selectivity local_conds_sel
Definition: postgres_fdw.h:56
List * ExtractExtensionList(const char *extensionsString, bool warnOnMissing)
Definition: option.c:328
Selectivity joinclause_sel
Definition: postgres_fdw.h:59
static char * buf
Definition: pg_test_fsync.c:65
PGresult * pgfdw_get_result(PGconn *conn, const char *query)
Definition: connection.c:474
int set_transmission_modes(void)
void deparseAnalyzeSql(StringInfo buf, Relation rel, List **retrieved_attrs)
Definition: deparse.c:1843
static int elevel
Definition: vacuumlazy.c:137
UserMapping * user
Definition: postgres_fdw.h:79
unsigned int Index
Definition: c.h:365
Expr * find_em_expr_for_rel(EquivalenceClass *ec, RelOptInfo *rel)
PGresult * pgfdw_exec_query(PGconn *conn, const char *query)
Definition: connection.c:450
unsigned int GetCursorNumber(PGconn *conn)
Definition: connection.c:423
void deparseDirectUpdateSql(StringInfo buf, PlannerInfo *root, Index rtindex, Relation rel, List *targetlist, List *targetAttrs, List *remote_conds, List **params_list, List *returningList, List **retrieved_attrs)
Definition: deparse.c:1658
StringInfo relation_name
Definition: postgres_fdw.h:88
Bitmapset * attrs_used
Definition: postgres_fdw.h:52
void deparseDirectDeleteSql(StringInfo buf, PlannerInfo *root, Index rtindex, Relation rel, List *remote_conds, List **params_list, List *returningList, List **retrieved_attrs)
Definition: deparse.c:1748
ForeignTable * table
Definition: postgres_fdw.h:77
void pgfdw_report_error(int elevel, PGresult *res, PGconn *conn, bool clear, const char *sql)
Definition: connection.c:528
void deparseAnalyzeSizeSql(StringInfo buf, Relation rel)
Definition: deparse.c:1823
void deparseSelectStmtForRel(StringInfo buf, PlannerInfo *root, RelOptInfo *foreignrel, List *tlist, List *remote_conds, List *pathkeys, bool is_subquery, List **retrieved_attrs, List **params_list)
Definition: deparse.c:919
void ReleaseConnection(PGconn *conn)
Definition: connection.c:402
static Datum values[MAXATTR]
Definition: bootstrap.c:162
RelOptInfo * innerrel
Definition: postgres_fdw.h:92
static char * user
Definition: pg_regress.c:92
List * shippable_extensions
Definition: postgres_fdw.h:74
Definition: pg_list.h:45
struct PgFdwRelationInfo PgFdwRelationInfo
long val
Definition: informix.c:689
double Cost
Definition: nodes.h:628
QualCost local_conds_cost
Definition: postgres_fdw.h:55
void deparseDeleteSql(StringInfo buf, PlannerInfo *root, Index rtindex, Relation rel, List *returningList, List **retrieved_attrs)
Definition: deparse.c:1726
void deparseStringLiteral(StringInfo buf, const char *val)
Definition: deparse.c:2089