PostgreSQL Source Code  git master
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-2020, 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 "libpq-fe.h"
19 #include "nodes/pathnodes.h"
20 #include "utils/relcache.h"
21 
22 /*
23  * FDW-specific planner information kept in RelOptInfo.fdw_private for a
24  * postgres_fdw foreign table. For a baserel, this struct is created by
25  * postgresGetForeignRelSize, although some fields are not filled till later.
26  * postgresGetForeignJoinPaths creates it for a joinrel, and
27  * postgresGetForeignUpperPaths creates it for an upperrel.
28  */
29 typedef struct PgFdwRelationInfo
30 {
31  /*
32  * True means that the relation can be pushed down. Always true for simple
33  * foreign scan.
34  */
36 
37  /*
38  * Restriction clauses, divided into safe and unsafe to pushdown subsets.
39  * All entries in these lists should have RestrictInfo wrappers; that
40  * improves efficiency of selectivity and cost estimation.
41  */
44 
45  /* Actual remote restriction clauses for scan (sans RestrictInfos) */
47 
48  /* Bitmap of attr numbers we need to fetch from the remote server. */
50 
51  /* True means that the query_pathkeys is safe to push down */
53 
54  /* Cost and selectivity of local_conds. */
57 
58  /* Selectivity of join conditions */
60 
61  /* Estimated size and cost for a scan, join, or grouping/aggregation. */
62  double rows;
63  int width;
66 
67  /*
68  * Estimated number of rows fetched from the foreign server, and costs
69  * excluding costs for transferring those rows from the foreign server.
70  * These are only used by estimate_path_cost_size().
71  */
75 
76  /* Options extracted from catalogs. */
80  List *shippable_extensions; /* OIDs of whitelisted extensions */
81 
82  /* Cached catalog information. */
85  UserMapping *user; /* only set in use_remote_estimate mode */
86 
87  int fetch_size; /* fetch size for this remote table */
88 
89  /*
90  * Name of the relation, for use while EXPLAINing ForeignScan. It is used
91  * for join and upper relations but is set for all relations. For a base
92  * relation, this is really just the RT index as a string; we convert that
93  * while producing EXPLAIN output. For join and upper relations, the name
94  * indicates which base foreign tables are included and the join type or
95  * aggregation type used.
96  */
98 
99  /* Join information */
103  /* joinclauses contains only JOIN/ON conditions for an outer join */
104  List *joinclauses; /* List of RestrictInfo */
105 
106  /* Upper relation information */
108 
109  /* Grouping information */
111 
112  /* Subquery information */
113  bool make_outerrel_subquery; /* do we deparse outerrel as a
114  * subquery? */
115  bool make_innerrel_subquery; /* do we deparse innerrel as a
116  * subquery? */
117  Relids lower_subquery_rels; /* all relids appearing in lower
118  * subqueries */
119 
120  /*
121  * Index of the relation. It is used to create an alias to a subquery
122  * representing the relation.
123  */
126 
127 /* in postgres_fdw.c */
128 extern int set_transmission_modes(void);
129 extern void reset_transmission_modes(int nestlevel);
130 
131 /* in connection.c */
132 extern PGconn *GetConnection(UserMapping *user, bool will_prep_stmt);
133 extern void ReleaseConnection(PGconn *conn);
134 extern unsigned int GetCursorNumber(PGconn *conn);
135 extern unsigned int GetPrepStmtNumber(PGconn *conn);
136 extern PGresult *pgfdw_get_result(PGconn *conn, const char *query);
137 extern PGresult *pgfdw_exec_query(PGconn *conn, const char *query);
138 extern void pgfdw_report_error(int elevel, PGresult *res, PGconn *conn,
139  bool clear, const char *sql);
140 
141 /* in option.c */
142 extern int ExtractConnectionOptions(List *defelems,
143  const char **keywords,
144  const char **values);
145 extern List *ExtractExtensionList(const char *extensionsString,
146  bool warnOnMissing);
147 
148 /* in deparse.c */
149 extern void classifyConditions(PlannerInfo *root,
150  RelOptInfo *baserel,
151  List *input_conds,
152  List **remote_conds,
153  List **local_conds);
154 extern bool is_foreign_expr(PlannerInfo *root,
155  RelOptInfo *baserel,
156  Expr *expr);
157 extern bool is_foreign_param(PlannerInfo *root,
158  RelOptInfo *baserel,
159  Expr *expr);
160 extern void deparseInsertSql(StringInfo buf, RangeTblEntry *rte,
161  Index rtindex, Relation rel,
162  List *targetAttrs, bool doNothing,
163  List *withCheckOptionList, List *returningList,
164  List **retrieved_attrs);
165 extern void deparseUpdateSql(StringInfo buf, RangeTblEntry *rte,
166  Index rtindex, Relation rel,
167  List *targetAttrs,
168  List *withCheckOptionList, List *returningList,
169  List **retrieved_attrs);
171  Index rtindex, Relation rel,
172  RelOptInfo *foreignrel,
173  List *targetlist,
174  List *targetAttrs,
176  List **params_list,
177  List *returningList,
178  List **retrieved_attrs);
179 extern void deparseDeleteSql(StringInfo buf, RangeTblEntry *rte,
180  Index rtindex, Relation rel,
181  List *returningList,
182  List **retrieved_attrs);
184  Index rtindex, Relation rel,
185  RelOptInfo *foreignrel,
187  List **params_list,
188  List *returningList,
189  List **retrieved_attrs);
190 extern void deparseAnalyzeSizeSql(StringInfo buf, Relation rel);
191 extern void deparseAnalyzeSql(StringInfo buf, Relation rel,
192  List **retrieved_attrs);
193 extern void deparseStringLiteral(StringInfo buf, const char *val);
196  EquivalenceClass *ec,
197  PathTarget *target);
198 extern List *build_tlist_to_deparse(RelOptInfo *foreignrel);
200  RelOptInfo *foreignrel, List *tlist,
201  List *remote_conds, List *pathkeys,
202  bool has_final_sort, bool has_limit,
203  bool is_subquery,
204  List **retrieved_attrs, List **params_list);
205 extern const char *get_jointype_name(JoinType jointype);
206 
207 /* in shippable.c */
208 extern bool is_builtin(Oid objectId);
209 extern bool is_shippable(Oid objectId, Oid classId, PgFdwRelationInfo *fpinfo);
210 
211 #endif /* POSTGRES_FDW_H */
bool is_builtin(Oid objectId)
Definition: shippable.c:153
UpperRelationKind
Definition: pathnodes.h:67
void reset_transmission_modes(int nestlevel)
List * build_tlist_to_deparse(RelOptInfo *foreignrel)
Definition: deparse.c:938
PGconn * GetConnection(UserMapping *user, bool will_prep_stmt)
Definition: connection.c:109
void deparseInsertSql(StringInfo buf, RangeTblEntry *rte, Index rtindex, Relation rel, List *targetAttrs, bool doNothing, List *withCheckOptionList, List *returningList, List **retrieved_attrs)
Definition: deparse.c:1705
bool is_foreign_expr(PlannerInfo *root, RelOptInfo *baserel, Expr *expr)
Definition: deparse.c:230
ForeignServer * server
Definition: postgres_fdw.h:84
int ExtractConnectionOptions(List *defelems, const char **keywords, const char **values)
Definition: option.c:333
Relids lower_subquery_rels
Definition: postgres_fdw.h:117
void classifyConditions(PlannerInfo *root, RelOptInfo *baserel, List *input_conds, List **remote_conds, List **local_conds)
Definition: deparse.c:204
double Selectivity
Definition: nodes.h:660
unsigned int Oid
Definition: postgres_ext.h:31
bool is_shippable(Oid objectId, Oid classId, PgFdwRelationInfo *fpinfo)
Definition: shippable.c:163
RelOptInfo * outerrel
Definition: postgres_fdw.h:100
JoinType
Definition: nodes.h:694
const char * get_jointype_name(JoinType jointype)
Definition: deparse.c:1369
unsigned int GetPrepStmtNumber(PGconn *conn)
Definition: connection.c:629
bool is_foreign_param(PlannerInfo *root, RelOptInfo *baserel, Expr *expr)
Definition: deparse.c:871
PGconn * conn
Definition: streamutil.c:54
Selectivity local_conds_sel
Definition: postgres_fdw.h:56
void deparseDirectUpdateSql(StringInfo buf, PlannerInfo *root, Index rtindex, Relation rel, RelOptInfo *foreignrel, List *targetlist, List *targetAttrs, List *remote_conds, List **params_list, List *returningList, List **retrieved_attrs)
Definition: deparse.c:1821
List * ExtractExtensionList(const char *extensionsString, bool warnOnMissing)
Definition: option.c:364
Selectivity joinclause_sel
Definition: postgres_fdw.h:59
static char * buf
Definition: pg_test_fsync.c:68
PGresult * pgfdw_get_result(PGconn *conn, const char *query)
Definition: connection.c:666
int set_transmission_modes(void)
void deparseAnalyzeSql(StringInfo buf, Relation rel, List **retrieved_attrs)
Definition: deparse.c:2063
void deparseSelectStmtForRel(StringInfo buf, PlannerInfo *root, RelOptInfo *foreignrel, List *tlist, List *remote_conds, List *pathkeys, bool has_final_sort, bool has_limit, bool is_subquery, List **retrieved_attrs, List **params_list)
Definition: deparse.c:995
static int elevel
Definition: vacuumlazy.c:333
void deparseDeleteSql(StringInfo buf, RangeTblEntry *rte, Index rtindex, Relation rel, List *returningList, List **retrieved_attrs)
Definition: deparse.c:1906
UserMapping * user
Definition: postgres_fdw.h:85
unsigned int Index
Definition: c.h:537
Expr * find_em_expr_for_rel(EquivalenceClass *ec, RelOptInfo *rel)
Definition: equivclass.c:776
PGresult * pgfdw_exec_query(PGconn *conn, const char *query)
Definition: connection.c:642
unsigned int GetCursorNumber(PGconn *conn)
Definition: connection.c:615
Bitmapset * attrs_used
Definition: postgres_fdw.h:49
void deparseDirectDeleteSql(StringInfo buf, PlannerInfo *root, Index rtindex, Relation rel, RelOptInfo *foreignrel, List *remote_conds, List **params_list, List *returningList, List **retrieved_attrs)
Definition: deparse.c:1935
ForeignTable * table
Definition: postgres_fdw.h:83
void pgfdw_report_error(int elevel, PGresult *res, PGconn *conn, bool clear, const char *sql)
Definition: connection.c:731
void deparseAnalyzeSizeSql(StringInfo buf, Relation rel)
Definition: deparse.c:2043
void ReleaseConnection(PGconn *conn)
Definition: connection.c:594
static Datum values[MAXATTR]
Definition: bootstrap.c:165
RelOptInfo * innerrel
Definition: postgres_fdw.h:101
List * final_remote_exprs
Definition: postgres_fdw.h:46
UpperRelationKind stage
Definition: postgres_fdw.h:107
Expr * find_em_expr_for_input_target(PlannerInfo *root, EquivalenceClass *ec, PathTarget *target)
List * shippable_extensions
Definition: postgres_fdw.h:80
Definition: pg_list.h:50
struct PgFdwRelationInfo PgFdwRelationInfo
long val
Definition: informix.c:664
double Cost
Definition: nodes.h:661
void deparseUpdateSql(StringInfo buf, RangeTblEntry *rte, Index rtindex, Relation rel, List *targetAttrs, List *withCheckOptionList, List *returningList, List **retrieved_attrs)
Definition: deparse.c:1769
QualCost local_conds_cost
Definition: postgres_fdw.h:55
void deparseStringLiteral(StringInfo buf, const char *val)
Definition: deparse.c:2292