Harmonize parameter names in contrib code.
[pgsql.git] / contrib / postgres_fdw / postgres_fdw.h
bloba11d45bedfc537b050df0ae89f3e7729863cc39c
1 /*-------------------------------------------------------------------------
3 * postgres_fdw.h
4 * Foreign-data wrapper for remote PostgreSQL servers
6 * Portions Copyright (c) 2012-2022, PostgreSQL Global Development Group
8 * IDENTIFICATION
9 * contrib/postgres_fdw/postgres_fdw.h
11 *-------------------------------------------------------------------------
13 #ifndef POSTGRES_FDW_H
14 #define POSTGRES_FDW_H
16 #include "foreign/foreign.h"
17 #include "lib/stringinfo.h"
18 #include "libpq-fe.h"
19 #include "nodes/execnodes.h"
20 #include "nodes/pathnodes.h"
21 #include "utils/relcache.h"
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.
30 typedef struct PgFdwRelationInfo
33 * True means that the relation can be pushed down. Always true for simple
34 * foreign scan.
36 bool pushdown_safe;
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.
43 List *remote_conds;
44 List *local_conds;
46 /* Actual remote restriction clauses for scan (sans RestrictInfos) */
47 List *final_remote_exprs;
49 /* Bitmap of attr numbers we need to fetch from the remote server. */
50 Bitmapset *attrs_used;
52 /* True means that the query_pathkeys is safe to push down */
53 bool qp_is_pushdown_safe;
55 /* Cost and selectivity of local_conds. */
56 QualCost local_conds_cost;
57 Selectivity local_conds_sel;
59 /* Selectivity of join conditions */
60 Selectivity joinclause_sel;
62 /* Estimated size and cost for a scan, join, or grouping/aggregation. */
63 double rows;
64 int width;
65 Cost startup_cost;
66 Cost total_cost;
69 * Estimated number of rows fetched from the foreign server, and costs
70 * excluding costs for transferring those rows from the foreign server.
71 * These are only used by estimate_path_cost_size().
73 double retrieved_rows;
74 Cost rel_startup_cost;
75 Cost rel_total_cost;
77 /* Options extracted from catalogs. */
78 bool use_remote_estimate;
79 Cost fdw_startup_cost;
80 Cost fdw_tuple_cost;
81 List *shippable_extensions; /* OIDs of shippable extensions */
82 bool async_capable;
84 /* Cached catalog information. */
85 ForeignTable *table;
86 ForeignServer *server;
87 UserMapping *user; /* only set in use_remote_estimate mode */
89 int fetch_size; /* fetch size for this remote table */
92 * Name of the relation, for use while EXPLAINing ForeignScan. It is used
93 * for join and upper relations but is set for all relations. For a base
94 * relation, this is really just the RT index as a string; we convert that
95 * while producing EXPLAIN output. For join and upper relations, the name
96 * indicates which base foreign tables are included and the join type or
97 * aggregation type used.
99 char *relation_name;
101 /* Join information */
102 RelOptInfo *outerrel;
103 RelOptInfo *innerrel;
104 JoinType jointype;
105 /* joinclauses contains only JOIN/ON conditions for an outer join */
106 List *joinclauses; /* List of RestrictInfo */
108 /* Upper relation information */
109 UpperRelationKind stage;
111 /* Grouping information */
112 List *grouped_tlist;
114 /* Subquery information */
115 bool make_outerrel_subquery; /* do we deparse outerrel as a
116 * subquery? */
117 bool make_innerrel_subquery; /* do we deparse innerrel as a
118 * subquery? */
119 Relids lower_subquery_rels; /* all relids appearing in lower
120 * subqueries */
123 * Index of the relation. It is used to create an alias to a subquery
124 * representing the relation.
126 int relation_index;
127 } PgFdwRelationInfo;
130 * Extra control information relating to a connection.
132 typedef struct PgFdwConnState
134 AsyncRequest *pendingAreq; /* pending async request */
135 } PgFdwConnState;
137 /* in postgres_fdw.c */
138 extern int set_transmission_modes(void);
139 extern void reset_transmission_modes(int nestlevel);
140 extern void process_pending_request(AsyncRequest *areq);
142 /* in connection.c */
143 extern PGconn *GetConnection(UserMapping *user, bool will_prep_stmt,
144 PgFdwConnState **state);
145 extern void ReleaseConnection(PGconn *conn);
146 extern unsigned int GetCursorNumber(PGconn *conn);
147 extern unsigned int GetPrepStmtNumber(PGconn *conn);
148 extern void do_sql_command(PGconn *conn, const char *sql);
149 extern PGresult *pgfdw_get_result(PGconn *conn, const char *query);
150 extern PGresult *pgfdw_exec_query(PGconn *conn, const char *query,
151 PgFdwConnState *state);
152 extern void pgfdw_report_error(int elevel, PGresult *res, PGconn *conn,
153 bool clear, const char *sql);
155 /* in option.c */
156 extern int ExtractConnectionOptions(List *defelems,
157 const char **keywords,
158 const char **values);
159 extern List *ExtractExtensionList(const char *extensionsString,
160 bool warnOnMissing);
161 extern char *process_pgfdw_appname(const char *appname);
162 extern char *pgfdw_application_name;
164 /* in deparse.c */
165 extern void classifyConditions(PlannerInfo *root,
166 RelOptInfo *baserel,
167 List *input_conds,
168 List **remote_conds,
169 List **local_conds);
170 extern bool is_foreign_expr(PlannerInfo *root,
171 RelOptInfo *baserel,
172 Expr *expr);
173 extern bool is_foreign_param(PlannerInfo *root,
174 RelOptInfo *baserel,
175 Expr *expr);
176 extern bool is_foreign_pathkey(PlannerInfo *root,
177 RelOptInfo *baserel,
178 PathKey *pathkey);
179 extern void deparseInsertSql(StringInfo buf, RangeTblEntry *rte,
180 Index rtindex, Relation rel,
181 List *targetAttrs, bool doNothing,
182 List *withCheckOptionList, List *returningList,
183 List **retrieved_attrs, int *values_end_len);
184 extern void rebuildInsertSql(StringInfo buf, Relation rel,
185 char *orig_query, List *target_attrs,
186 int values_end_len, int num_params,
187 int num_rows);
188 extern void deparseUpdateSql(StringInfo buf, RangeTblEntry *rte,
189 Index rtindex, Relation rel,
190 List *targetAttrs,
191 List *withCheckOptionList, List *returningList,
192 List **retrieved_attrs);
193 extern void deparseDirectUpdateSql(StringInfo buf, PlannerInfo *root,
194 Index rtindex, Relation rel,
195 RelOptInfo *foreignrel,
196 List *targetlist,
197 List *targetAttrs,
198 List *remote_conds,
199 List **params_list,
200 List *returningList,
201 List **retrieved_attrs);
202 extern void deparseDeleteSql(StringInfo buf, RangeTblEntry *rte,
203 Index rtindex, Relation rel,
204 List *returningList,
205 List **retrieved_attrs);
206 extern void deparseDirectDeleteSql(StringInfo buf, PlannerInfo *root,
207 Index rtindex, Relation rel,
208 RelOptInfo *foreignrel,
209 List *remote_conds,
210 List **params_list,
211 List *returningList,
212 List **retrieved_attrs);
213 extern void deparseAnalyzeSizeSql(StringInfo buf, Relation rel);
214 extern void deparseAnalyzeSql(StringInfo buf, Relation rel,
215 List **retrieved_attrs);
216 extern void deparseTruncateSql(StringInfo buf,
217 List *rels,
218 DropBehavior behavior,
219 bool restart_seqs);
220 extern void deparseStringLiteral(StringInfo buf, const char *val);
221 extern EquivalenceMember *find_em_for_rel(PlannerInfo *root,
222 EquivalenceClass *ec,
223 RelOptInfo *rel);
224 extern EquivalenceMember *find_em_for_rel_target(PlannerInfo *root,
225 EquivalenceClass *ec,
226 RelOptInfo *rel);
227 extern List *build_tlist_to_deparse(RelOptInfo *foreignrel);
228 extern void deparseSelectStmtForRel(StringInfo buf, PlannerInfo *root,
229 RelOptInfo *rel, List *tlist,
230 List *remote_conds, List *pathkeys,
231 bool has_final_sort, bool has_limit,
232 bool is_subquery,
233 List **retrieved_attrs, List **params_list);
234 extern const char *get_jointype_name(JoinType jointype);
236 /* in shippable.c */
237 extern bool is_builtin(Oid objectId);
238 extern bool is_shippable(Oid objectId, Oid classId, PgFdwRelationInfo *fpinfo);
240 #endif /* POSTGRES_FDW_H */