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-2016, 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 */
96 
97 /* in postgres_fdw.c */
98 extern int set_transmission_modes(void);
99 extern void reset_transmission_modes(int nestlevel);
100 
101 /* in connection.c */
102 extern PGconn *GetConnection(UserMapping *user, bool will_prep_stmt);
103 extern void ReleaseConnection(PGconn *conn);
104 extern unsigned int GetCursorNumber(PGconn *conn);
105 extern unsigned int GetPrepStmtNumber(PGconn *conn);
106 extern PGresult *pgfdw_get_result(PGconn *conn, const char *query);
107 extern PGresult *pgfdw_exec_query(PGconn *conn, const char *query);
108 extern void pgfdw_report_error(int elevel, PGresult *res, PGconn *conn,
109  bool clear, const char *sql);
110 
111 /* in option.c */
112 extern int ExtractConnectionOptions(List *defelems,
113  const char **keywords,
114  const char **values);
115 extern List *ExtractExtensionList(const char *extensionsString,
116  bool warnOnMissing);
117 
118 /* in deparse.c */
119 extern void classifyConditions(PlannerInfo *root,
120  RelOptInfo *baserel,
121  List *input_conds,
122  List **remote_conds,
123  List **local_conds);
124 extern bool is_foreign_expr(PlannerInfo *root,
125  RelOptInfo *baserel,
126  Expr *expr);
127 extern void deparseInsertSql(StringInfo buf, PlannerInfo *root,
128  Index rtindex, Relation rel,
129  List *targetAttrs, bool doNothing, List *returningList,
130  List **retrieved_attrs);
131 extern void deparseUpdateSql(StringInfo buf, PlannerInfo *root,
132  Index rtindex, Relation rel,
133  List *targetAttrs, List *returningList,
134  List **retrieved_attrs);
136  Index rtindex, Relation rel,
137  List *targetlist,
138  List *targetAttrs,
139  List *remote_conds,
140  List **params_list,
141  List *returningList,
142  List **retrieved_attrs);
143 extern void deparseDeleteSql(StringInfo buf, PlannerInfo *root,
144  Index rtindex, Relation rel,
145  List *returningList,
146  List **retrieved_attrs);
148  Index rtindex, Relation rel,
149  List *remote_conds,
150  List **params_list,
151  List *returningList,
152  List **retrieved_attrs);
153 extern void deparseAnalyzeSizeSql(StringInfo buf, Relation rel);
154 extern void deparseAnalyzeSql(StringInfo buf, Relation rel,
155  List **retrieved_attrs);
156 extern void deparseStringLiteral(StringInfo buf, const char *val);
158 extern List *build_tlist_to_deparse(RelOptInfo *foreign_rel);
160  RelOptInfo *foreignrel, List *tlist,
161  List *remote_conds, List *pathkeys,
162  List **retrieved_attrs, List **params_list);
163 
164 /* in shippable.c */
165 extern bool is_builtin(Oid objectId);
166 extern bool is_shippable(Oid objectId, Oid classId, PgFdwRelationInfo *fpinfo);
167 extern const char *get_jointype_name(JoinType jointype);
168 
169 #endif /* POSTGRES_FDW_H */
bool is_builtin(Oid objectId)
Definition: shippable.c:155
void deparseSelectStmtForRel(StringInfo buf, PlannerInfo *root, RelOptInfo *foreignrel, List *tlist, List *remote_conds, List *pathkeys, List **retrieved_attrs, List **params_list)
Definition: deparse.c:763
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:1283
PGconn * GetConnection(UserMapping *user, bool will_prep_stmt)
Definition: connection.c:96
void deparseInsertSql(StringInfo buf, PlannerInfo *root, Index rtindex, Relation rel, List *targetAttrs, bool doNothing, List *returningList, List **retrieved_attrs)
Definition: deparse.c:1220
bool is_foreign_expr(PlannerInfo *root, RelOptInfo *baserel, Expr *expr)
Definition: deparse.c:197
ForeignServer * server
Definition: postgres_fdw.h:78
int ExtractConnectionOptions(List *defelems, const char **keywords, const char **values)
Definition: option.c:296
void classifyConditions(PlannerInfo *root, RelOptInfo *baserel, List *input_conds, List **remote_conds, List **local_conds)
Definition: deparse.c:171
double Selectivity
Definition: nodes.h:593
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:627
const char * get_jointype_name(JoinType jointype)
Definition: deparse.c:1064
unsigned int GetPrepStmtNumber(PGconn *conn)
Definition: connection.c:446
PGconn * conn
Definition: streamutil.c:45
Selectivity local_conds_sel
Definition: postgres_fdw.h:56
List * ExtractExtensionList(const char *extensionsString, bool warnOnMissing)
Definition: option.c:327
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:483
int set_transmission_modes(void)
void deparseAnalyzeSql(StringInfo buf, Relation rel, List **retrieved_attrs)
Definition: deparse.c:1508
static int elevel
Definition: vacuumlazy.c:130
UserMapping * user
Definition: postgres_fdw.h:79
unsigned int Index
Definition: c.h:361
Expr * find_em_expr_for_rel(EquivalenceClass *ec, RelOptInfo *rel)
List * build_tlist_to_deparse(RelOptInfo *foreign_rel)
Definition: deparse.c:725
PGresult * pgfdw_exec_query(PGconn *conn, const char *query)
Definition: connection.c:459
unsigned int GetCursorNumber(PGconn *conn)
Definition: connection.c:432
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:1325
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:1414
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:537
void deparseAnalyzeSizeSql(StringInfo buf, Relation rel)
Definition: deparse.c:1488
void ReleaseConnection(PGconn *conn)
Definition: connection.c:411
static Datum values[MAXATTR]
Definition: bootstrap.c:160
RelOptInfo * innerrel
Definition: postgres_fdw.h:92
static char * user
Definition: pg_regress.c:90
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:594
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:1392
void deparseStringLiteral(StringInfo buf, const char *val)
Definition: deparse.c:1748