PostgreSQL Source Code  git master
postgres_fdw.h File Reference
#include "foreign/foreign.h"
#include "lib/stringinfo.h"
#include "libpq-fe.h"
#include "nodes/execnodes.h"
#include "nodes/pathnodes.h"
#include "utils/relcache.h"
Include dependency graph for postgres_fdw.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  PgFdwRelationInfo
 
struct  PgFdwConnState
 

Typedefs

typedef struct PgFdwRelationInfo PgFdwRelationInfo
 
typedef struct PgFdwConnState PgFdwConnState
 

Functions

int set_transmission_modes (void)
 
void reset_transmission_modes (int nestlevel)
 
void process_pending_request (AsyncRequest *areq)
 
PGconnGetConnection (UserMapping *user, bool will_prep_stmt, PgFdwConnState **state)
 
void ReleaseConnection (PGconn *conn)
 
unsigned int GetCursorNumber (PGconn *conn)
 
unsigned int GetPrepStmtNumber (PGconn *conn)
 
void do_sql_command (PGconn *conn, const char *sql)
 
PGresultpgfdw_get_result (PGconn *conn, const char *query)
 
PGresultpgfdw_exec_query (PGconn *conn, const char *query, PgFdwConnState *state)
 
void pgfdw_report_error (int elevel, PGresult *res, PGconn *conn, bool clear, const char *sql)
 
int ExtractConnectionOptions (List *defelems, const char **keywords, const char **values)
 
ListExtractExtensionList (const char *extensionsString, bool warnOnMissing)
 
char * process_pgfdw_appname (const char *appname)
 
void classifyConditions (PlannerInfo *root, RelOptInfo *baserel, List *input_conds, List **remote_conds, List **local_conds)
 
bool is_foreign_expr (PlannerInfo *root, RelOptInfo *baserel, Expr *expr)
 
bool is_foreign_param (PlannerInfo *root, RelOptInfo *baserel, Expr *expr)
 
void deparseInsertSql (StringInfo buf, RangeTblEntry *rte, Index rtindex, Relation rel, List *targetAttrs, bool doNothing, List *withCheckOptionList, List *returningList, List **retrieved_attrs, int *values_end_len)
 
void rebuildInsertSql (StringInfo buf, Relation rel, char *orig_query, List *target_attrs, int values_end_len, int num_params, int num_rows)
 
void deparseUpdateSql (StringInfo buf, RangeTblEntry *rte, Index rtindex, Relation rel, List *targetAttrs, List *withCheckOptionList, List *returningList, List **retrieved_attrs)
 
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)
 
void deparseDeleteSql (StringInfo buf, RangeTblEntry *rte, Index rtindex, Relation rel, List *returningList, List **retrieved_attrs)
 
void deparseDirectDeleteSql (StringInfo buf, PlannerInfo *root, Index rtindex, Relation rel, RelOptInfo *foreignrel, List *remote_conds, List **params_list, List *returningList, List **retrieved_attrs)
 
void deparseAnalyzeSizeSql (StringInfo buf, Relation rel)
 
void deparseAnalyzeSql (StringInfo buf, Relation rel, List **retrieved_attrs)
 
void deparseTruncateSql (StringInfo buf, List *rels, DropBehavior behavior, bool restart_seqs)
 
void deparseStringLiteral (StringInfo buf, const char *val)
 
Exprfind_em_expr_for_rel (EquivalenceClass *ec, RelOptInfo *rel)
 
Exprfind_em_expr_for_input_target (PlannerInfo *root, EquivalenceClass *ec, PathTarget *target)
 
Listbuild_tlist_to_deparse (RelOptInfo *foreignrel)
 
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)
 
const char * get_jointype_name (JoinType jointype)
 
bool is_builtin (Oid objectId)
 
bool is_shippable (Oid objectId, Oid classId, PgFdwRelationInfo *fpinfo)
 

Variables

char * pgfdw_application_name
 

Typedef Documentation

◆ PgFdwConnState

◆ PgFdwRelationInfo

Function Documentation

◆ build_tlist_to_deparse()

List* build_tlist_to_deparse ( RelOptInfo foreignrel)

Definition at line 1072 of file deparse.c.

1073 {
1074  List *tlist = NIL;
1075  PgFdwRelationInfo *fpinfo = (PgFdwRelationInfo *) foreignrel->fdw_private;
1076  ListCell *lc;
1077 
1078  /*
1079  * For an upper relation, we have already built the target list while
1080  * checking shippability, so just return that.
1081  */
1082  if (IS_UPPER_REL(foreignrel))
1083  return fpinfo->grouped_tlist;
1084 
1085  /*
1086  * We require columns specified in foreignrel->reltarget->exprs and those
1087  * required for evaluating the local conditions.
1088  */
1089  tlist = add_to_flat_tlist(tlist,
1090  pull_var_clause((Node *) foreignrel->reltarget->exprs,
1092  foreach(lc, fpinfo->local_conds)
1093  {
1094  RestrictInfo *rinfo = lfirst_node(RestrictInfo, lc);
1095 
1096  tlist = add_to_flat_tlist(tlist,
1097  pull_var_clause((Node *) rinfo->clause,
1099  }
1100 
1101  return tlist;
1102 }
#define PVC_RECURSE_PLACEHOLDERS
Definition: optimizer.h:191
#define IS_UPPER_REL(rel)
Definition: pathnodes.h:664
#define lfirst_node(type, lc)
Definition: pg_list.h:172
#define NIL
Definition: pg_list.h:65
Definition: pg_list.h:51
Definition: nodes.h:540
List * exprs
Definition: pathnodes.h:1111
void * fdw_private
Definition: pathnodes.h:737
struct PathTarget * reltarget
Definition: pathnodes.h:692
Expr * clause
Definition: pathnodes.h:2059
List * add_to_flat_tlist(List *tlist, List *exprs)
Definition: tlist.c:121
List * pull_var_clause(Node *node, int flags)
Definition: var.c:604

References add_to_flat_tlist(), RestrictInfo::clause, PathTarget::exprs, RelOptInfo::fdw_private, PgFdwRelationInfo::grouped_tlist, if(), IS_UPPER_REL, lfirst_node, PgFdwRelationInfo::local_conds, NIL, pull_var_clause(), PVC_RECURSE_PLACEHOLDERS, and RelOptInfo::reltarget.

Referenced by estimate_path_cost_size(), and postgresGetForeignPlan().

◆ classifyConditions()

void classifyConditions ( PlannerInfo root,
RelOptInfo baserel,
List input_conds,
List **  remote_conds,
List **  local_conds 
)

Definition at line 208 of file deparse.c.

213 {
214  ListCell *lc;
215 
216  *remote_conds = NIL;
217  *local_conds = NIL;
218 
219  foreach(lc, input_conds)
220  {
222 
223  if (is_foreign_expr(root, baserel, ri->clause))
224  *remote_conds = lappend(*remote_conds, ri);
225  else
226  *local_conds = lappend(*local_conds, ri);
227  }
228 }
bool is_foreign_expr(PlannerInfo *root, RelOptInfo *baserel, Expr *expr)
Definition: deparse.c:234
List * lappend(List *list, void *datum)
Definition: list.c:336

References RestrictInfo::clause, is_foreign_expr(), lappend(), lfirst_node, and NIL.

Referenced by estimate_path_cost_size(), and postgresGetForeignRelSize().

◆ deparseAnalyzeSizeSql()

void deparseAnalyzeSizeSql ( StringInfo  buf,
Relation  rel 
)

Definition at line 2257 of file deparse.c.

2258 {
2260 
2261  /* We'll need the remote relation name as a literal. */
2263  deparseRelation(&relname, rel);
2264 
2265  appendStringInfoString(buf, "SELECT pg_catalog.pg_relation_size(");
2267  appendStringInfo(buf, "::pg_catalog.regclass) / %d", BLCKSZ);
2268 }
void deparseStringLiteral(StringInfo buf, const char *val)
Definition: deparse.c:2538
static void deparseRelation(StringInfo buf, Relation rel)
Definition: deparse.c:2498
NameData relname
Definition: pg_class.h:38
static char * buf
Definition: pg_test_fsync.c:70
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
char data[NAMEDATALEN]
Definition: c.h:677

References appendStringInfo(), appendStringInfoString(), buf, nameData::data, deparseRelation(), deparseStringLiteral(), initStringInfo(), and relname.

Referenced by postgresAnalyzeForeignTable().

◆ deparseAnalyzeSql()

void deparseAnalyzeSql ( StringInfo  buf,
Relation  rel,
List **  retrieved_attrs 
)

Definition at line 2277 of file deparse.c.

2278 {
2279  Oid relid = RelationGetRelid(rel);
2280  TupleDesc tupdesc = RelationGetDescr(rel);
2281  int i;
2282  char *colname;
2283  List *options;
2284  ListCell *lc;
2285  bool first = true;
2286 
2287  *retrieved_attrs = NIL;
2288 
2289  appendStringInfoString(buf, "SELECT ");
2290  for (i = 0; i < tupdesc->natts; i++)
2291  {
2292  /* Ignore dropped columns. */
2293  if (TupleDescAttr(tupdesc, i)->attisdropped)
2294  continue;
2295 
2296  if (!first)
2297  appendStringInfoString(buf, ", ");
2298  first = false;
2299 
2300  /* Use attribute name or column_name option. */
2301  colname = NameStr(TupleDescAttr(tupdesc, i)->attname);
2302  options = GetForeignColumnOptions(relid, i + 1);
2303 
2304  foreach(lc, options)
2305  {
2306  DefElem *def = (DefElem *) lfirst(lc);
2307 
2308  if (strcmp(def->defname, "column_name") == 0)
2309  {
2310  colname = defGetString(def);
2311  break;
2312  }
2313  }
2314 
2316 
2317  *retrieved_attrs = lappend_int(*retrieved_attrs, i + 1);
2318  }
2319 
2320  /* Don't generate bad syntax for zero-column relation. */
2321  if (first)
2322  appendStringInfoString(buf, "NULL");
2323 
2324  /*
2325  * Construct FROM clause
2326  */
2327  appendStringInfoString(buf, " FROM ");
2328  deparseRelation(buf, rel);
2329 }
#define NameStr(name)
Definition: c.h:681
char * defGetString(DefElem *def)
Definition: define.c:49
List * GetForeignColumnOptions(Oid relid, AttrNumber attnum)
Definition: foreign.c:286
int i
Definition: isn.c:73
List * lappend_int(List *list, int datum)
Definition: list.c:354
NameData attname
Definition: pg_attribute.h:41
#define lfirst(lc)
Definition: pg_list.h:169
static char ** options
unsigned int Oid
Definition: postgres_ext.h:31
#define RelationGetRelid(relation)
Definition: rel.h:478
#define RelationGetDescr(relation)
Definition: rel.h:504
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:11440
char * defname
Definition: parsenodes.h:758
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92

References appendStringInfoString(), attname, buf, defGetString(), DefElem::defname, deparseRelation(), GetForeignColumnOptions(), i, lappend_int(), lfirst, NameStr, TupleDescData::natts, NIL, options, quote_identifier(), RelationGetDescr, RelationGetRelid, and TupleDescAttr.

Referenced by postgresAcquireSampleRowsFunc().

◆ deparseDeleteSql()

void deparseDeleteSql ( StringInfo  buf,
RangeTblEntry rte,
Index  rtindex,
Relation  rel,
List returningList,
List **  retrieved_attrs 
)

Definition at line 2120 of file deparse.c.

2124 {
2125  appendStringInfoString(buf, "DELETE FROM ");
2126  deparseRelation(buf, rel);
2127  appendStringInfoString(buf, " WHERE ctid = $1");
2128 
2129  deparseReturningList(buf, rte, rtindex, rel,
2130  rel->trigdesc && rel->trigdesc->trig_delete_after_row,
2131  NIL, returningList, retrieved_attrs);
2132 }
static void deparseReturningList(StringInfo buf, RangeTblEntry *rte, Index rtindex, Relation rel, bool trig_after_row, List *withCheckOptionList, List *returningList, List **retrieved_attrs)
Definition: deparse.c:2200
TriggerDesc * trigdesc
Definition: rel.h:115
bool trig_delete_after_row
Definition: reltrigger.h:67

References appendStringInfoString(), buf, deparseRelation(), deparseReturningList(), NIL, TriggerDesc::trig_delete_after_row, and RelationData::trigdesc.

Referenced by postgresPlanForeignModify().

◆ deparseDirectDeleteSql()

void deparseDirectDeleteSql ( StringInfo  buf,
PlannerInfo root,
Index  rtindex,
Relation  rel,
RelOptInfo foreignrel,
List remote_conds,
List **  params_list,
List returningList,
List **  retrieved_attrs 
)

Definition at line 2149 of file deparse.c.

2156 {
2157  deparse_expr_cxt context;
2158 
2159  /* Set up context struct for recursion */
2160  context.root = root;
2161  context.foreignrel = foreignrel;
2162  context.scanrel = foreignrel;
2163  context.buf = buf;
2164  context.params_list = params_list;
2165 
2166  appendStringInfoString(buf, "DELETE FROM ");
2167  deparseRelation(buf, rel);
2168  if (foreignrel->reloptkind == RELOPT_JOINREL)
2169  appendStringInfo(buf, " %s%d", REL_ALIAS_PREFIX, rtindex);
2170 
2171  if (foreignrel->reloptkind == RELOPT_JOINREL)
2172  {
2173  List *ignore_conds = NIL;
2174 
2175  appendStringInfoString(buf, " USING ");
2176  deparseFromExprForRel(buf, root, foreignrel, true, rtindex,
2177  &ignore_conds, params_list);
2178  remote_conds = list_concat(remote_conds, ignore_conds);
2179  }
2180 
2181  if (remote_conds)
2182  {
2183  appendStringInfoString(buf, " WHERE ");
2184  appendConditions(remote_conds, &context);
2185  }
2186 
2187  if (foreignrel->reloptkind == RELOPT_JOINREL)
2188  deparseExplicitTargetList(returningList, true, retrieved_attrs,
2189  &context);
2190  else
2191  deparseReturningList(buf, planner_rt_fetch(rtindex, root),
2192  rtindex, rel, false,
2193  NIL, returningList, retrieved_attrs);
2194 }
#define REL_ALIAS_PREFIX
Definition: deparse.c:106
static void appendConditions(List *exprs, deparse_expr_cxt *context)
Definition: deparse.c:1469
static void deparseExplicitTargetList(List *tlist, bool is_returning, List **retrieved_attrs, deparse_expr_cxt *context)
Definition: deparse.c:1540
static void deparseFromExprForRel(StringInfo buf, PlannerInfo *root, RelOptInfo *foreignrel, bool use_alias, Index ignore_rel, List **ignore_conds, List **params_list)
Definition: deparse.c:1617
List * list_concat(List *list1, const List *list2)
Definition: list.c:540
#define planner_rt_fetch(rti, root)
Definition: pathnodes.h:388
@ RELOPT_JOINREL
Definition: pathnodes.h:642
RelOptKind reloptkind
Definition: pathnodes.h:678
PlannerInfo * root
Definition: deparse.c:97
List ** params_list
Definition: deparse.c:103
RelOptInfo * foreignrel
Definition: deparse.c:98
StringInfo buf
Definition: deparse.c:102
RelOptInfo * scanrel
Definition: deparse.c:99

References appendConditions(), appendStringInfo(), appendStringInfoString(), deparse_expr_cxt::buf, buf, deparseExplicitTargetList(), deparseFromExprForRel(), deparseRelation(), deparseReturningList(), deparse_expr_cxt::foreignrel, list_concat(), NIL, deparse_expr_cxt::params_list, planner_rt_fetch, REL_ALIAS_PREFIX, RELOPT_JOINREL, RelOptInfo::reloptkind, deparse_expr_cxt::root, and deparse_expr_cxt::scanrel.

Referenced by postgresPlanDirectModify().

◆ deparseDirectUpdateSql()

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 at line 2035 of file deparse.c.

2044 {
2045  deparse_expr_cxt context;
2046  int nestlevel;
2047  bool first;
2048  RangeTblEntry *rte = planner_rt_fetch(rtindex, root);
2049  ListCell *lc,
2050  *lc2;
2051 
2052  /* Set up context struct for recursion */
2053  context.root = root;
2054  context.foreignrel = foreignrel;
2055  context.scanrel = foreignrel;
2056  context.buf = buf;
2057  context.params_list = params_list;
2058 
2059  appendStringInfoString(buf, "UPDATE ");
2060  deparseRelation(buf, rel);
2061  if (foreignrel->reloptkind == RELOPT_JOINREL)
2062  appendStringInfo(buf, " %s%d", REL_ALIAS_PREFIX, rtindex);
2063  appendStringInfoString(buf, " SET ");
2064 
2065  /* Make sure any constants in the exprs are printed portably */
2066  nestlevel = set_transmission_modes();
2067 
2068  first = true;
2069  forboth(lc, targetlist, lc2, targetAttrs)
2070  {
2071  TargetEntry *tle = lfirst_node(TargetEntry, lc);
2072  int attnum = lfirst_int(lc2);
2073 
2074  /* update's new-value expressions shouldn't be resjunk */
2075  Assert(!tle->resjunk);
2076 
2077  if (!first)
2078  appendStringInfoString(buf, ", ");
2079  first = false;
2080 
2081  deparseColumnRef(buf, rtindex, attnum, rte, false);
2082  appendStringInfoString(buf, " = ");
2083  deparseExpr((Expr *) tle->expr, &context);
2084  }
2085 
2086  reset_transmission_modes(nestlevel);
2087 
2088  if (foreignrel->reloptkind == RELOPT_JOINREL)
2089  {
2090  List *ignore_conds = NIL;
2091 
2092  appendStringInfoString(buf, " FROM ");
2093  deparseFromExprForRel(buf, root, foreignrel, true, rtindex,
2094  &ignore_conds, params_list);
2095  remote_conds = list_concat(remote_conds, ignore_conds);
2096  }
2097 
2098  if (remote_conds)
2099  {
2100  appendStringInfoString(buf, " WHERE ");
2101  appendConditions(remote_conds, &context);
2102  }
2103 
2104  if (foreignrel->reloptkind == RELOPT_JOINREL)
2105  deparseExplicitTargetList(returningList, true, retrieved_attrs,
2106  &context);
2107  else
2108  deparseReturningList(buf, rte, rtindex, rel, false,
2109  NIL, returningList, retrieved_attrs);
2110 }
static void deparseExpr(Expr *expr, deparse_expr_cxt *context)
Definition: deparse.c:2573
static void deparseColumnRef(StringInfo buf, int varno, int varattno, RangeTblEntry *rte, bool qualify_col)
Definition: deparse.c:2370
Assert(fmt[strlen(fmt) - 1] !='\n')
int16 attnum
Definition: pg_attribute.h:83
#define forboth(cell1, list1, cell2, list2)
Definition: pg_list.h:446
#define lfirst_int(lc)
Definition: pg_list.h:170
void reset_transmission_modes(int nestlevel)
int set_transmission_modes(void)
Expr * expr
Definition: primnodes.h:1455
bool resjunk
Definition: primnodes.h:1462

References appendConditions(), appendStringInfo(), appendStringInfoString(), Assert(), attnum, deparse_expr_cxt::buf, buf, deparseColumnRef(), deparseExplicitTargetList(), deparseExpr(), deparseFromExprForRel(), deparseRelation(), deparseReturningList(), TargetEntry::expr, forboth, deparse_expr_cxt::foreignrel, lfirst_int, lfirst_node, list_concat(), NIL, deparse_expr_cxt::params_list, planner_rt_fetch, REL_ALIAS_PREFIX, RELOPT_JOINREL, RelOptInfo::reloptkind, reset_transmission_modes(), TargetEntry::resjunk, deparse_expr_cxt::root, deparse_expr_cxt::scanrel, and set_transmission_modes().

Referenced by postgresPlanDirectModify().

◆ deparseInsertSql()

void deparseInsertSql ( StringInfo  buf,
RangeTblEntry rte,
Index  rtindex,
Relation  rel,
List targetAttrs,
bool  doNothing,
List withCheckOptionList,
List returningList,
List **  retrieved_attrs,
int *  values_end_len 
)

Definition at line 1842 of file deparse.c.

1847 {
1848  TupleDesc tupdesc = RelationGetDescr(rel);
1849  AttrNumber pindex;
1850  bool first;
1851  ListCell *lc;
1852 
1853  appendStringInfoString(buf, "INSERT INTO ");
1854  deparseRelation(buf, rel);
1855 
1856  if (targetAttrs)
1857  {
1858  appendStringInfoChar(buf, '(');
1859 
1860  first = true;
1861  foreach(lc, targetAttrs)
1862  {
1863  int attnum = lfirst_int(lc);
1864 
1865  if (!first)
1866  appendStringInfoString(buf, ", ");
1867  first = false;
1868 
1869  deparseColumnRef(buf, rtindex, attnum, rte, false);
1870  }
1871 
1872  appendStringInfoString(buf, ") VALUES (");
1873 
1874  pindex = 1;
1875  first = true;
1876  foreach(lc, targetAttrs)
1877  {
1878  int attnum = lfirst_int(lc);
1879  Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum - 1);
1880 
1881  if (!first)
1882  appendStringInfoString(buf, ", ");
1883  first = false;
1884 
1885  if (attr->attgenerated)
1886  appendStringInfoString(buf, "DEFAULT");
1887  else
1888  {
1889  appendStringInfo(buf, "$%d", pindex);
1890  pindex++;
1891  }
1892  }
1893 
1894  appendStringInfoChar(buf, ')');
1895  }
1896  else
1897  appendStringInfoString(buf, " DEFAULT VALUES");
1898  *values_end_len = buf->len;
1899 
1900  if (doNothing)
1901  appendStringInfoString(buf, " ON CONFLICT DO NOTHING");
1902 
1903  deparseReturningList(buf, rte, rtindex, rel,
1904  rel->trigdesc && rel->trigdesc->trig_insert_after_row,
1905  withCheckOptionList, returningList, retrieved_attrs);
1906 }
int16 AttrNumber
Definition: attnum.h:21
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:207
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:188
bool trig_insert_after_row
Definition: reltrigger.h:57

References appendStringInfo(), appendStringInfoChar(), appendStringInfoString(), attnum, buf, deparseColumnRef(), deparseRelation(), deparseReturningList(), lfirst_int, RelationGetDescr, TriggerDesc::trig_insert_after_row, RelationData::trigdesc, and TupleDescAttr.

Referenced by postgresBeginForeignInsert(), and postgresPlanForeignModify().

◆ deparseSelectStmtForRel()

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 at line 1129 of file deparse.c.

1133 {
1134  deparse_expr_cxt context;
1135  PgFdwRelationInfo *fpinfo = (PgFdwRelationInfo *) rel->fdw_private;
1136  List *quals;
1137 
1138  /*
1139  * We handle relations for foreign tables, joins between those and upper
1140  * relations.
1141  */
1142  Assert(IS_JOIN_REL(rel) || IS_SIMPLE_REL(rel) || IS_UPPER_REL(rel));
1143 
1144  /* Fill portions of context common to upper, join and base relation */
1145  context.buf = buf;
1146  context.root = root;
1147  context.foreignrel = rel;
1148  context.scanrel = IS_UPPER_REL(rel) ? fpinfo->outerrel : rel;
1149  context.params_list = params_list;
1150 
1151  /* Construct SELECT clause */
1152  deparseSelectSql(tlist, is_subquery, retrieved_attrs, &context);
1153 
1154  /*
1155  * For upper relations, the WHERE clause is built from the remote
1156  * conditions of the underlying scan relation; otherwise, we can use the
1157  * supplied list of remote conditions directly.
1158  */
1159  if (IS_UPPER_REL(rel))
1160  {
1161  PgFdwRelationInfo *ofpinfo;
1162 
1163  ofpinfo = (PgFdwRelationInfo *) fpinfo->outerrel->fdw_private;
1164  quals = ofpinfo->remote_conds;
1165  }
1166  else
1167  quals = remote_conds;
1168 
1169  /* Construct FROM and WHERE clauses */
1170  deparseFromExpr(quals, &context);
1171 
1172  if (IS_UPPER_REL(rel))
1173  {
1174  /* Append GROUP BY clause */
1175  appendGroupByClause(tlist, &context);
1176 
1177  /* Append HAVING clause */
1178  if (remote_conds)
1179  {
1180  appendStringInfoString(buf, " HAVING ");
1181  appendConditions(remote_conds, &context);
1182  }
1183  }
1184 
1185  /* Add ORDER BY clause if we found any useful pathkeys */
1186  if (pathkeys)
1187  appendOrderByClause(pathkeys, has_final_sort, &context);
1188 
1189  /* Add LIMIT clause if necessary */
1190  if (has_limit)
1191  appendLimitClause(&context);
1192 
1193  /* Add any necessary FOR UPDATE/SHARE. */
1194  deparseLockingClause(&context);
1195 }
static void appendGroupByClause(List *tlist, deparse_expr_cxt *context)
Definition: deparse.c:3536
static void deparseFromExpr(List *quals, deparse_expr_cxt *context)
Definition: deparse.c:1269
static void deparseLockingClause(deparse_expr_cxt *context)
Definition: deparse.c:1379
static void appendOrderByClause(List *pathkeys, bool has_final_sort, deparse_expr_cxt *context)
Definition: deparse.c:3573
static void appendLimitClause(deparse_expr_cxt *context)
Definition: deparse.c:3627
static void deparseSelectSql(List *tlist, bool is_subquery, List **retrieved_attrs, deparse_expr_cxt *context)
Definition: deparse.c:1211
#define IS_SIMPLE_REL(rel)
Definition: pathnodes.h:654
#define IS_JOIN_REL(rel)
Definition: pathnodes.h:659
RelOptInfo * outerrel
Definition: postgres_fdw.h:102

References appendConditions(), appendGroupByClause(), appendLimitClause(), appendOrderByClause(), appendStringInfoString(), Assert(), deparse_expr_cxt::buf, buf, deparseFromExpr(), deparseLockingClause(), deparseSelectSql(), RelOptInfo::fdw_private, deparse_expr_cxt::foreignrel, IS_JOIN_REL, IS_SIMPLE_REL, IS_UPPER_REL, PgFdwRelationInfo::outerrel, deparse_expr_cxt::params_list, PgFdwRelationInfo::remote_conds, deparse_expr_cxt::root, and deparse_expr_cxt::scanrel.

Referenced by deparseRangeTblRef(), estimate_path_cost_size(), and postgresGetForeignPlan().

◆ deparseStringLiteral()

void deparseStringLiteral ( StringInfo  buf,
const char *  val 
)

Definition at line 2538 of file deparse.c.

2539 {
2540  const char *valptr;
2541 
2542  /*
2543  * Rather than making assumptions about the remote server's value of
2544  * standard_conforming_strings, always use E'foo' syntax if there are any
2545  * backslashes. This will fail on remote servers before 8.1, but those
2546  * are long out of support.
2547  */
2548  if (strchr(val, '\\') != NULL)
2550  appendStringInfoChar(buf, '\'');
2551  for (valptr = val; *valptr; valptr++)
2552  {
2553  char ch = *valptr;
2554 
2555  if (SQL_STR_DOUBLE(ch, true))
2558  }
2559  appendStringInfoChar(buf, '\'');
2560 }
#define ESCAPE_STRING_SYNTAX
Definition: c.h:1164
#define SQL_STR_DOUBLE(ch, escape_backslash)
Definition: c.h:1161
long val
Definition: informix.c:664

References appendStringInfoChar(), buf, ESCAPE_STRING_SYNTAX, SQL_STR_DOUBLE, and val.

Referenced by deparseAnalyzeSizeSql(), deparseConst(), and postgresImportForeignSchema().

◆ deparseTruncateSql()

void deparseTruncateSql ( StringInfo  buf,
List rels,
DropBehavior  behavior,
bool  restart_seqs 
)

Definition at line 2335 of file deparse.c.

2339 {
2340  ListCell *cell;
2341 
2342  appendStringInfoString(buf, "TRUNCATE ");
2343 
2344  foreach(cell, rels)
2345  {
2346  Relation rel = lfirst(cell);
2347 
2348  if (cell != list_head(rels))
2349  appendStringInfoString(buf, ", ");
2350 
2351  deparseRelation(buf, rel);
2352  }
2353 
2354  appendStringInfo(buf, " %s IDENTITY",
2355  restart_seqs ? "RESTART" : "CONTINUE");
2356 
2357  if (behavior == DROP_RESTRICT)
2358  appendStringInfoString(buf, " RESTRICT");
2359  else if (behavior == DROP_CASCADE)
2360  appendStringInfoString(buf, " CASCADE");
2361 }
@ DROP_CASCADE
Definition: parsenodes.h:1862
@ DROP_RESTRICT
Definition: parsenodes.h:1861
static ListCell * list_head(const List *l)
Definition: pg_list.h:125

References appendStringInfo(), appendStringInfoString(), buf, deparseRelation(), DROP_CASCADE, DROP_RESTRICT, lfirst, and list_head().

Referenced by postgresExecForeignTruncate().

◆ deparseUpdateSql()

void deparseUpdateSql ( StringInfo  buf,
RangeTblEntry rte,
Index  rtindex,
Relation  rel,
List targetAttrs,
List withCheckOptionList,
List returningList,
List **  retrieved_attrs 
)

Definition at line 1975 of file deparse.c.

1980 {
1981  TupleDesc tupdesc = RelationGetDescr(rel);
1982  AttrNumber pindex;
1983  bool first;
1984  ListCell *lc;
1985 
1986  appendStringInfoString(buf, "UPDATE ");
1987  deparseRelation(buf, rel);
1988  appendStringInfoString(buf, " SET ");
1989 
1990  pindex = 2; /* ctid is always the first param */
1991  first = true;
1992  foreach(lc, targetAttrs)
1993  {
1994  int attnum = lfirst_int(lc);
1995  Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum - 1);
1996 
1997  if (!first)
1998  appendStringInfoString(buf, ", ");
1999  first = false;
2000 
2001  deparseColumnRef(buf, rtindex, attnum, rte, false);
2002  if (attr->attgenerated)
2003  appendStringInfoString(buf, " = DEFAULT");
2004  else
2005  {
2006  appendStringInfo(buf, " = $%d", pindex);
2007  pindex++;
2008  }
2009  }
2010  appendStringInfoString(buf, " WHERE ctid = $1");
2011 
2012  deparseReturningList(buf, rte, rtindex, rel,
2013  rel->trigdesc && rel->trigdesc->trig_update_after_row,
2014  withCheckOptionList, returningList, retrieved_attrs);
2015 }
bool trig_update_after_row
Definition: reltrigger.h:62

References appendStringInfo(), appendStringInfoString(), attnum, buf, deparseColumnRef(), deparseRelation(), deparseReturningList(), lfirst_int, RelationGetDescr, TriggerDesc::trig_update_after_row, RelationData::trigdesc, and TupleDescAttr.

Referenced by postgresPlanForeignModify().

◆ do_sql_command()

void do_sql_command ( PGconn conn,
const char *  sql 
)

Definition at line 624 of file connection.c.

625 {
626  PGresult *res;
627 
628  if (!PQsendQuery(conn, sql))
629  pgfdw_report_error(ERROR, NULL, conn, false, sql);
630  res = pgfdw_get_result(conn, sql);
632  pgfdw_report_error(ERROR, res, conn, true, sql);
633  PQclear(res);
634 }
PGresult * pgfdw_get_result(PGconn *conn, const char *query)
Definition: connection.c:766
void pgfdw_report_error(int elevel, PGresult *res, PGconn *conn, bool clear, const char *sql)
Definition: connection.c:831
#define ERROR
Definition: elog.h:33
ExecStatusType PQresultStatus(const PGresult *res)
Definition: fe-exec.c:3178
void PQclear(PGresult *res)
Definition: fe-exec.c:694
int PQsendQuery(PGconn *conn, const char *query)
Definition: fe-exec.c:1326
@ PGRES_COMMAND_OK
Definition: libpq-fe.h:95
PGconn * conn
Definition: streamutil.c:54

References conn, ERROR, pgfdw_get_result(), pgfdw_report_error(), PGRES_COMMAND_OK, PQclear(), PQresultStatus(), PQsendQuery(), and res.

Referenced by begin_remote_xact(), configure_remote_session(), pgfdw_subxact_callback(), pgfdw_xact_callback(), and postgresExecForeignTruncate().

◆ ExtractConnectionOptions()

int ExtractConnectionOptions ( List defelems,
const char **  keywords,
const char **  values 
)

Definition at line 380 of file option.c.

382 {
383  ListCell *lc;
384  int i;
385 
386  /* Build our options lists if we didn't yet. */
388 
389  i = 0;
390  foreach(lc, defelems)
391  {
392  DefElem *d = (DefElem *) lfirst(lc);
393 
394  if (is_libpq_option(d->defname))
395  {
396  keywords[i] = d->defname;
397  values[i] = defGetString(d);
398  i++;
399  }
400  }
401  return i;
402 }
static Datum values[MAXATTR]
Definition: bootstrap.c:156
static bool is_libpq_option(const char *keyword)
Definition: option.c:359
static void InitPgFdwOptions(void)
Definition: option.c:218

References defGetString(), DefElem::defname, i, InitPgFdwOptions(), is_libpq_option(), lfirst, and values.

Referenced by connect_pg_server().

◆ ExtractExtensionList()

List* ExtractExtensionList ( const char *  extensionsString,
bool  warnOnMissing 
)

Definition at line 411 of file option.c.

412 {
413  List *extensionOids = NIL;
414  List *extlist;
415  ListCell *lc;
416 
417  /* SplitIdentifierString scribbles on its input, so pstrdup first */
418  if (!SplitIdentifierString(pstrdup(extensionsString), ',', &extlist))
419  {
420  /* syntax error in name list */
421  ereport(ERROR,
422  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
423  errmsg("parameter \"%s\" must be a list of extension names",
424  "extensions")));
425  }
426 
427  foreach(lc, extlist)
428  {
429  const char *extension_name = (const char *) lfirst(lc);
430  Oid extension_oid = get_extension_oid(extension_name, true);
431 
432  if (OidIsValid(extension_oid))
433  {
434  extensionOids = lappend_oid(extensionOids, extension_oid);
435  }
436  else if (warnOnMissing)
437  {
439  (errcode(ERRCODE_UNDEFINED_OBJECT),
440  errmsg("extension \"%s\" is not installed",
441  extension_name)));
442  }
443  }
444 
445  list_free(extlist);
446  return extensionOids;
447 }
#define OidIsValid(objectId)
Definition: c.h:710
int errcode(int sqlerrcode)
Definition: elog.c:693
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define WARNING
Definition: elog.h:30
#define ereport(elevel,...)
Definition: elog.h:143
Oid get_extension_oid(const char *extname, bool missing_ok)
Definition: extension.c:140
List * lappend_oid(List *list, Oid datum)
Definition: list.c:372
void list_free(List *list)
Definition: list.c:1505
char * pstrdup(const char *in)
Definition: mcxt.c:1299
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3754

References ereport, errcode(), errmsg(), ERROR, get_extension_oid(), lappend_oid(), lfirst, list_free(), NIL, OidIsValid, pstrdup(), SplitIdentifierString(), and WARNING.

Referenced by apply_server_options(), and postgres_fdw_validator().

◆ find_em_expr_for_input_target()

Expr* find_em_expr_for_input_target ( PlannerInfo root,
EquivalenceClass ec,
PathTarget target 
)

Definition at line 7377 of file postgres_fdw.c.

7380 {
7381  ListCell *lc1;
7382  int i;
7383 
7384  i = 0;
7385  foreach(lc1, target->exprs)
7386  {
7387  Expr *expr = (Expr *) lfirst(lc1);
7388  Index sgref = get_pathtarget_sortgroupref(target, i);
7389  ListCell *lc2;
7390 
7391  /* Ignore non-sort expressions */
7392  if (sgref == 0 ||
7394  root->parse->sortClause) == NULL)
7395  {
7396  i++;
7397  continue;
7398  }
7399 
7400  /* We ignore binary-compatible relabeling on both ends */
7401  while (expr && IsA(expr, RelabelType))
7402  expr = ((RelabelType *) expr)->arg;
7403 
7404  /* Locate an EquivalenceClass member matching this expr, if any */
7405  foreach(lc2, ec->ec_members)
7406  {
7408  Expr *em_expr;
7409 
7410  /* Don't match constants */
7411  if (em->em_is_const)
7412  continue;
7413 
7414  /* Ignore child members */
7415  if (em->em_is_child)
7416  continue;
7417 
7418  /* Match if same expression (after stripping relabel) */
7419  em_expr = em->em_expr;
7420  while (em_expr && IsA(em_expr, RelabelType))
7421  em_expr = ((RelabelType *) em_expr)->arg;
7422 
7423  if (equal(em_expr, expr))
7424  return em->em_expr;
7425  }
7426 
7427  i++;
7428  }
7429 
7430  elog(ERROR, "could not find pathkey item to sort");
7431  return NULL; /* keep compiler quiet */
7432 }
unsigned int Index
Definition: c.h:549
#define elog(elevel,...)
Definition: elog.h:218
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:3170
#define IsA(nodeptr, _type_)
Definition: nodes.h:590
#define get_pathtarget_sortgroupref(target, colno)
Definition: pathnodes.h:1120
void * arg
List * ec_members
Definition: pathnodes.h:990
Query * parse
Definition: pathnodes.h:162
List * sortClause
Definition: parsenodes.h:168
SortGroupClause * get_sortgroupref_clause_noerr(Index sortref, List *clauses)
Definition: tlist.c:432

References arg, EquivalenceClass::ec_members, elog, EquivalenceMember::em_expr, EquivalenceMember::em_is_child, EquivalenceMember::em_is_const, equal(), ERROR, PathTarget::exprs, get_pathtarget_sortgroupref, get_sortgroupref_clause_noerr(), i, IsA, lfirst, PlannerInfo::parse, and Query::sortClause.

Referenced by add_foreign_ordered_paths(), and appendOrderByClause().

◆ find_em_expr_for_rel()

Expr* find_em_expr_for_rel ( EquivalenceClass ec,
RelOptInfo rel 
)

Definition at line 939 of file equivclass.c.

940 {
941  ListCell *lc_em;
942 
943  foreach(lc_em, ec->ec_members)
944  {
945  EquivalenceMember *em = lfirst(lc_em);
946 
947  if (bms_is_subset(em->em_relids, rel->relids) &&
948  !bms_is_empty(em->em_relids))
949  {
950  /*
951  * If there is more than one equivalence member whose Vars are
952  * taken entirely from this relation, we'll be content to choose
953  * any one of those.
954  */
955  return em->em_expr;
956  }
957  }
958 
959  /* We didn't find any suitable equivalence class expression */
960  return NULL;
961 }
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:315
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:703
Relids relids
Definition: pathnodes.h:681

References bms_is_empty(), bms_is_subset(), EquivalenceClass::ec_members, EquivalenceMember::em_expr, EquivalenceMember::em_relids, lfirst, and RelOptInfo::relids.

Referenced by appendOrderByClause(), and get_useful_pathkeys_for_relation().

◆ get_jointype_name()

const char* get_jointype_name ( JoinType  jointype)

Definition at line 1503 of file deparse.c.

1504 {
1505  switch (jointype)
1506  {
1507  case JOIN_INNER:
1508  return "INNER";
1509 
1510  case JOIN_LEFT:
1511  return "LEFT";
1512 
1513  case JOIN_RIGHT:
1514  return "RIGHT";
1515 
1516  case JOIN_FULL:
1517  return "FULL";
1518 
1519  default:
1520  /* Shouldn't come here, but protect from buggy code. */
1521  elog(ERROR, "unsupported join type %d", jointype);
1522  }
1523 
1524  /* Keep compiler happy */
1525  return NULL;
1526 }
@ JOIN_FULL
Definition: nodes.h:715
@ JOIN_INNER
Definition: nodes.h:713
@ JOIN_RIGHT
Definition: nodes.h:716
@ JOIN_LEFT
Definition: nodes.h:714

References elog, ERROR, JOIN_FULL, JOIN_INNER, JOIN_LEFT, and JOIN_RIGHT.

Referenced by deparseFromExprForRel(), and foreign_join_ok().

◆ GetConnection()

PGconn* GetConnection ( UserMapping user,
bool  will_prep_stmt,
PgFdwConnState **  state 
)

Definition at line 127 of file connection.c.

128 {
129  bool found;
130  bool retry = false;
131  ConnCacheEntry *entry;
134 
135  /* First time through, initialize connection cache hashtable */
136  if (ConnectionHash == NULL)
137  {
138  HASHCTL ctl;
139 
140  ctl.keysize = sizeof(ConnCacheKey);
141  ctl.entrysize = sizeof(ConnCacheEntry);
142  ConnectionHash = hash_create("postgres_fdw connections", 8,
143  &ctl,
145 
146  /*
147  * Register some callback functions that manage connection cleanup.
148  * This should be done just once in each backend.
149  */
156  }
157 
158  /* Set flag that we did GetConnection during the current transaction */
159  xact_got_connection = true;
160 
161  /* Create hash key for the entry. Assume no pad bytes in key struct */
162  key = user->umid;
163 
164  /*
165  * Find or create cached entry for requested connection.
166  */
167  entry = hash_search(ConnectionHash, &key, HASH_ENTER, &found);
168  if (!found)
169  {
170  /*
171  * We need only clear "conn" here; remaining fields will be filled
172  * later when "conn" is set.
173  */
174  entry->conn = NULL;
175  }
176 
177  /* Reject further use of connections which failed abort cleanup. */
179 
180  /*
181  * If the connection needs to be remade due to invalidation, disconnect as
182  * soon as we're out of all transactions.
183  */
184  if (entry->conn != NULL && entry->invalidated && entry->xact_depth == 0)
185  {
186  elog(DEBUG3, "closing connection %p for option changes to take effect",
187  entry->conn);
188  disconnect_pg_server(entry);
189  }
190 
191  /*
192  * If cache entry doesn't have a connection, we have to establish a new
193  * connection. (If connect_pg_server throws an error, the cache entry
194  * will remain in a valid empty state, ie conn == NULL.)
195  */
196  if (entry->conn == NULL)
197  make_new_connection(entry, user);
198 
199  /*
200  * We check the health of the cached connection here when using it. In
201  * cases where we're out of all transactions, if a broken connection is
202  * detected, we try to reestablish a new connection later.
203  */
204  PG_TRY();
205  {
206  /* Process a pending asynchronous request if any. */
207  if (entry->state.pendingAreq)
209  /* Start a new transaction or subtransaction if needed. */
210  begin_remote_xact(entry);
211  }
212  PG_CATCH();
213  {
215  ErrorData *errdata = CopyErrorData();
216 
217  /*
218  * Determine whether to try to reestablish the connection.
219  *
220  * After a broken connection is detected in libpq, any error other
221  * than connection failure (e.g., out-of-memory) can be thrown
222  * somewhere between return from libpq and the expected ereport() call
223  * in pgfdw_report_error(). In this case, since PQstatus() indicates
224  * CONNECTION_BAD, checking only PQstatus() causes the false detection
225  * of connection failure. To avoid this, we also verify that the
226  * error's sqlstate is ERRCODE_CONNECTION_FAILURE. Note that also
227  * checking only the sqlstate can cause another false detection
228  * because pgfdw_report_error() may report ERRCODE_CONNECTION_FAILURE
229  * for any libpq-originated error condition.
230  */
231  if (errdata->sqlerrcode != ERRCODE_CONNECTION_FAILURE ||
232  PQstatus(entry->conn) != CONNECTION_BAD ||
233  entry->xact_depth > 0)
234  {
235  MemoryContextSwitchTo(ecxt);
236  PG_RE_THROW();
237  }
238 
239  /* Clean up the error state */
240  FlushErrorState();
241  FreeErrorData(errdata);
242  errdata = NULL;
243 
244  retry = true;
245  }
246  PG_END_TRY();
247 
248  /*
249  * If a broken connection is detected, disconnect it, reestablish a new
250  * connection and retry a new remote transaction. If connection failure is
251  * reported again, we give up getting a connection.
252  */
253  if (retry)
254  {
255  Assert(entry->xact_depth == 0);
256 
257  ereport(DEBUG3,
258  (errmsg_internal("could not start remote transaction on connection %p",
259  entry->conn)),
260  errdetail_internal("%s", pchomp(PQerrorMessage(entry->conn))));
261 
262  elog(DEBUG3, "closing connection %p to reestablish a new one",
263  entry->conn);
264  disconnect_pg_server(entry);
265 
266  if (entry->conn == NULL)
267  make_new_connection(entry, user);
268 
269  begin_remote_xact(entry);
270  }
271 
272  /* Remember if caller will prepare statements */
273  entry->have_prep_stmt |= will_prep_stmt;
274 
275  /* If caller needs access to the per-connection state, return it. */
276  if (state)
277  *state = &entry->state;
278 
279  return entry->conn;
280 }
Oid ConnCacheKey
Definition: connection.c:49
static void disconnect_pg_server(ConnCacheEntry *entry)
Definition: connection.c:513
static bool xact_got_connection
Definition: connection.c:80
struct ConnCacheEntry ConnCacheEntry
static HTAB * ConnectionHash
Definition: connection.c:73
static void make_new_connection(ConnCacheEntry *entry, UserMapping *user)
Definition: connection.c:287
static void pgfdw_subxact_callback(SubXactEvent event, SubTransactionId mySubid, SubTransactionId parentSubid, void *arg)
Definition: connection.c:1018
static void pgfdw_reject_incomplete_xact_state_change(ConnCacheEntry *entry)
Definition: connection.c:1152
static void pgfdw_inval_callback(Datum arg, int cacheid, uint32 hashvalue)
Definition: connection.c:1102
static void pgfdw_xact_callback(XactEvent event, void *arg)
Definition: connection.c:887
static void begin_remote_xact(ConnCacheEntry *entry)
Definition: connection.c:647
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:349
int errmsg_internal(const char *fmt,...)
Definition: elog.c:991
void FreeErrorData(ErrorData *edata)
Definition: elog.c:1611
int errdetail_internal(const char *fmt,...)
Definition: elog.c:1064
void FlushErrorState(void)
Definition: elog.c:1649
ErrorData * CopyErrorData(void)
Definition: elog.c:1555
#define PG_RE_THROW()
Definition: elog.h:340
#define PG_END_TRY()
Definition: elog.h:324
#define DEBUG3
Definition: elog.h:22
#define PG_TRY()
Definition: elog.h:299
#define PG_CATCH()
Definition: elog.h:309
char * PQerrorMessage(const PGconn *conn)
Definition: fe-connect.c:6915
ConnStatusType PQstatus(const PGconn *conn)
Definition: fe-connect.c:6862
@ HASH_ENTER
Definition: hsearch.h:114
#define HASH_ELEM
Definition: hsearch.h:95
#define HASH_BLOBS
Definition: hsearch.h:97
void CacheRegisterSyscacheCallback(int cacheid, SyscacheCallbackFunction func, Datum arg)
Definition: inval.c:1518
@ CONNECTION_BAD
Definition: libpq-fe.h:59
char * pchomp(const char *in)
Definition: mcxt.c:1327
MemoryContext CurrentMemoryContext
Definition: mcxt.c:42
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
static char * user
Definition: pg_regress.c:95
uintptr_t Datum
Definition: postgres.h:411
void process_pending_request(AsyncRequest *areq)
PGconn * conn
Definition: connection.c:54
bool have_prep_stmt
Definition: connection.c:58
PgFdwConnState state
Definition: connection.c:67
bool invalidated
Definition: connection.c:61
int sqlerrcode
Definition: elog.h:367
Size keysize
Definition: hsearch.h:75
Size entrysize
Definition: hsearch.h:76
AsyncRequest * pendingAreq
Definition: postgres_fdw.h:134
Definition: regguts.h:318
@ FOREIGNSERVEROID
Definition: syscache.h:64
@ USERMAPPINGOID
Definition: syscache.h:113
void RegisterXactCallback(XactCallback callback, void *arg)
Definition: xact.c:3598
void RegisterSubXactCallback(SubXactCallback callback, void *arg)
Definition: xact.c:3653

References Assert(), begin_remote_xact(), CacheRegisterSyscacheCallback(), ConnCacheEntry::conn, CONNECTION_BAD, ConnectionHash, CopyErrorData(), CurrentMemoryContext, DEBUG3, disconnect_pg_server(), elog, HASHCTL::entrysize, ereport, errdetail_internal(), errmsg_internal(), FlushErrorState(), FOREIGNSERVEROID, FreeErrorData(), HASH_BLOBS, hash_create(), HASH_ELEM, HASH_ENTER, hash_search(), ConnCacheEntry::have_prep_stmt, ConnCacheEntry::invalidated, sort-test::key, HASHCTL::keysize, make_new_connection(), MemoryContextSwitchTo(), pchomp(), PgFdwConnState::pendingAreq, PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, pgfdw_inval_callback(), pgfdw_reject_incomplete_xact_state_change(), pgfdw_subxact_callback(), pgfdw_xact_callback(), PQerrorMessage(), PQstatus(), process_pending_request(), RegisterSubXactCallback(), RegisterXactCallback(), ErrorData::sqlerrcode, ConnCacheEntry::state, user, USERMAPPINGOID, ConnCacheEntry::xact_depth, and xact_got_connection.

Referenced by create_foreign_modify(), dumpBlobs(), dumpDatabase(), dumpDatabaseConfig(), dumpTableData_copy(), estimate_path_cost_size(), expand_extension_name_patterns(), expand_foreign_server_name_patterns(), expand_schema_name_patterns(), expand_table_name_patterns(), getTables(), main(), postgresAcquireSampleRowsFunc(), postgresAnalyzeForeignTable(), postgresBeginDirectModify(), postgresBeginForeignScan(), postgresExecForeignTruncate(), postgresImportForeignSchema(), setup_connection(), StartLogStreamer(), StreamLog(), and StreamLogicalLog().

◆ GetCursorNumber()

unsigned int GetCursorNumber ( PGconn conn)

Definition at line 711 of file connection.c.

712 {
713  return ++cursor_number;
714 }
static unsigned int cursor_number
Definition: connection.c:76

References cursor_number.

Referenced by postgresAcquireSampleRowsFunc(), and postgresBeginForeignScan().

◆ GetPrepStmtNumber()

unsigned int GetPrepStmtNumber ( PGconn conn)

Definition at line 725 of file connection.c.

726 {
727  return ++prep_stmt_number;
728 }
static unsigned int prep_stmt_number
Definition: connection.c:77

References prep_stmt_number.

Referenced by prepare_foreign_modify().

◆ is_builtin()

bool is_builtin ( Oid  objectId)

Definition at line 152 of file shippable.c.

153 {
154  return (objectId < FirstGenbkiObjectId);
155 }
#define FirstGenbkiObjectId
Definition: transam.h:195

References FirstGenbkiObjectId.

Referenced by deparse_type_name(), and is_shippable().

◆ is_foreign_expr()

bool is_foreign_expr ( PlannerInfo root,
RelOptInfo baserel,
Expr expr 
)

Definition at line 234 of file deparse.c.

237 {
238  foreign_glob_cxt glob_cxt;
239  foreign_loc_cxt loc_cxt;
240  PgFdwRelationInfo *fpinfo = (PgFdwRelationInfo *) (baserel->fdw_private);
241 
242  /*
243  * Check that the expression consists of nodes that are safe to execute
244  * remotely.
245  */
246  glob_cxt.root = root;
247  glob_cxt.foreignrel = baserel;
248 
249  /*
250  * For an upper relation, use relids from its underneath scan relation,
251  * because the upperrel's own relids currently aren't set to anything
252  * meaningful by the core code. For other relation, use their own relids.
253  */
254  if (IS_UPPER_REL(baserel))
255  glob_cxt.relids = fpinfo->outerrel->relids;
256  else
257  glob_cxt.relids = baserel->relids;
258  loc_cxt.collation = InvalidOid;
259  loc_cxt.state = FDW_COLLATE_NONE;
260  if (!foreign_expr_walker((Node *) expr, &glob_cxt, &loc_cxt, NULL))
261  return false;
262 
263  /*
264  * If the expression has a valid collation that does not arise from a
265  * foreign var, the expression can not be sent over.
266  */
267  if (loc_cxt.state == FDW_COLLATE_UNSAFE)
268  return false;
269 
270  /*
271  * An expression which includes any mutable functions can't be sent over
272  * because its result is not stable. For example, sending now() remote
273  * side could cause confusion from clock offsets. Future versions might
274  * be able to make this choice with more granularity. (We check this last
275  * because it requires a lot of expensive catalog lookups.)
276  */
277  if (contain_mutable_functions((Node *) expr))
278  return false;
279 
280  /* OK to evaluate on the remote server */
281  return true;
282 }
bool contain_mutable_functions(Node *clause)
Definition: clauses.c:364
@ FDW_COLLATE_UNSAFE
Definition: deparse.c:82
@ FDW_COLLATE_NONE
Definition: deparse.c:78
static bool foreign_expr_walker(Node *node, foreign_glob_cxt *glob_cxt, foreign_loc_cxt *outer_cxt, foreign_loc_cxt *case_arg_cxt)
Definition: deparse.c:302
#define InvalidOid
Definition: postgres_ext.h:36
RelOptInfo * foreignrel
Definition: deparse.c:67
Relids relids
Definition: deparse.c:68
PlannerInfo * root
Definition: deparse.c:66
FDWCollateState state
Definition: deparse.c:89

References foreign_loc_cxt::collation, contain_mutable_functions(), FDW_COLLATE_NONE, FDW_COLLATE_UNSAFE, RelOptInfo::fdw_private, foreign_expr_walker(), foreign_glob_cxt::foreignrel, if(), InvalidOid, IS_UPPER_REL, PgFdwRelationInfo::outerrel, foreign_glob_cxt::relids, RelOptInfo::relids, foreign_glob_cxt::root, and foreign_loc_cxt::state.

Referenced by add_foreign_final_paths(), add_foreign_ordered_paths(), classifyConditions(), foreign_grouping_ok(), foreign_join_ok(), get_useful_pathkeys_for_relation(), postgresGetForeignPaths(), postgresGetForeignPlan(), and postgresPlanDirectModify().

◆ is_foreign_param()

bool is_foreign_param ( PlannerInfo root,
RelOptInfo baserel,
Expr expr 
)

Definition at line 1005 of file deparse.c.

1008 {
1009  if (expr == NULL)
1010  return false;
1011 
1012  switch (nodeTag(expr))
1013  {
1014  case T_Var:
1015  {
1016  /* It would have to be sent unless it's a foreign Var */
1017  Var *var = (Var *) expr;
1018  PgFdwRelationInfo *fpinfo = (PgFdwRelationInfo *) (baserel->fdw_private);
1019  Relids relids;
1020 
1021  if (IS_UPPER_REL(baserel))
1022  relids = fpinfo->outerrel->relids;
1023  else
1024  relids = baserel->relids;
1025 
1026  if (bms_is_member(var->varno, relids) && var->varlevelsup == 0)
1027  return false; /* foreign Var, so not a param */
1028  else
1029  return true; /* it'd have to be a param */
1030  break;
1031  }
1032  case T_Param:
1033  /* Params always have to be sent to the foreign server */
1034  return true;
1035  default:
1036  break;
1037  }
1038  return false;
1039 }
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:427
#define nodeTag(nodeptr)
Definition: nodes.h:544
@ T_Param
Definition: nodes.h:158
@ T_Var
Definition: nodes.h:156
Definition: primnodes.h:187
int varno
Definition: primnodes.h:189
Index varlevelsup
Definition: primnodes.h:196

References bms_is_member(), RelOptInfo::fdw_private, if(), IS_UPPER_REL, nodeTag, PgFdwRelationInfo::outerrel, RelOptInfo::relids, T_Param, T_Var, Var::varlevelsup, and Var::varno.

Referenced by foreign_grouping_ok().

◆ is_shippable()

bool is_shippable ( Oid  objectId,
Oid  classId,
PgFdwRelationInfo fpinfo 
)

Definition at line 162 of file shippable.c.

163 {
165  ShippableCacheEntry *entry;
166 
167  /* Built-in objects are presumed shippable. */
168  if (is_builtin(objectId))
169  return true;
170 
171  /* Otherwise, give up if user hasn't specified any shippable extensions. */
172  if (fpinfo->shippable_extensions == NIL)
173  return false;
174 
175  /* Initialize cache if first time through. */
176  if (!ShippableCacheHash)
178 
179  /* Set up cache hash key */
180  key.objid = objectId;
181  key.classid = classId;
182  key.serverid = fpinfo->server->serverid;
183 
184  /* See if we already cached the result. */
185  entry = (ShippableCacheEntry *)
187  (void *) &key,
188  HASH_FIND,
189  NULL);
190 
191  if (!entry)
192  {
193  /* Not found in cache, so perform shippability lookup. */
194  bool shippable = lookup_shippable(objectId, classId, fpinfo);
195 
196  /*
197  * Don't create a new hash entry until *after* we have the shippable
198  * result in hand, as the underlying catalog lookups might trigger a
199  * cache invalidation.
200  */
201  entry = (ShippableCacheEntry *)
203  (void *) &key,
204  HASH_ENTER,
205  NULL);
206 
207  entry->shippable = shippable;
208  }
209 
210  return entry->shippable;
211 }
@ HASH_FIND
Definition: hsearch.h:113
static bool lookup_shippable(Oid objectId, Oid classId, PgFdwRelationInfo *fpinfo)
Definition: shippable.c:116
bool is_builtin(Oid objectId)
Definition: shippable.c:152
static void InitializeShippableCache(void)
Definition: shippable.c:91
static HTAB * ShippableCacheHash
Definition: shippable.c:34
Oid serverid
Definition: foreign.h:36
List * shippable_extensions
Definition: postgres_fdw.h:81
ForeignServer * server
Definition: postgres_fdw.h:86

References HASH_ENTER, HASH_FIND, hash_search(), InitializeShippableCache(), is_builtin(), sort-test::key, lookup_shippable(), NIL, PgFdwRelationInfo::server, ForeignServer::serverid, ShippableCacheEntry::shippable, PgFdwRelationInfo::shippable_extensions, and ShippableCacheHash.

Referenced by foreign_expr_walker().

◆ pgfdw_exec_query()

PGresult* pgfdw_exec_query ( PGconn conn,
const char *  query,
PgFdwConnState state 
)

Definition at line 738 of file connection.c.

739 {
740  /* First, process a pending asynchronous request, if any. */
741  if (state && state->pendingAreq)
742  process_pending_request(state->pendingAreq);
743 
744  /*
745  * Submit a query. Since we don't use non-blocking mode, this also can
746  * block. But its risk is relatively small, so we ignore that for now.
747  */
748  if (!PQsendQuery(conn, query))
749  pgfdw_report_error(ERROR, NULL, conn, false, query);
750 
751  /* Wait for the result. */
752  return pgfdw_get_result(conn, query);
753 }

References conn, ERROR, pgfdw_get_result(), pgfdw_report_error(), PQsendQuery(), and process_pending_request().

Referenced by close_cursor(), deallocate_query(), fetch_more_data(), get_remote_estimate(), postgresAcquireSampleRowsFunc(), postgresAnalyzeForeignTable(), postgresImportForeignSchema(), and postgresReScanForeignScan().

◆ pgfdw_get_result()

PGresult* pgfdw_get_result ( PGconn conn,
const char *  query 
)

Definition at line 766 of file connection.c.

767 {
768  PGresult *volatile last_res = NULL;
769 
770  /* In what follows, do not leak any PGresults on an error. */
771  PG_TRY();
772  {
773  for (;;)
774  {
775  PGresult *res;
776 
777  while (PQisBusy(conn))
778  {
779  int wc;
780 
781  /* Sleep until there's something to do */
785  PQsocket(conn),
786  -1L, PG_WAIT_EXTENSION);
788 
790 
791  /* Data available in socket? */
792  if (wc & WL_SOCKET_READABLE)
793  {
794  if (!PQconsumeInput(conn))
795  pgfdw_report_error(ERROR, NULL, conn, false, query);
796  }
797  }
798 
799  res = PQgetResult(conn);
800  if (res == NULL)
801  break; /* query is complete */
802 
803  PQclear(last_res);
804  last_res = res;
805  }
806  }
807  PG_CATCH();
808  {
809  PQclear(last_res);
810  PG_RE_THROW();
811  }
812  PG_END_TRY();
813 
814  return last_res;
815 }
int PQsocket(const PGconn *conn)
Definition: fe-connect.c:6941
int PQconsumeInput(PGconn *conn)
Definition: fe-exec.c:1904
int PQisBusy(PGconn *conn)
Definition: fe-exec.c:1951
PGresult * PQgetResult(PGconn *conn)
Definition: fe-exec.c:1978
struct Latch * MyLatch
Definition: globals.c:57
int WaitLatchOrSocket(Latch *latch, int wakeEvents, pgsocket sock, long timeout, uint32 wait_event_info)
Definition: latch.c:500
void ResetLatch(Latch *latch)
Definition: latch.c:660
#define WL_SOCKET_READABLE
Definition: latch.h:126
#define WL_EXIT_ON_PM_DEATH
Definition: latch.h:130
#define WL_LATCH_SET
Definition: latch.h:125
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:120
#define PG_WAIT_EXTENSION
Definition: wait_event.h:23

References CHECK_FOR_INTERRUPTS, conn, ERROR, MyLatch, PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, PG_WAIT_EXTENSION, pgfdw_report_error(), PQclear(), PQconsumeInput(), PQgetResult(), PQisBusy(), PQsocket(), res, ResetLatch(), WaitLatchOrSocket(), WL_EXIT_ON_PM_DEATH, WL_LATCH_SET, and WL_SOCKET_READABLE.

Referenced by create_cursor(), do_sql_command(), execute_dml_stmt(), execute_foreign_modify(), fetch_more_data(), pgfdw_exec_query(), and prepare_foreign_modify().

◆ pgfdw_report_error()

void pgfdw_report_error ( int  elevel,
PGresult res,
PGconn conn,
bool  clear,
const char *  sql 
)

Definition at line 831 of file connection.c.

833 {
834  /* If requested, PGresult must be released before leaving this function. */
835  PG_TRY();
836  {
837  char *diag_sqlstate = PQresultErrorField(res, PG_DIAG_SQLSTATE);
838  char *message_primary = PQresultErrorField(res, PG_DIAG_MESSAGE_PRIMARY);
839  char *message_detail = PQresultErrorField(res, PG_DIAG_MESSAGE_DETAIL);
840  char *message_hint = PQresultErrorField(res, PG_DIAG_MESSAGE_HINT);
841  char *message_context = PQresultErrorField(res, PG_DIAG_CONTEXT);
842  int sqlstate;
843 
844  if (diag_sqlstate)
845  sqlstate = MAKE_SQLSTATE(diag_sqlstate[0],
846  diag_sqlstate[1],
847  diag_sqlstate[2],
848  diag_sqlstate[3],
849  diag_sqlstate[4]);
850  else
851  sqlstate = ERRCODE_CONNECTION_FAILURE;
852 
853  /*
854  * If we don't get a message from the PGresult, try the PGconn. This
855  * is needed because for connection-level failures, PQexec may just
856  * return NULL, not a PGresult at all.
857  */
858  if (message_primary == NULL)
859  message_primary = pchomp(PQerrorMessage(conn));
860 
861  ereport(elevel,
862  (errcode(sqlstate),
863  (message_primary != NULL && message_primary[0] != '\0') ?
864  errmsg_internal("%s", message_primary) :
865  errmsg("could not obtain message string for remote error"),
866  message_detail ? errdetail_internal("%s", message_detail) : 0,
867  message_hint ? errhint("%s", message_hint) : 0,
868  message_context ? errcontext("%s", message_context) : 0,
869  sql ? errcontext("remote SQL command: %s", sql) : 0));
870  }
871  PG_FINALLY();
872  {
873  if (clear)
874  PQclear(res);
875  }
876  PG_END_TRY();
877 }
int errhint(const char *fmt,...)
Definition: elog.c:1151
#define errcontext
Definition: elog.h:190
#define PG_FINALLY()
Definition: elog.h:316
#define MAKE_SQLSTATE(ch1, ch2, ch3, ch4, ch5)
Definition: elog.h:50
char * PQresultErrorField(const PGresult *res, int fieldcode)
Definition: fe-exec.c:3233
#define PG_DIAG_MESSAGE_HINT
Definition: postgres_ext.h:60
#define PG_DIAG_SQLSTATE
Definition: postgres_ext.h:57
#define PG_DIAG_MESSAGE_PRIMARY
Definition: postgres_ext.h:58
#define PG_DIAG_MESSAGE_DETAIL
Definition: postgres_ext.h:59
#define PG_DIAG_CONTEXT
Definition: postgres_ext.h:64

References conn, ereport, errcode(), errcontext, errdetail_internal(), errhint(), errmsg(), errmsg_internal(), MAKE_SQLSTATE, pchomp(), PG_DIAG_CONTEXT, PG_DIAG_MESSAGE_DETAIL, PG_DIAG_MESSAGE_HINT, PG_DIAG_MESSAGE_PRIMARY, PG_DIAG_SQLSTATE, PG_END_TRY, PG_FINALLY, PG_TRY, PQclear(), PQerrorMessage(), PQresultErrorField(), and res.

Referenced by close_cursor(), create_cursor(), deallocate_query(), do_sql_command(), execute_dml_stmt(), execute_foreign_modify(), fetch_more_data(), fetch_more_data_begin(), get_remote_estimate(), pgfdw_exec_cleanup_query(), pgfdw_exec_query(), pgfdw_get_result(), postgresAcquireSampleRowsFunc(), postgresAnalyzeForeignTable(), postgresForeignAsyncNotify(), postgresImportForeignSchema(), postgresReScanForeignScan(), and prepare_foreign_modify().

◆ process_pending_request()

void process_pending_request ( AsyncRequest areq)

Definition at line 7058 of file postgres_fdw.c.

7059 {
7060  ForeignScanState *node = (ForeignScanState *) areq->requestee;
7061  PgFdwScanState *fsstate = (PgFdwScanState *) node->fdw_state;
7062 
7063  /* The request would have been pending for a callback */
7064  Assert(areq->callback_pending);
7065 
7066  /* The request should be currently in-process */
7067  Assert(fsstate->conn_state->pendingAreq == areq);
7068 
7069  fetch_more_data(node);
7070 
7071  /*
7072  * If we didn't get any tuples, must be end of data; complete the request
7073  * now. Otherwise, we postpone completing the request until we are called
7074  * from postgresForeignAsyncConfigureWait()/postgresForeignAsyncNotify().
7075  */
7076  if (fsstate->next_tuple >= fsstate->num_tuples)
7077  {
7078  /* Unlike AsyncNotify, we unset callback_pending ourselves */
7079  areq->callback_pending = false;
7080  /* Mark the request as complete */
7081  ExecAsyncRequestDone(areq, NULL);
7082  /* Unlike AsyncNotify, we call ExecAsyncResponse ourselves */
7083  ExecAsyncResponse(areq);
7084  }
7085 }
void ExecAsyncResponse(AsyncRequest *areq)
Definition: execAsync.c:117
void ExecAsyncRequestDone(AsyncRequest *areq, TupleTableSlot *result)
Definition: execAsync.c:137
static void fetch_more_data(ForeignScanState *node)
bool callback_pending
Definition: execnodes.h:545
struct PlanState * requestee
Definition: execnodes.h:543

References Assert(), AsyncRequest::callback_pending, ExecAsyncRequestDone(), ExecAsyncResponse(), ForeignScanState::fdw_state, fetch_more_data(), and AsyncRequest::requestee.

Referenced by create_cursor(), execute_dml_stmt(), execute_foreign_modify(), GetConnection(), pgfdw_exec_query(), and postgresForeignAsyncConfigureWait().

◆ process_pgfdw_appname()

char* process_pgfdw_appname ( const char *  appname)

Definition at line 457 of file option.c.

458 {
459  const char *p;
461 
462  Assert(MyProcPort != NULL);
463 
465 
466  for (p = appname; *p != '\0'; p++)
467  {
468  if (*p != '%')
469  {
470  /* literal char, just copy */
472  continue;
473  }
474 
475  /* must be a '%', so skip to the next char */
476  p++;
477  if (*p == '\0')
478  break; /* format error - ignore it */
479  else if (*p == '%')
480  {
481  /* string contains %% */
482  appendStringInfoChar(&buf, '%');
483  continue;
484  }
485 
486  /* process the option */
487  switch (*p)
488  {
489  case 'a':
491  break;
492  case 'd':
494  break;
495  case 'p':
496  appendStringInfo(&buf, "%d", MyProcPid);
497  break;
498  case 'u':
500  break;
501  default:
502  /* format error - ignore it */
503  break;
504  }
505  }
506 
507  return buf.data;
508 }
int MyProcPid
Definition: globals.c:43
struct Port * MyProcPort
Definition: globals.c:46
char * application_name
Definition: guc.c:623
char * user_name
Definition: libpq-be.h:146
char * database_name
Definition: libpq-be.h:145

References appendStringInfo(), appendStringInfoChar(), appendStringInfoString(), application_name, Assert(), buf, Port::database_name, initStringInfo(), MyProcPid, MyProcPort, and Port::user_name.

Referenced by connect_pg_server().

◆ rebuildInsertSql()

void rebuildInsertSql ( StringInfo  buf,
Relation  rel,
char *  orig_query,
List target_attrs,
int  values_end_len,
int  num_params,
int  num_rows 
)

Definition at line 1915 of file deparse.c.

1919 {
1920  TupleDesc tupdesc = RelationGetDescr(rel);
1921  int i;
1922  int pindex;
1923  bool first;
1924  ListCell *lc;
1925 
1926  /* Make sure the values_end_len is sensible */
1927  Assert((values_end_len > 0) && (values_end_len <= strlen(orig_query)));
1928 
1929  /* Copy up to the end of the first record from the original query */
1930  appendBinaryStringInfo(buf, orig_query, values_end_len);
1931 
1932  /*
1933  * Add records to VALUES clause (we already have parameters for the first
1934  * row, so start at the right offset).
1935  */
1936  pindex = num_params + 1;
1937  for (i = 0; i < num_rows; i++)
1938  {
1939  appendStringInfoString(buf, ", (");
1940 
1941  first = true;
1942  foreach(lc, target_attrs)
1943  {
1944  int attnum = lfirst_int(lc);
1945  Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum - 1);
1946 
1947  if (!first)
1948  appendStringInfoString(buf, ", ");
1949  first = false;
1950 
1951  if (attr->attgenerated)
1952  appendStringInfoString(buf, "DEFAULT");
1953  else
1954  {
1955  appendStringInfo(buf, "$%d", pindex);
1956  pindex++;
1957  }
1958  }
1959 
1960  appendStringInfoChar(buf, ')');
1961  }
1962 
1963  /* Copy stuff after VALUES clause from the original query */
1964  appendStringInfoString(buf, orig_query + values_end_len);
1965 }
void appendBinaryStringInfo(StringInfo str, const char *data, int datalen)
Definition: stringinfo.c:227

References appendBinaryStringInfo(), appendStringInfo(), appendStringInfoChar(), appendStringInfoString(), Assert(), attnum, buf, i, lfirst_int, RelationGetDescr, and TupleDescAttr.

Referenced by execute_foreign_modify().

◆ ReleaseConnection()

void ReleaseConnection ( PGconn conn)

Definition at line 690 of file connection.c.

691 {
692  /*
693  * Currently, we don't actually track connection references because all
694  * cleanup is managed on a transaction or subtransaction basis instead. So
695  * there's nothing to do here.
696  */
697 }

Referenced by estimate_path_cost_size(), finish_foreign_modify(), postgresAcquireSampleRowsFunc(), postgresAnalyzeForeignTable(), postgresEndDirectModify(), postgresEndForeignScan(), and postgresImportForeignSchema().

◆ reset_transmission_modes()

void reset_transmission_modes ( int  nestlevel)

Definition at line 3891 of file postgres_fdw.c.

3892 {
3893  AtEOXact_GUC(true, nestlevel);
3894 }
void AtEOXact_GUC(bool isCommit, int nestLevel)
Definition: guc.c:6273

References AtEOXact_GUC().

Referenced by appendConditions(), appendLimitClause(), appendOrderByClause(), convert_prep_stmt_params(), deparseDirectUpdateSql(), and process_query_params().

◆ set_transmission_modes()

int set_transmission_modes ( void  )

Definition at line 3863 of file postgres_fdw.c.

3864 {
3865  int nestlevel = NewGUCNestLevel();
3866 
3867  /*
3868  * The values set here should match what pg_dump does. See also
3869  * configure_remote_session in connection.c.
3870  */
3871  if (DateStyle != USE_ISO_DATES)
3872  (void) set_config_option("datestyle", "ISO",
3874  GUC_ACTION_SAVE, true, 0, false);
3876  (void) set_config_option("intervalstyle", "postgres",
3878  GUC_ACTION_SAVE, true, 0, false);
3879  if (extra_float_digits < 3)
3880  (void) set_config_option("extra_float_digits", "3",
3882  GUC_ACTION_SAVE, true, 0, false);
3883 
3884  return nestlevel;
3885 }
int extra_float_digits
Definition: float.c:43
int DateStyle
Definition: globals.c:118
int IntervalStyle
Definition: globals.c:120
int NewGUCNestLevel(void)
Definition: guc.c:6259
int set_config_option(const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
Definition: guc.c:7350
@ GUC_ACTION_SAVE
Definition: guc.h:196
@ PGC_S_SESSION
Definition: guc.h:119
@ PGC_USERSET
Definition: guc.h:76
#define USE_ISO_DATES
Definition: miscadmin.h:229
#define INTSTYLE_POSTGRES
Definition: miscadmin.h:249

References DateStyle, extra_float_digits, GUC_ACTION_SAVE, IntervalStyle, INTSTYLE_POSTGRES, NewGUCNestLevel(), PGC_S_SESSION, PGC_USERSET, set_config_option(), and USE_ISO_DATES.

Referenced by appendConditions(), appendLimitClause(), appendOrderByClause(), convert_prep_stmt_params(), deparseDirectUpdateSql(), and process_query_params().

Variable Documentation

◆ pgfdw_application_name

char* pgfdw_application_name
extern

Definition at line 52 of file option.c.

Referenced by _PG_init(), and connect_pg_server().