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  * postgres_fdw foreign table. For a baserel, this struct is created by
26  * postgresGetForeignRelSize, although some fields are not filled till later.
27  * postgresGetForeignJoinPaths creates it for a joinrel, and
28  * postgresGetForeignUpperPaths creates it for an upperrel.
29  */
30 typedef struct PgFdwRelationInfo
31 {
32  /*
33  * True means that the relation can be pushed down. Always true for simple
34  * foreign scan.
35  */
37 
38  /*
39  * Restriction clauses, divided into safe and unsafe to pushdown subsets.
40  * All entries in these lists should have RestrictInfo wrappers; that
41  * improves efficiency of selectivity and cost estimation.
42  */
45 
46  /* Actual remote restriction clauses for scan (sans RestrictInfos) */
48 
49  /* Bitmap of attr numbers we need to fetch from the remote server. */
51 
52  /* Cost and selectivity of local_conds. */
55 
56  /* Selectivity of join conditions */
58 
59  /* Estimated size and cost for a scan or join. */
60  double rows;
61  int width;
64  /* Costs excluding costs for transferring data from the foreign server */
67 
68  /* Options extracted from catalogs. */
72  List *shippable_extensions; /* OIDs of whitelisted extensions */
73 
74  /* Cached catalog information. */
77  UserMapping *user; /* only set in use_remote_estimate mode */
78 
79  int fetch_size; /* fetch size for this remote table */
80 
81  /*
82  * Name of the relation while EXPLAINing ForeignScan. It is used for join
83  * relations but is set for all relations. For join relation, the name
84  * indicates which foreign tables are being joined and the join type used.
85  */
87 
88  /* Join information */
92  /* joinclauses contains only JOIN/ON conditions for an outer join */
93  List *joinclauses; /* List of RestrictInfo */
94 
95  /* Grouping information */
97 
98  /* Subquery information */
99  bool make_outerrel_subquery; /* do we deparse outerrel as a
100  * subquery? */
101  bool make_innerrel_subquery; /* do we deparse innerrel as a
102  * subquery? */
103  Relids lower_subquery_rels; /* all relids appearing in lower
104  * subqueries */
105 
106  /*
107  * Index of the relation. It is used to create an alias to a subquery
108  * representing the relation.
109  */
112 
113 /* in postgres_fdw.c */
114 extern int set_transmission_modes(void);
115 extern void reset_transmission_modes(int nestlevel);
116 
117 /* in connection.c */
118 extern PGconn *GetConnection(UserMapping *user, bool will_prep_stmt);
119 extern void ReleaseConnection(PGconn *conn);
120 extern unsigned int GetCursorNumber(PGconn *conn);
121 extern unsigned int GetPrepStmtNumber(PGconn *conn);
122 extern PGresult *pgfdw_get_result(PGconn *conn, const char *query);
123 extern PGresult *pgfdw_exec_query(PGconn *conn, const char *query);
124 extern void pgfdw_report_error(int elevel, PGresult *res, PGconn *conn,
125  bool clear, const char *sql);
126 
127 /* in option.c */
128 extern int ExtractConnectionOptions(List *defelems,
129  const char **keywords,
130  const char **values);
131 extern List *ExtractExtensionList(const char *extensionsString,
132  bool warnOnMissing);
133 
134 /* in deparse.c */
135 extern void classifyConditions(PlannerInfo *root,
136  RelOptInfo *baserel,
137  List *input_conds,
138  List **remote_conds,
139  List **local_conds);
140 extern bool is_foreign_expr(PlannerInfo *root,
141  RelOptInfo *baserel,
142  Expr *expr);
143 extern void deparseInsertSql(StringInfo buf, PlannerInfo *root,
144  Index rtindex, Relation rel,
145  List *targetAttrs, bool doNothing, List *returningList,
146  List **retrieved_attrs);
147 extern void deparseUpdateSql(StringInfo buf, PlannerInfo *root,
148  Index rtindex, Relation rel,
149  List *targetAttrs, List *returningList,
150  List **retrieved_attrs);
152  Index rtindex, Relation rel,
153  List *targetlist,
154  List *targetAttrs,
155  List *remote_conds,
156  List **params_list,
157  List *returningList,
158  List **retrieved_attrs);
159 extern void deparseDeleteSql(StringInfo buf, PlannerInfo *root,
160  Index rtindex, Relation rel,
161  List *returningList,
162  List **retrieved_attrs);
164  Index rtindex, Relation rel,
165  List *remote_conds,
166  List **params_list,
167  List *returningList,
168  List **retrieved_attrs);
169 extern void deparseAnalyzeSizeSql(StringInfo buf, Relation rel);
170 extern void deparseAnalyzeSql(StringInfo buf, Relation rel,
171  List **retrieved_attrs);
172 extern void deparseStringLiteral(StringInfo buf, const char *val);
174 extern List *build_tlist_to_deparse(RelOptInfo *foreignrel);
176  RelOptInfo *foreignrel, List *tlist,
177  List *remote_conds, List *pathkeys, bool is_subquery,
178  List **retrieved_attrs, List **params_list);
179 
180 /* in shippable.c */
181 extern bool is_builtin(Oid objectId);
182 extern bool is_shippable(Oid objectId, Oid classId, PgFdwRelationInfo *fpinfo);
183 extern const char *get_jointype_name(JoinType jointype);
184 
185 #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:1611
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:1548
bool is_foreign_expr(PlannerInfo *root, RelOptInfo *baserel, Expr *expr)
Definition: deparse.c:226
ForeignServer * server
Definition: postgres_fdw.h:76
int ExtractConnectionOptions(List *defelems, const char **keywords, const char **values)
Definition: option.c:297
Relids lower_subquery_rels
Definition: postgres_fdw.h:103
void classifyConditions(PlannerInfo *root, RelOptInfo *baserel, List *input_conds, List **remote_conds, List **local_conds)
Definition: deparse.c:200
double Selectivity
Definition: nodes.h:638
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:89
JoinType
Definition: nodes.h:672
const char * get_jointype_name(JoinType jointype)
Definition: deparse.c:1311
unsigned int GetPrepStmtNumber(PGconn *conn)
Definition: connection.c:437
bool make_outerrel_subquery
Definition: postgres_fdw.h:99
PGconn * conn
Definition: streamutil.c:42
Selectivity local_conds_sel
Definition: postgres_fdw.h:54
List * ExtractExtensionList(const char *extensionsString, bool warnOnMissing)
Definition: option.c:328
Selectivity joinclause_sel
Definition: postgres_fdw.h:57
static char * buf
Definition: pg_test_fsync.c:66
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:1838
static int elevel
Definition: vacuumlazy.c:137
UserMapping * user
Definition: postgres_fdw.h:77
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:1653
StringInfo relation_name
Definition: postgres_fdw.h:86
Bitmapset * attrs_used
Definition: postgres_fdw.h:50
void deparseDirectDeleteSql(StringInfo buf, PlannerInfo *root, Index rtindex, Relation rel, List *remote_conds, List **params_list, List *returningList, List **retrieved_attrs)
Definition: deparse.c:1743
ForeignTable * table
Definition: postgres_fdw.h:75
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:1818
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:925
void ReleaseConnection(PGconn *conn)
Definition: connection.c:402
static Datum values[MAXATTR]
Definition: bootstrap.c:163
RelOptInfo * innerrel
Definition: postgres_fdw.h:90
static char * user
Definition: pg_regress.c:92
List * final_remote_exprs
Definition: postgres_fdw.h:47
List * shippable_extensions
Definition: postgres_fdw.h:72
Definition: pg_list.h:45
struct PgFdwRelationInfo PgFdwRelationInfo
long val
Definition: informix.c:689
double Cost
Definition: nodes.h:639
QualCost local_conds_cost
Definition: postgres_fdw.h:53
void deparseDeleteSql(StringInfo buf, PlannerInfo *root, Index rtindex, Relation rel, List *returningList, List **retrieved_attrs)
Definition: deparse.c:1721
void deparseStringLiteral(StringInfo buf, const char *val)
Definition: deparse.c:2084