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 */
99 
100 /* in postgres_fdw.c */
101 extern int set_transmission_modes(void);
102 extern void reset_transmission_modes(int nestlevel);
103 
104 /* in connection.c */
105 extern PGconn *GetConnection(UserMapping *user, bool will_prep_stmt);
106 extern void ReleaseConnection(PGconn *conn);
107 extern unsigned int GetCursorNumber(PGconn *conn);
108 extern unsigned int GetPrepStmtNumber(PGconn *conn);
109 extern PGresult *pgfdw_get_result(PGconn *conn, const char *query);
110 extern PGresult *pgfdw_exec_query(PGconn *conn, const char *query);
111 extern void pgfdw_report_error(int elevel, PGresult *res, PGconn *conn,
112  bool clear, const char *sql);
113 
114 /* in option.c */
115 extern int ExtractConnectionOptions(List *defelems,
116  const char **keywords,
117  const char **values);
118 extern List *ExtractExtensionList(const char *extensionsString,
119  bool warnOnMissing);
120 
121 /* in deparse.c */
122 extern void classifyConditions(PlannerInfo *root,
123  RelOptInfo *baserel,
124  List *input_conds,
125  List **remote_conds,
126  List **local_conds);
127 extern bool is_foreign_expr(PlannerInfo *root,
128  RelOptInfo *baserel,
129  Expr *expr);
130 extern void deparseInsertSql(StringInfo buf, PlannerInfo *root,
131  Index rtindex, Relation rel,
132  List *targetAttrs, bool doNothing, List *returningList,
133  List **retrieved_attrs);
134 extern void deparseUpdateSql(StringInfo buf, PlannerInfo *root,
135  Index rtindex, Relation rel,
136  List *targetAttrs, List *returningList,
137  List **retrieved_attrs);
139  Index rtindex, Relation rel,
140  List *targetlist,
141  List *targetAttrs,
142  List *remote_conds,
143  List **params_list,
144  List *returningList,
145  List **retrieved_attrs);
146 extern void deparseDeleteSql(StringInfo buf, PlannerInfo *root,
147  Index rtindex, Relation rel,
148  List *returningList,
149  List **retrieved_attrs);
151  Index rtindex, Relation rel,
152  List *remote_conds,
153  List **params_list,
154  List *returningList,
155  List **retrieved_attrs);
156 extern void deparseAnalyzeSizeSql(StringInfo buf, Relation rel);
157 extern void deparseAnalyzeSql(StringInfo buf, Relation rel,
158  List **retrieved_attrs);
159 extern void deparseStringLiteral(StringInfo buf, const char *val);
161 extern List *build_tlist_to_deparse(RelOptInfo *foreignrel);
163  RelOptInfo *foreignrel, List *tlist,
164  List *remote_conds, List *pathkeys,
165  List **retrieved_attrs, List **params_list);
166 
167 /* in shippable.c */
168 extern bool is_builtin(Oid objectId);
169 extern bool is_shippable(Oid objectId, Oid classId, PgFdwRelationInfo *fpinfo);
170 extern const char *get_jointype_name(JoinType jointype);
171 
172 #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:902
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:1484
List * build_tlist_to_deparse(RelOptInfo *foreignrel)
Definition: deparse.c:854
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:1421
bool is_foreign_expr(PlannerInfo *root, RelOptInfo *baserel, Expr *expr)
Definition: deparse.c:212
ForeignServer * server
Definition: postgres_fdw.h:78
int ExtractConnectionOptions(List *defelems, const char **keywords, const char **values)
Definition: option.c:297
void classifyConditions(PlannerInfo *root, RelOptInfo *baserel, List *input_conds, List **remote_conds, List **local_conds)
Definition: deparse.c:186
double Selectivity
Definition: nodes.h:631
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:665
const char * get_jointype_name(JoinType jointype)
Definition: deparse.c:1273
unsigned int GetPrepStmtNumber(PGconn *conn)
Definition: connection.c:447
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: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:484
int set_transmission_modes(void)
void deparseAnalyzeSql(StringInfo buf, Relation rel, List **retrieved_attrs)
Definition: deparse.c:1711
static int elevel
Definition: vacuumlazy.c:136
UserMapping * user
Definition: postgres_fdw.h:79
unsigned int Index
Definition: c.h:362
Expr * find_em_expr_for_rel(EquivalenceClass *ec, RelOptInfo *rel)
PGresult * pgfdw_exec_query(PGconn *conn, const char *query)
Definition: connection.c:460
unsigned int GetCursorNumber(PGconn *conn)
Definition: connection.c:433
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:1526
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:1616
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:538
void deparseAnalyzeSizeSql(StringInfo buf, Relation rel)
Definition: deparse.c:1691
void ReleaseConnection(PGconn *conn)
Definition: connection.c:412
static Datum values[MAXATTR]
Definition: bootstrap.c:162
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:632
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:1594
void deparseStringLiteral(StringInfo buf, const char *val)
Definition: deparse.c:1957