PostgreSQL Source Code  git master
postgres_fdw.h File Reference
#include "foreign/foreign.h"
#include "lib/stringinfo.h"
#include "libpq-fe.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
 

Typedefs

typedef struct PgFdwRelationInfo PgFdwRelationInfo
 

Functions

int set_transmission_modes (void)
 
void reset_transmission_modes (int nestlevel)
 
PGconnGetConnection (UserMapping *user, bool will_prep_stmt)
 
void ReleaseConnection (PGconn *conn)
 
unsigned int GetCursorNumber (PGconn *conn)
 
unsigned int GetPrepStmtNumber (PGconn *conn)
 
PGresultpgfdw_get_result (PGconn *conn, const char *query)
 
PGresultpgfdw_exec_query (PGconn *conn, const char *query)
 
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)
 
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, char *orig_query, int values_end_len, int num_cols, 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 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)
 

Typedef Documentation

◆ PgFdwRelationInfo

Function Documentation

◆ build_tlist_to_deparse()

List* build_tlist_to_deparse ( RelOptInfo foreignrel)

Definition at line 943 of file deparse.c.

References add_to_flat_tlist(), RestrictInfo::clause, PathTarget::exprs, RelOptInfo::fdw_private, PgFdwRelationInfo::grouped_tlist, 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().

944 {
945  List *tlist = NIL;
946  PgFdwRelationInfo *fpinfo = (PgFdwRelationInfo *) foreignrel->fdw_private;
947  ListCell *lc;
948 
949  /*
950  * For an upper relation, we have already built the target list while
951  * checking shippability, so just return that.
952  */
953  if (IS_UPPER_REL(foreignrel))
954  return fpinfo->grouped_tlist;
955 
956  /*
957  * We require columns specified in foreignrel->reltarget->exprs and those
958  * required for evaluating the local conditions.
959  */
960  tlist = add_to_flat_tlist(tlist,
961  pull_var_clause((Node *) foreignrel->reltarget->exprs,
963  foreach(lc, fpinfo->local_conds)
964  {
965  RestrictInfo *rinfo = lfirst_node(RestrictInfo, lc);
966 
967  tlist = add_to_flat_tlist(tlist,
968  pull_var_clause((Node *) rinfo->clause,
970  }
971 
972  return tlist;
973 }
#define NIL
Definition: pg_list.h:65
#define PVC_RECURSE_PLACEHOLDERS
Definition: optimizer.h:189
Definition: nodes.h:533
List * pull_var_clause(Node *node, int flags)
Definition: var.c:562
#define lfirst_node(type, lc)
Definition: pg_list.h:172
Expr * clause
Definition: pathnodes.h:2006
List * exprs
Definition: pathnodes.h:1084
void * fdw_private
Definition: pathnodes.h:726
List * add_to_flat_tlist(List *tlist, List *exprs)
Definition: tlist.c:149
#define IS_UPPER_REL(rel)
Definition: pathnodes.h:653
Definition: pg_list.h:50
struct PathTarget * reltarget
Definition: pathnodes.h:681

◆ classifyConditions()

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

Definition at line 204 of file deparse.c.

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

Referenced by estimate_path_cost_size(), and postgresGetForeignRelSize().

209 {
210  ListCell *lc;
211 
212  *remote_conds = NIL;
213  *local_conds = NIL;
214 
215  foreach(lc, input_conds)
216  {
218 
219  if (is_foreign_expr(root, baserel, ri->clause))
220  *remote_conds = lappend(*remote_conds, ri);
221  else
222  *local_conds = lappend(*local_conds, ri);
223  }
224 }
#define NIL
Definition: pg_list.h:65
#define lfirst_node(type, lc)
Definition: pg_list.h:172
List * lappend(List *list, void *datum)
Definition: list.c:336
Expr * clause
Definition: pathnodes.h:2006
bool is_foreign_expr(PlannerInfo *root, RelOptInfo *baserel, Expr *expr)
Definition: deparse.c:230

◆ deparseAnalyzeSizeSql()

void deparseAnalyzeSizeSql ( StringInfo  buf,
Relation  rel 
)

Definition at line 2100 of file deparse.c.

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

Referenced by postgresAnalyzeForeignTable().

2101 {
2103 
2104  /* We'll need the remote relation name as a literal. */
2105  initStringInfo(&relname);
2106  deparseRelation(&relname, rel);
2107 
2108  appendStringInfoString(buf, "SELECT pg_catalog.pg_relation_size(");
2109  deparseStringLiteral(buf, relname.data);
2110  appendStringInfo(buf, "::pg_catalog.regclass) / %d", BLCKSZ);
2111 }
NameData relname
Definition: pg_class.h:38
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
void deparseStringLiteral(StringInfo buf, const char *val)
Definition: deparse.c:2349
static void deparseRelation(StringInfo buf, Relation rel)
Definition: deparse.c:2309

◆ deparseAnalyzeSql()

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

Definition at line 2120 of file deparse.c.

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

Referenced by postgresAcquireSampleRowsFunc().

2121 {
2122  Oid relid = RelationGetRelid(rel);
2123  TupleDesc tupdesc = RelationGetDescr(rel);
2124  int i;
2125  char *colname;
2126  List *options;
2127  ListCell *lc;
2128  bool first = true;
2129 
2130  *retrieved_attrs = NIL;
2131 
2132  appendStringInfoString(buf, "SELECT ");
2133  for (i = 0; i < tupdesc->natts; i++)
2134  {
2135  /* Ignore dropped columns. */
2136  if (TupleDescAttr(tupdesc, i)->attisdropped)
2137  continue;
2138 
2139  if (!first)
2140  appendStringInfoString(buf, ", ");
2141  first = false;
2142 
2143  /* Use attribute name or column_name option. */
2144  colname = NameStr(TupleDescAttr(tupdesc, i)->attname);
2145  options = GetForeignColumnOptions(relid, i + 1);
2146 
2147  foreach(lc, options)
2148  {
2149  DefElem *def = (DefElem *) lfirst(lc);
2150 
2151  if (strcmp(def->defname, "column_name") == 0)
2152  {
2153  colname = defGetString(def);
2154  break;
2155  }
2156  }
2157 
2159 
2160  *retrieved_attrs = lappend_int(*retrieved_attrs, i + 1);
2161  }
2162 
2163  /* Don't generate bad syntax for zero-column relation. */
2164  if (first)
2165  appendStringInfoString(buf, "NULL");
2166 
2167  /*
2168  * Construct FROM clause
2169  */
2170  appendStringInfoString(buf, " FROM ");
2171  deparseRelation(buf, rel);
2172 }
#define NIL
Definition: pg_list.h:65
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10994
#define RelationGetDescr(relation)
Definition: rel.h:483
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
unsigned int Oid
Definition: postgres_ext.h:31
List * GetForeignColumnOptions(Oid relid, AttrNumber attnum)
Definition: foreign.c:286
NameData attname
Definition: pg_attribute.h:41
char * defGetString(DefElem *def)
Definition: define.c:49
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
List * lappend_int(List *list, int datum)
Definition: list.c:354
static char ** options
static void deparseRelation(StringInfo buf, Relation rel)
Definition: deparse.c:2309
#define lfirst(lc)
Definition: pg_list.h:169
int i
#define NameStr(name)
Definition: c.h:681
char * defname
Definition: parsenodes.h:733
Definition: pg_list.h:50
#define RelationGetRelid(relation)
Definition: rel.h:457

◆ deparseDeleteSql()

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

Definition at line 1963 of file deparse.c.

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

Referenced by postgresPlanForeignModify().

1967 {
1968  appendStringInfoString(buf, "DELETE FROM ");
1969  deparseRelation(buf, rel);
1970  appendStringInfoString(buf, " WHERE ctid = $1");
1971 
1972  deparseReturningList(buf, rte, rtindex, rel,
1973  rel->trigdesc && rel->trigdesc->trig_delete_after_row,
1974  NIL, returningList, retrieved_attrs);
1975 }
#define NIL
Definition: pg_list.h:65
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:2043
TriggerDesc * trigdesc
Definition: rel.h:116
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
bool trig_delete_after_row
Definition: reltrigger.h:67
static void deparseRelation(StringInfo buf, Relation rel)
Definition: deparse.c:2309

◆ 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 1992 of file deparse.c.

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

Referenced by postgresPlanDirectModify().

1999 {
2000  deparse_expr_cxt context;
2001 
2002  /* Set up context struct for recursion */
2003  context.root = root;
2004  context.foreignrel = foreignrel;
2005  context.scanrel = foreignrel;
2006  context.buf = buf;
2007  context.params_list = params_list;
2008 
2009  appendStringInfoString(buf, "DELETE FROM ");
2010  deparseRelation(buf, rel);
2011  if (foreignrel->reloptkind == RELOPT_JOINREL)
2012  appendStringInfo(buf, " %s%d", REL_ALIAS_PREFIX, rtindex);
2013 
2014  if (foreignrel->reloptkind == RELOPT_JOINREL)
2015  {
2016  List *ignore_conds = NIL;
2017 
2018  appendStringInfoString(buf, " USING ");
2019  deparseFromExprForRel(buf, root, foreignrel, true, rtindex,
2020  &ignore_conds, params_list);
2021  remote_conds = list_concat(remote_conds, ignore_conds);
2022  }
2023 
2024  if (remote_conds)
2025  {
2026  appendStringInfoString(buf, " WHERE ");
2027  appendConditions(remote_conds, &context);
2028  }
2029 
2030  if (foreignrel->reloptkind == RELOPT_JOINREL)
2031  deparseExplicitTargetList(returningList, true, retrieved_attrs,
2032  &context);
2033  else
2034  deparseReturningList(buf, planner_rt_fetch(rtindex, root),
2035  rtindex, rel, false,
2036  NIL, returningList, retrieved_attrs);
2037 }
#define NIL
Definition: pg_list.h:65
RelOptKind reloptkind
Definition: pathnodes.h:667
List ** params_list
Definition: deparse.c:102
List * list_concat(List *list1, const List *list2)
Definition: list.c:530
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:2043
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
#define planner_rt_fetch(rti, root)
Definition: pathnodes.h:377
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
static char * buf
Definition: pg_test_fsync.c:68
#define REL_ALIAS_PREFIX
Definition: deparse.c:105
static void deparseExplicitTargetList(List *tlist, bool is_returning, List **retrieved_attrs, deparse_expr_cxt *context)
Definition: deparse.c:1411
static void appendConditions(List *exprs, deparse_expr_cxt *context)
Definition: deparse.c:1340
StringInfo buf
Definition: deparse.c:101
static void deparseRelation(StringInfo buf, Relation rel)
Definition: deparse.c:2309
PlannerInfo * root
Definition: deparse.c:96
static void deparseFromExprForRel(StringInfo buf, PlannerInfo *root, RelOptInfo *foreignrel, bool use_alias, Index ignore_rel, List **ignore_conds, List **params_list)
Definition: deparse.c:1488
RelOptInfo * scanrel
Definition: deparse.c:98
Definition: pg_list.h:50
RelOptInfo * foreignrel
Definition: deparse.c:97

◆ 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 1878 of file deparse.c.

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

Referenced by postgresPlanDirectModify().

1887 {
1888  deparse_expr_cxt context;
1889  int nestlevel;
1890  bool first;
1891  ListCell *lc;
1892  RangeTblEntry *rte = planner_rt_fetch(rtindex, root);
1893 
1894  /* Set up context struct for recursion */
1895  context.root = root;
1896  context.foreignrel = foreignrel;
1897  context.scanrel = foreignrel;
1898  context.buf = buf;
1899  context.params_list = params_list;
1900 
1901  appendStringInfoString(buf, "UPDATE ");
1902  deparseRelation(buf, rel);
1903  if (foreignrel->reloptkind == RELOPT_JOINREL)
1904  appendStringInfo(buf, " %s%d", REL_ALIAS_PREFIX, rtindex);
1905  appendStringInfoString(buf, " SET ");
1906 
1907  /* Make sure any constants in the exprs are printed portably */
1908  nestlevel = set_transmission_modes();
1909 
1910  first = true;
1911  foreach(lc, targetAttrs)
1912  {
1913  int attnum = lfirst_int(lc);
1914  TargetEntry *tle = get_tle_by_resno(targetlist, attnum);
1915 
1916  if (!tle)
1917  elog(ERROR, "attribute number %d not found in UPDATE targetlist",
1918  attnum);
1919 
1920  if (!first)
1921  appendStringInfoString(buf, ", ");
1922  first = false;
1923 
1924  deparseColumnRef(buf, rtindex, attnum, rte, false);
1925  appendStringInfoString(buf, " = ");
1926  deparseExpr((Expr *) tle->expr, &context);
1927  }
1928 
1929  reset_transmission_modes(nestlevel);
1930 
1931  if (foreignrel->reloptkind == RELOPT_JOINREL)
1932  {
1933  List *ignore_conds = NIL;
1934 
1935  appendStringInfoString(buf, " FROM ");
1936  deparseFromExprForRel(buf, root, foreignrel, true, rtindex,
1937  &ignore_conds, params_list);
1938  remote_conds = list_concat(remote_conds, ignore_conds);
1939  }
1940 
1941  if (remote_conds)
1942  {
1943  appendStringInfoString(buf, " WHERE ");
1944  appendConditions(remote_conds, &context);
1945  }
1946 
1947  if (foreignrel->reloptkind == RELOPT_JOINREL)
1948  deparseExplicitTargetList(returningList, true, retrieved_attrs,
1949  &context);
1950  else
1951  deparseReturningList(buf, rte, rtindex, rel, false,
1952  NIL, returningList, retrieved_attrs);
1953 }
#define NIL
Definition: pg_list.h:65
RelOptKind reloptkind
Definition: pathnodes.h:667
List ** params_list
Definition: deparse.c:102
int set_transmission_modes(void)
List * list_concat(List *list1, const List *list2)
Definition: list.c:530
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:2043
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
#define ERROR
Definition: elog.h:45
#define lfirst_int(lc)
Definition: pg_list.h:170
#define planner_rt_fetch(rti, root)
Definition: pathnodes.h:377
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
static char * buf
Definition: pg_test_fsync.c:68
#define REL_ALIAS_PREFIX
Definition: deparse.c:105
static void deparseExplicitTargetList(List *tlist, bool is_returning, List **retrieved_attrs, deparse_expr_cxt *context)
Definition: deparse.c:1411
static void appendConditions(List *exprs, deparse_expr_cxt *context)
Definition: deparse.c:1340
StringInfo buf
Definition: deparse.c:101
int16 attnum
Definition: pg_attribute.h:83
static void deparseRelation(StringInfo buf, Relation rel)
Definition: deparse.c:2309
PlannerInfo * root
Definition: deparse.c:96
Expr * expr
Definition: primnodes.h:1431
void reset_transmission_modes(int nestlevel)
static void deparseExpr(Expr *expr, deparse_expr_cxt *context)
Definition: deparse.c:2384
static void deparseFromExprForRel(StringInfo buf, PlannerInfo *root, RelOptInfo *foreignrel, bool use_alias, Index ignore_rel, List **ignore_conds, List **params_list)
Definition: deparse.c:1488
#define elog(elevel,...)
Definition: elog.h:227
TargetEntry * get_tle_by_resno(List *tlist, AttrNumber resno)
RelOptInfo * scanrel
Definition: deparse.c:98
Definition: pg_list.h:50
RelOptInfo * foreignrel
Definition: deparse.c:97
static void deparseColumnRef(StringInfo buf, int varno, int varattno, RangeTblEntry *rte, bool qualify_col)
Definition: deparse.c:2181

◆ 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 1713 of file deparse.c.

References appendStringInfo(), appendStringInfoChar(), appendStringInfoString(), attnum, deparseColumnRef(), deparseRelation(), deparseReturningList(), StringInfoData::len, lfirst_int, TriggerDesc::trig_insert_after_row, and RelationData::trigdesc.

Referenced by postgresBeginForeignInsert(), and postgresPlanForeignModify().

1718 {
1719  AttrNumber pindex;
1720  bool first;
1721  ListCell *lc;
1722 
1723  appendStringInfoString(buf, "INSERT INTO ");
1724  deparseRelation(buf, rel);
1725 
1726  if (targetAttrs)
1727  {
1728  appendStringInfoChar(buf, '(');
1729 
1730  first = true;
1731  foreach(lc, targetAttrs)
1732  {
1733  int attnum = lfirst_int(lc);
1734 
1735  if (!first)
1736  appendStringInfoString(buf, ", ");
1737  first = false;
1738 
1739  deparseColumnRef(buf, rtindex, attnum, rte, false);
1740  }
1741 
1742  appendStringInfoString(buf, ") VALUES (");
1743 
1744  pindex = 1;
1745  first = true;
1746  foreach(lc, targetAttrs)
1747  {
1748  if (!first)
1749  appendStringInfoString(buf, ", ");
1750  first = false;
1751 
1752  appendStringInfo(buf, "$%d", pindex);
1753  pindex++;
1754  }
1755 
1756  appendStringInfoChar(buf, ')');
1757  }
1758  else
1759  appendStringInfoString(buf, " DEFAULT VALUES");
1760  *values_end_len = buf->len;
1761 
1762  if (doNothing)
1763  appendStringInfoString(buf, " ON CONFLICT DO NOTHING");
1764 
1765  deparseReturningList(buf, rte, rtindex, rel,
1766  rel->trigdesc && rel->trigdesc->trig_insert_after_row,
1767  withCheckOptionList, returningList, retrieved_attrs);
1768 }
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:2043
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
#define lfirst_int(lc)
Definition: pg_list.h:170
TriggerDesc * trigdesc
Definition: rel.h:116
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
bool trig_insert_after_row
Definition: reltrigger.h:57
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:188
int16 attnum
Definition: pg_attribute.h:83
static void deparseRelation(StringInfo buf, Relation rel)
Definition: deparse.c:2309
int16 AttrNumber
Definition: attnum.h:21
static void deparseColumnRef(StringInfo buf, int varno, int varattno, RangeTblEntry *rte, bool qualify_col)
Definition: deparse.c:2181

◆ 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 1000 of file deparse.c.

References appendConditions(), appendGroupByClause(), appendLimitClause(), appendOrderByClause(), appendStringInfoString(), Assert, buf, deparse_expr_cxt::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, foreign_glob_cxt::root, deparse_expr_cxt::root, and deparse_expr_cxt::scanrel.

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

1004 {
1005  deparse_expr_cxt context;
1006  PgFdwRelationInfo *fpinfo = (PgFdwRelationInfo *) rel->fdw_private;
1007  List *quals;
1008 
1009  /*
1010  * We handle relations for foreign tables, joins between those and upper
1011  * relations.
1012  */
1013  Assert(IS_JOIN_REL(rel) || IS_SIMPLE_REL(rel) || IS_UPPER_REL(rel));
1014 
1015  /* Fill portions of context common to upper, join and base relation */
1016  context.buf = buf;
1017  context.root = root;
1018  context.foreignrel = rel;
1019  context.scanrel = IS_UPPER_REL(rel) ? fpinfo->outerrel : rel;
1020  context.params_list = params_list;
1021 
1022  /* Construct SELECT clause */
1023  deparseSelectSql(tlist, is_subquery, retrieved_attrs, &context);
1024 
1025  /*
1026  * For upper relations, the WHERE clause is built from the remote
1027  * conditions of the underlying scan relation; otherwise, we can use the
1028  * supplied list of remote conditions directly.
1029  */
1030  if (IS_UPPER_REL(rel))
1031  {
1032  PgFdwRelationInfo *ofpinfo;
1033 
1034  ofpinfo = (PgFdwRelationInfo *) fpinfo->outerrel->fdw_private;
1035  quals = ofpinfo->remote_conds;
1036  }
1037  else
1038  quals = remote_conds;
1039 
1040  /* Construct FROM and WHERE clauses */
1041  deparseFromExpr(quals, &context);
1042 
1043  if (IS_UPPER_REL(rel))
1044  {
1045  /* Append GROUP BY clause */
1046  appendGroupByClause(tlist, &context);
1047 
1048  /* Append HAVING clause */
1049  if (remote_conds)
1050  {
1051  appendStringInfoString(buf, " HAVING ");
1052  appendConditions(remote_conds, &context);
1053  }
1054  }
1055 
1056  /* Add ORDER BY clause if we found any useful pathkeys */
1057  if (pathkeys)
1058  appendOrderByClause(pathkeys, has_final_sort, &context);
1059 
1060  /* Add LIMIT clause if necessary */
1061  if (has_limit)
1062  appendLimitClause(&context);
1063 
1064  /* Add any necessary FOR UPDATE/SHARE. */
1065  deparseLockingClause(&context);
1066 }
static void appendGroupByClause(List *tlist, deparse_expr_cxt *context)
Definition: deparse.c:3195
List ** params_list
Definition: deparse.c:102
#define IS_JOIN_REL(rel)
Definition: pathnodes.h:648
static void appendLimitClause(deparse_expr_cxt *context)
Definition: deparse.c:3286
RelOptInfo * outerrel
Definition: postgres_fdw.h:100
#define IS_SIMPLE_REL(rel)
Definition: pathnodes.h:643
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
static char * buf
Definition: pg_test_fsync.c:68
static void appendOrderByClause(List *pathkeys, bool has_final_sort, deparse_expr_cxt *context)
Definition: deparse.c:3232
static void deparseSelectSql(List *tlist, bool is_subquery, List **retrieved_attrs, deparse_expr_cxt *context)
Definition: deparse.c:1082
static void appendConditions(List *exprs, deparse_expr_cxt *context)
Definition: deparse.c:1340
StringInfo buf
Definition: deparse.c:101
void * fdw_private
Definition: pathnodes.h:726
PlannerInfo * root
Definition: deparse.c:96
#define Assert(condition)
Definition: c.h:804
static void deparseFromExpr(List *quals, deparse_expr_cxt *context)
Definition: deparse.c:1140
#define IS_UPPER_REL(rel)
Definition: pathnodes.h:653
static void deparseLockingClause(deparse_expr_cxt *context)
Definition: deparse.c:1250
RelOptInfo * scanrel
Definition: deparse.c:98
Definition: pg_list.h:50
RelOptInfo * foreignrel
Definition: deparse.c:97

◆ deparseStringLiteral()

void deparseStringLiteral ( StringInfo  buf,
const char *  val 
)

Definition at line 2349 of file deparse.c.

References appendStringInfoChar(), ESCAPE_STRING_SYNTAX, and SQL_STR_DOUBLE.

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

2350 {
2351  const char *valptr;
2352 
2353  /*
2354  * Rather than making assumptions about the remote server's value of
2355  * standard_conforming_strings, always use E'foo' syntax if there are any
2356  * backslashes. This will fail on remote servers before 8.1, but those
2357  * are long out of support.
2358  */
2359  if (strchr(val, '\\') != NULL)
2361  appendStringInfoChar(buf, '\'');
2362  for (valptr = val; *valptr; valptr++)
2363  {
2364  char ch = *valptr;
2365 
2366  if (SQL_STR_DOUBLE(ch, true))
2367  appendStringInfoChar(buf, ch);
2368  appendStringInfoChar(buf, ch);
2369  }
2370  appendStringInfoChar(buf, '\'');
2371 }
#define ESCAPE_STRING_SYNTAX
Definition: c.h:1167
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:188
#define SQL_STR_DOUBLE(ch, escape_backslash)
Definition: c.h:1164
long val
Definition: informix.c:664

◆ deparseUpdateSql()

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

Definition at line 1826 of file deparse.c.

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

Referenced by postgresPlanForeignModify().

1831 {
1832  AttrNumber pindex;
1833  bool first;
1834  ListCell *lc;
1835 
1836  appendStringInfoString(buf, "UPDATE ");
1837  deparseRelation(buf, rel);
1838  appendStringInfoString(buf, " SET ");
1839 
1840  pindex = 2; /* ctid is always the first param */
1841  first = true;
1842  foreach(lc, targetAttrs)
1843  {
1844  int attnum = lfirst_int(lc);
1845 
1846  if (!first)
1847  appendStringInfoString(buf, ", ");
1848  first = false;
1849 
1850  deparseColumnRef(buf, rtindex, attnum, rte, false);
1851  appendStringInfo(buf, " = $%d", pindex);
1852  pindex++;
1853  }
1854  appendStringInfoString(buf, " WHERE ctid = $1");
1855 
1856  deparseReturningList(buf, rte, rtindex, rel,
1857  rel->trigdesc && rel->trigdesc->trig_update_after_row,
1858  withCheckOptionList, returningList, retrieved_attrs);
1859 }
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:2043
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
#define lfirst_int(lc)
Definition: pg_list.h:170
TriggerDesc * trigdesc
Definition: rel.h:116
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
bool trig_update_after_row
Definition: reltrigger.h:62
int16 attnum
Definition: pg_attribute.h:83
static void deparseRelation(StringInfo buf, Relation rel)
Definition: deparse.c:2309
int16 AttrNumber
Definition: attnum.h:21
static void deparseColumnRef(StringInfo buf, int varno, int varattno, RangeTblEntry *rte, bool qualify_col)
Definition: deparse.c:2181

◆ ExtractConnectionOptions()

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

Definition at line 347 of file option.c.

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

Referenced by connect_pg_server().

349 {
350  ListCell *lc;
351  int i;
352 
353  /* Build our options lists if we didn't yet. */
355 
356  i = 0;
357  foreach(lc, defelems)
358  {
359  DefElem *d = (DefElem *) lfirst(lc);
360 
361  if (is_libpq_option(d->defname))
362  {
363  keywords[i] = d->defname;
364  values[i] = defGetString(d);
365  i++;
366  }
367  }
368  return i;
369 }
char * defGetString(DefElem *def)
Definition: define.c:49
#define lfirst(lc)
Definition: pg_list.h:169
static Datum values[MAXATTR]
Definition: bootstrap.c:165
int i
static bool is_libpq_option(const char *keyword)
Definition: option.c:326
char * defname
Definition: parsenodes.h:733
static void InitPgFdwOptions(void)
Definition: option.c:192

◆ ExtractExtensionList()

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

Definition at line 378 of file option.c.

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().

379 {
380  List *extensionOids = NIL;
381  List *extlist;
382  ListCell *lc;
383 
384  /* SplitIdentifierString scribbles on its input, so pstrdup first */
385  if (!SplitIdentifierString(pstrdup(extensionsString), ',', &extlist))
386  {
387  /* syntax error in name list */
388  ereport(ERROR,
389  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
390  errmsg("parameter \"%s\" must be a list of extension names",
391  "extensions")));
392  }
393 
394  foreach(lc, extlist)
395  {
396  const char *extension_name = (const char *) lfirst(lc);
397  Oid extension_oid = get_extension_oid(extension_name, true);
398 
399  if (OidIsValid(extension_oid))
400  {
401  extensionOids = lappend_oid(extensionOids, extension_oid);
402  }
403  else if (warnOnMissing)
404  {
406  (errcode(ERRCODE_UNDEFINED_OBJECT),
407  errmsg("extension \"%s\" is not installed",
408  extension_name)));
409  }
410  }
411 
412  list_free(extlist);
413  return extensionOids;
414 }
#define NIL
Definition: pg_list.h:65
char * pstrdup(const char *in)
Definition: mcxt.c:1187
int errcode(int sqlerrcode)
Definition: elog.c:694
unsigned int Oid
Definition: postgres_ext.h:31
List * lappend_oid(List *list, Oid datum)
Definition: list.c:372
#define OidIsValid(objectId)
Definition: c.h:710
#define ERROR
Definition: elog.h:45
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3741
#define WARNING
Definition: elog.h:40
#define ereport(elevel,...)
Definition: elog.h:155
#define lfirst(lc)
Definition: pg_list.h:169
Oid get_extension_oid(const char *extname, bool missing_ok)
Definition: extension.c:140
int errmsg(const char *fmt,...)
Definition: elog.c:905
void list_free(List *list)
Definition: list.c:1391
Definition: pg_list.h:50

◆ find_em_expr_for_input_target()

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

Definition at line 6718 of file postgres_fdw.c.

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().

6721 {
6722  ListCell *lc1;
6723  int i;
6724 
6725  i = 0;
6726  foreach(lc1, target->exprs)
6727  {
6728  Expr *expr = (Expr *) lfirst(lc1);
6729  Index sgref = get_pathtarget_sortgroupref(target, i);
6730  ListCell *lc2;
6731 
6732  /* Ignore non-sort expressions */
6733  if (sgref == 0 ||
6735  root->parse->sortClause) == NULL)
6736  {
6737  i++;
6738  continue;
6739  }
6740 
6741  /* We ignore binary-compatible relabeling on both ends */
6742  while (expr && IsA(expr, RelabelType))
6743  expr = ((RelabelType *) expr)->arg;
6744 
6745  /* Locate an EquivalenceClass member matching this expr, if any */
6746  foreach(lc2, ec->ec_members)
6747  {
6749  Expr *em_expr;
6750 
6751  /* Don't match constants */
6752  if (em->em_is_const)
6753  continue;
6754 
6755  /* Ignore child members */
6756  if (em->em_is_child)
6757  continue;
6758 
6759  /* Match if same expression (after stripping relabel) */
6760  em_expr = em->em_expr;
6761  while (em_expr && IsA(em_expr, RelabelType))
6762  em_expr = ((RelabelType *) em_expr)->arg;
6763 
6764  if (equal(em_expr, expr))
6765  return em->em_expr;
6766  }
6767 
6768  i++;
6769  }
6770 
6771  elog(ERROR, "could not find pathkey item to sort");
6772  return NULL; /* keep compiler quiet */
6773 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:584
Query * parse
Definition: pathnodes.h:173
List * sortClause
Definition: parsenodes.h:158
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:3073
#define ERROR
Definition: elog.h:45
List * exprs
Definition: pathnodes.h:1084
SortGroupClause * get_sortgroupref_clause_noerr(Index sortref, List *clauses)
Definition: tlist.c:460
unsigned int Index
Definition: c.h:549
#define get_pathtarget_sortgroupref(target, colno)
Definition: pathnodes.h:1091
#define lfirst(lc)
Definition: pg_list.h:169
#define elog(elevel,...)
Definition: elog.h:227
int i
void * arg
List * ec_members
Definition: pathnodes.h:974

◆ find_em_expr_for_rel()

Expr* find_em_expr_for_rel ( EquivalenceClass ec,
RelOptInfo rel 
)

Definition at line 777 of file equivclass.c.

Referenced by appendOrderByClause(), and get_useful_pathkeys_for_relation().

778 {
779  ListCell *lc_em;
780 
781  foreach(lc_em, ec->ec_members)
782  {
783  EquivalenceMember *em = lfirst(lc_em);
784 
785  if (bms_is_subset(em->em_relids, rel->relids) &&
786  !bms_is_empty(em->em_relids))
787  {
788  /*
789  * If there is more than one equivalence member whose Vars are
790  * taken entirely from this relation, we'll be content to choose
791  * any one of those.
792  */
793  return em->em_expr;
794  }
795  }
796 
797  /* We didn't find any suitable equivalence class expression */
798  return NULL;
799 }
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:315
Relids relids
Definition: pathnodes.h:670
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:701
#define lfirst(lc)
Definition: pg_list.h:169
List * ec_members
Definition: pathnodes.h:974

◆ get_jointype_name()

const char* get_jointype_name ( JoinType  jointype)

Definition at line 1374 of file deparse.c.

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

Referenced by deparseFromExprForRel(), and foreign_join_ok().

1375 {
1376  switch (jointype)
1377  {
1378  case JOIN_INNER:
1379  return "INNER";
1380 
1381  case JOIN_LEFT:
1382  return "LEFT";
1383 
1384  case JOIN_RIGHT:
1385  return "RIGHT";
1386 
1387  case JOIN_FULL:
1388  return "FULL";
1389 
1390  default:
1391  /* Shouldn't come here, but protect from buggy code. */
1392  elog(ERROR, "unsupported join type %d", jointype);
1393  }
1394 
1395  /* Keep compiler happy */
1396  return NULL;
1397 }
#define ERROR
Definition: elog.h:45
#define elog(elevel,...)
Definition: elog.h:227

◆ GetConnection()

PGconn* GetConnection ( UserMapping user,
bool  will_prep_stmt 
)

Definition at line 120 of file connection.c.

References Assert, begin_remote_xact(), CacheRegisterSyscacheCallback(), ConnCacheEntry::conn, CONNECTION_BAD, 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, ConnCacheEntry::key, HASHCTL::keysize, make_new_connection(), MemoryContextSwitchTo(), pchomp(), 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(), RegisterSubXactCallback(), RegisterXactCallback(), ErrorData::sqlerrcode, UserMapping::umid, USERMAPPINGOID, ConnCacheEntry::xact_depth, and xact_got_connection.

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

121 {
122  bool found;
123  bool retry = false;
124  ConnCacheEntry *entry;
127 
128  /* First time through, initialize connection cache hashtable */
129  if (ConnectionHash == NULL)
130  {
131  HASHCTL ctl;
132 
133  ctl.keysize = sizeof(ConnCacheKey);
134  ctl.entrysize = sizeof(ConnCacheEntry);
135  ConnectionHash = hash_create("postgres_fdw connections", 8,
136  &ctl,
138 
139  /*
140  * Register some callback functions that manage connection cleanup.
141  * This should be done just once in each backend.
142  */
149  }
150 
151  /* Set flag that we did GetConnection during the current transaction */
152  xact_got_connection = true;
153 
154  /* Create hash key for the entry. Assume no pad bytes in key struct */
155  key = user->umid;
156 
157  /*
158  * Find or create cached entry for requested connection.
159  */
160  entry = hash_search(ConnectionHash, &key, HASH_ENTER, &found);
161  if (!found)
162  {
163  /*
164  * We need only clear "conn" here; remaining fields will be filled
165  * later when "conn" is set.
166  */
167  entry->conn = NULL;
168  }
169 
170  /* Reject further use of connections which failed abort cleanup. */
172 
173  /*
174  * If the connection needs to be remade due to invalidation, disconnect as
175  * soon as we're out of all transactions.
176  */
177  if (entry->conn != NULL && entry->invalidated && entry->xact_depth == 0)
178  {
179  elog(DEBUG3, "closing connection %p for option changes to take effect",
180  entry->conn);
181  disconnect_pg_server(entry);
182  }
183 
184  /*
185  * If cache entry doesn't have a connection, we have to establish a new
186  * connection. (If connect_pg_server throws an error, the cache entry
187  * will remain in a valid empty state, ie conn == NULL.)
188  */
189  if (entry->conn == NULL)
190  make_new_connection(entry, user);
191 
192  /*
193  * We check the health of the cached connection here when starting a new
194  * remote transaction. If a broken connection is detected, we try to
195  * reestablish a new connection later.
196  */
197  PG_TRY();
198  {
199  /* Start a new transaction or subtransaction if needed. */
200  begin_remote_xact(entry);
201  }
202  PG_CATCH();
203  {
205  ErrorData *errdata = CopyErrorData();
206 
207  /*
208  * If connection failure is reported when starting a new remote
209  * transaction (not subtransaction), new connection will be
210  * reestablished later.
211  *
212  * After a broken connection is detected in libpq, any error other
213  * than connection failure (e.g., out-of-memory) can be thrown
214  * somewhere between return from libpq and the expected ereport() call
215  * in pgfdw_report_error(). In this case, since PQstatus() indicates
216  * CONNECTION_BAD, checking only PQstatus() causes the false detection
217  * of connection failure. To avoid this, we also verify that the
218  * error's sqlstate is ERRCODE_CONNECTION_FAILURE. Note that also
219  * checking only the sqlstate can cause another false detection
220  * because pgfdw_report_error() may report ERRCODE_CONNECTION_FAILURE
221  * for any libpq-originated error condition.
222  */
223  if (errdata->sqlerrcode != ERRCODE_CONNECTION_FAILURE ||
224  PQstatus(entry->conn) != CONNECTION_BAD ||
225  entry->xact_depth > 0)
226  {
227  MemoryContextSwitchTo(ecxt);
228  PG_RE_THROW();
229  }
230 
231  /* Clean up the error state */
232  FlushErrorState();
233  FreeErrorData(errdata);
234  errdata = NULL;
235 
236  retry = true;
237  }
238  PG_END_TRY();
239 
240  /*
241  * If a broken connection is detected, disconnect it, reestablish a new
242  * connection and retry a new remote transaction. If connection failure is
243  * reported again, we give up getting a connection.
244  */
245  if (retry)
246  {
247  Assert(entry->xact_depth == 0);
248 
249  ereport(DEBUG3,
250  (errmsg_internal("could not start remote transaction on connection %p",
251  entry->conn)),
252  errdetail_internal("%s", pchomp(PQerrorMessage(entry->conn))));
253 
254  elog(DEBUG3, "closing connection %p to reestablish a new one",
255  entry->conn);
256  disconnect_pg_server(entry);
257 
258  if (entry->conn == NULL)
259  make_new_connection(entry, user);
260 
261  begin_remote_xact(entry);
262  }
263 
264  /* Remember if caller will prepare statements */
265  entry->have_prep_stmt |= will_prep_stmt;
266 
267  return entry->conn;
268 }
Oid umid
Definition: foreign.h:47
char * PQerrorMessage(const PGconn *conn)
Definition: fe-connect.c:6705
#define HASH_ELEM
Definition: hsearch.h:95
int sqlerrcode
Definition: elog.h:376
#define DEBUG3
Definition: elog.h:23
struct ConnCacheEntry ConnCacheEntry
ErrorData * CopyErrorData(void)
Definition: elog.c:1533
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
Size entrysize
Definition: hsearch.h:76
bool have_prep_stmt
Definition: connection.c:58
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
void FlushErrorState(void)
Definition: elog.c:1627
int errdetail_internal(const char *fmt,...)
Definition: elog.c:1065
char * pchomp(const char *in)
Definition: mcxt.c:1215
void FreeErrorData(ErrorData *edata)
Definition: elog.c:1589
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:349
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
bool invalidated
Definition: connection.c:61
static void pgfdw_inval_callback(Datum arg, int cacheid, uint32 hashvalue)
Definition: connection.c:1101
#define HASH_BLOBS
Definition: hsearch.h:97
void CacheRegisterSyscacheCallback(int cacheid, SyscacheCallbackFunction func, Datum arg)
Definition: inval.c:1434
static void pgfdw_xact_callback(XactEvent event, void *arg)
Definition: connection.c:795
static HTAB * ConnectionHash
Definition: connection.c:70
uintptr_t Datum
Definition: postgres.h:367
void RegisterSubXactCallback(SubXactCallback callback, void *arg)
Definition: xact.c:3582
Size keysize
Definition: hsearch.h:75
#define ereport(elevel,...)
Definition: elog.h:155
int errmsg_internal(const char *fmt,...)
Definition: elog.c:992
#define PG_CATCH()
Definition: elog.h:318
PGconn * conn
Definition: connection.c:54
static void disconnect_pg_server(ConnCacheEntry *entry)
Definition: connection.c:426
#define Assert(condition)
Definition: c.h:804
void RegisterXactCallback(XactCallback callback, void *arg)
Definition: xact.c:3527
static void pgfdw_reject_incomplete_xact_state_change(ConnCacheEntry *entry)
Definition: connection.c:1151
static bool xact_got_connection
Definition: connection.c:77
#define PG_RE_THROW()
Definition: elog.h:349
static void make_new_connection(ConnCacheEntry *entry, UserMapping *user)
Definition: connection.c:275
#define elog(elevel,...)
Definition: elog.h:227
static void pgfdw_subxact_callback(SubXactEvent event, SubTransactionId mySubid, SubTransactionId parentSubid, void *arg)
Definition: connection.c:984
ConnStatusType PQstatus(const PGconn *conn)
Definition: fe-connect.c:6652
#define PG_TRY()
Definition: elog.h:308
static void begin_remote_xact(ConnCacheEntry *entry)
Definition: connection.c:560
Oid ConnCacheKey
Definition: connection.c:49
#define PG_END_TRY()
Definition: elog.h:333

◆ GetCursorNumber()

unsigned int GetCursorNumber ( PGconn conn)

Definition at line 624 of file connection.c.

References cursor_number.

Referenced by postgresAcquireSampleRowsFunc(), and postgresBeginForeignScan().

625 {
626  return ++cursor_number;
627 }
static unsigned int cursor_number
Definition: connection.c:73

◆ GetPrepStmtNumber()

unsigned int GetPrepStmtNumber ( PGconn conn)

Definition at line 638 of file connection.c.

References prep_stmt_number.

Referenced by prepare_foreign_modify().

639 {
640  return ++prep_stmt_number;
641 }
static unsigned int prep_stmt_number
Definition: connection.c:74

◆ is_builtin()

bool is_builtin ( Oid  objectId)

Definition at line 152 of file shippable.c.

References FirstGenbkiObjectId.

Referenced by deparse_type_name(), and is_shippable().

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

◆ is_foreign_expr()

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

Definition at line 230 of file deparse.c.

References foreign_loc_cxt::collation, contain_mutable_functions(), FDW_COLLATE_NONE, FDW_COLLATE_UNSAFE, RelOptInfo::fdw_private, foreign_expr_walker(), foreign_glob_cxt::foreignrel, 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().

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

◆ is_foreign_param()

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

Definition at line 876 of file deparse.c.

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

Referenced by foreign_grouping_ok().

879 {
880  if (expr == NULL)
881  return false;
882 
883  switch (nodeTag(expr))
884  {
885  case T_Var:
886  {
887  /* It would have to be sent unless it's a foreign Var */
888  Var *var = (Var *) expr;
889  PgFdwRelationInfo *fpinfo = (PgFdwRelationInfo *) (baserel->fdw_private);
890  Relids relids;
891 
892  if (IS_UPPER_REL(baserel))
893  relids = fpinfo->outerrel->relids;
894  else
895  relids = baserel->relids;
896 
897  if (bms_is_member(var->varno, relids) && var->varlevelsup == 0)
898  return false; /* foreign Var, so not a param */
899  else
900  return true; /* it'd have to be a param */
901  break;
902  }
903  case T_Param:
904  /* Params always have to be sent to the foreign server */
905  return true;
906  default:
907  break;
908  }
909  return false;
910 }
Index varlevelsup
Definition: primnodes.h:191
Definition: primnodes.h:181
RelOptInfo * outerrel
Definition: postgres_fdw.h:100
Relids relids
Definition: pathnodes.h:670
Index varno
Definition: primnodes.h:184
Definition: nodes.h:155
void * fdw_private
Definition: pathnodes.h:726
#define IS_UPPER_REL(rel)
Definition: pathnodes.h:653
#define nodeTag(nodeptr)
Definition: nodes.h:538
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:427
Definition: nodes.h:157

◆ is_shippable()

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

Definition at line 162 of file shippable.c.

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

Referenced by foreign_expr_walker().

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 }
#define NIL
Definition: pg_list.h:65
bool is_builtin(Oid objectId)
Definition: shippable.c:152
ForeignServer * server
Definition: postgres_fdw.h:84
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
static void InitializeShippableCache(void)
Definition: shippable.c:91
static bool lookup_shippable(Oid objectId, Oid classId, PgFdwRelationInfo *fpinfo)
Definition: shippable.c:116
static HTAB * ShippableCacheHash
Definition: shippable.c:34
List * shippable_extensions
Definition: postgres_fdw.h:80
Oid serverid
Definition: foreign.h:36

◆ pgfdw_exec_query()

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

Definition at line 651 of file connection.c.

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

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

652 {
653  /*
654  * Submit a query. Since we don't use non-blocking mode, this also can
655  * block. But its risk is relatively small, so we ignore that for now.
656  */
657  if (!PQsendQuery(conn, query))
658  pgfdw_report_error(ERROR, NULL, conn, false, query);
659 
660  /* Wait for the result. */
661  return pgfdw_get_result(conn, query);
662 }
int PQsendQuery(PGconn *conn, const char *query)
Definition: fe-exec.c:1198
#define ERROR
Definition: elog.h:45
void pgfdw_report_error(int elevel, PGresult *res, PGconn *conn, bool clear, const char *sql)
Definition: connection.c:740
PGresult * pgfdw_get_result(PGconn *conn, const char *query)
Definition: connection.c:675

◆ pgfdw_get_result()

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

Definition at line 675 of file connection.c.

References CHECK_FOR_INTERRUPTS, ERROR, MyLatch, PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, PG_WAIT_EXTENSION, pgfdw_report_error(), PQclear(), PQconsumeInput(), PQgetResult(), PQisBusy(), PQsocket(), 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(), pgfdw_exec_query(), and prepare_foreign_modify().

676 {
677  PGresult *volatile last_res = NULL;
678 
679  /* In what follows, do not leak any PGresults on an error. */
680  PG_TRY();
681  {
682  for (;;)
683  {
684  PGresult *res;
685 
686  while (PQisBusy(conn))
687  {
688  int wc;
689 
690  /* Sleep until there's something to do */
694  PQsocket(conn),
695  -1L, PG_WAIT_EXTENSION);
697 
699 
700  /* Data available in socket? */
701  if (wc & WL_SOCKET_READABLE)
702  {
703  if (!PQconsumeInput(conn))
704  pgfdw_report_error(ERROR, NULL, conn, false, query);
705  }
706  }
707 
708  res = PQgetResult(conn);
709  if (res == NULL)
710  break; /* query is complete */
711 
712  PQclear(last_res);
713  last_res = res;
714  }
715  }
716  PG_CATCH();
717  {
718  PQclear(last_res);
719  PG_RE_THROW();
720  }
721  PG_END_TRY();
722 
723  return last_res;
724 }
#define WL_SOCKET_READABLE
Definition: latch.h:126
void ResetLatch(Latch *latch)
Definition: latch.c:660
#define ERROR
Definition: elog.h:45
int WaitLatchOrSocket(Latch *latch, int wakeEvents, pgsocket sock, long timeout, uint32 wait_event_info)
Definition: latch.c:500
void pgfdw_report_error(int elevel, PGresult *res, PGconn *conn, bool clear, const char *sql)
Definition: connection.c:740
#define PG_WAIT_EXTENSION
Definition: pgstat.h:900
int PQconsumeInput(PGconn *conn)
Definition: fe-exec.c:1667
void PQclear(PGresult *res)
Definition: fe-exec.c:676
#define PG_CATCH()
Definition: elog.h:318
int PQisBusy(PGconn *conn)
Definition: fe-exec.c:1714
#define PG_RE_THROW()
Definition: elog.h:349
struct Latch * MyLatch
Definition: globals.c:55
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:100
#define PG_TRY()
Definition: elog.h:308
#define WL_LATCH_SET
Definition: latch.h:125
int PQsocket(const PGconn *conn)
Definition: fe-connect.c:6723
PGresult * PQgetResult(PGconn *conn)
Definition: fe-exec.c:1738
#define PG_END_TRY()
Definition: elog.h:333
#define WL_EXIT_ON_PM_DEATH
Definition: latch.h:130

◆ pgfdw_report_error()

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

Definition at line 740 of file connection.c.

References 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(), and PQresultErrorField().

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

742 {
743  /* If requested, PGresult must be released before leaving this function. */
744  PG_TRY();
745  {
746  char *diag_sqlstate = PQresultErrorField(res, PG_DIAG_SQLSTATE);
747  char *message_primary = PQresultErrorField(res, PG_DIAG_MESSAGE_PRIMARY);
748  char *message_detail = PQresultErrorField(res, PG_DIAG_MESSAGE_DETAIL);
749  char *message_hint = PQresultErrorField(res, PG_DIAG_MESSAGE_HINT);
750  char *message_context = PQresultErrorField(res, PG_DIAG_CONTEXT);
751  int sqlstate;
752 
753  if (diag_sqlstate)
754  sqlstate = MAKE_SQLSTATE(diag_sqlstate[0],
755  diag_sqlstate[1],
756  diag_sqlstate[2],
757  diag_sqlstate[3],
758  diag_sqlstate[4]);
759  else
760  sqlstate = ERRCODE_CONNECTION_FAILURE;
761 
762  /*
763  * If we don't get a message from the PGresult, try the PGconn. This
764  * is needed because for connection-level failures, PQexec may just
765  * return NULL, not a PGresult at all.
766  */
767  if (message_primary == NULL)
768  message_primary = pchomp(PQerrorMessage(conn));
769 
770  ereport(elevel,
771  (errcode(sqlstate),
772  message_primary ? errmsg_internal("%s", message_primary) :
773  errmsg("could not obtain message string for remote error"),
774  message_detail ? errdetail_internal("%s", message_detail) : 0,
775  message_hint ? errhint("%s", message_hint) : 0,
776  message_context ? errcontext("%s", message_context) : 0,
777  sql ? errcontext("remote SQL command: %s", sql) : 0));
778  }
779  PG_FINALLY();
780  {
781  if (clear)
782  PQclear(res);
783  }
784  PG_END_TRY();
785 }
char * PQerrorMessage(const PGconn *conn)
Definition: fe-connect.c:6705
int errhint(const char *fmt,...)
Definition: elog.c:1152
#define PG_DIAG_MESSAGE_PRIMARY
Definition: postgres_ext.h:58
#define PG_DIAG_MESSAGE_DETAIL
Definition: postgres_ext.h:59
#define MAKE_SQLSTATE(ch1, ch2, ch3, ch4, ch5)
Definition: elog.h:62
int errcode(int sqlerrcode)
Definition: elog.c:694
#define PG_DIAG_SQLSTATE
Definition: postgres_ext.h:57
int errdetail_internal(const char *fmt,...)
Definition: elog.c:1065
char * pchomp(const char *in)
Definition: mcxt.c:1215
static int elevel
Definition: vacuumlazy.c:333
#define PG_FINALLY()
Definition: elog.h:325
#define PG_DIAG_MESSAGE_HINT
Definition: postgres_ext.h:60
#define ereport(elevel,...)
Definition: elog.h:155
void PQclear(PGresult *res)
Definition: fe-exec.c:676
int errmsg_internal(const char *fmt,...)
Definition: elog.c:992
char * PQresultErrorField(const PGresult *res, int fieldcode)
Definition: fe-exec.c:2617
int errmsg(const char *fmt,...)
Definition: elog.c:905
#define errcontext
Definition: elog.h:199
#define PG_TRY()
Definition: elog.h:308
#define PG_END_TRY()
Definition: elog.h:333
#define PG_DIAG_CONTEXT
Definition: postgres_ext.h:64

◆ rebuildInsertSql()

void rebuildInsertSql ( StringInfo  buf,
char *  orig_query,
int  values_end_len,
int  num_cols,
int  num_rows 
)

Definition at line 1777 of file deparse.c.

References appendBinaryStringInfo(), appendStringInfo(), appendStringInfoChar(), appendStringInfoString(), Assert, and i.

Referenced by execute_foreign_modify().

1780 {
1781  int i, j;
1782  int pindex;
1783  bool first;
1784 
1785  /* Make sure the values_end_len is sensible */
1786  Assert((values_end_len > 0) && (values_end_len <= strlen(orig_query)));
1787 
1788  /* Copy up to the end of the first record from the original query */
1789  appendBinaryStringInfo(buf, orig_query, values_end_len);
1790 
1791  /*
1792  * Add records to VALUES clause (we already have parameters for the
1793  * first row, so start at the right offset).
1794  */
1795  pindex = num_cols + 1;
1796  for (i = 0; i < num_rows; i++)
1797  {
1798  appendStringInfoString(buf, ", (");
1799 
1800  first = true;
1801  for (j = 0; j < num_cols; j++)
1802  {
1803  if (!first)
1804  appendStringInfoString(buf, ", ");
1805  first = false;
1806 
1807  appendStringInfo(buf, "$%d", pindex);
1808  pindex++;
1809  }
1810 
1811  appendStringInfoChar(buf, ')');
1812  }
1813 
1814  /* Copy stuff after VALUES clause from the original query */
1815  appendStringInfoString(buf, orig_query + values_end_len);
1816 }
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:188
#define Assert(condition)
Definition: c.h:804
int i
void appendBinaryStringInfo(StringInfo str, const char *data, int datalen)
Definition: stringinfo.c:227

◆ ReleaseConnection()

void ReleaseConnection ( PGconn conn)

Definition at line 603 of file connection.c.

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

604 {
605  /*
606  * Currently, we don't actually track connection references because all
607  * cleanup is managed on a transaction or subtransaction basis instead. So
608  * there's nothing to do here.
609  */
610 }

◆ reset_transmission_modes()

void reset_transmission_modes ( int  nestlevel)

Definition at line 3627 of file postgres_fdw.c.

References AtEOXact_GUC().

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

3628 {
3629  AtEOXact_GUC(true, nestlevel);
3630 }
void AtEOXact_GUC(bool isCommit, int nestLevel)
Definition: guc.c:6019

◆ set_transmission_modes()

int set_transmission_modes ( void  )

Definition at line 3599 of file postgres_fdw.c.

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().

3600 {
3601  int nestlevel = NewGUCNestLevel();
3602 
3603  /*
3604  * The values set here should match what pg_dump does. See also
3605  * configure_remote_session in connection.c.
3606  */
3607  if (DateStyle != USE_ISO_DATES)
3608  (void) set_config_option("datestyle", "ISO",
3610  GUC_ACTION_SAVE, true, 0, false);
3612  (void) set_config_option("intervalstyle", "postgres",
3614  GUC_ACTION_SAVE, true, 0, false);
3615  if (extra_float_digits < 3)
3616  (void) set_config_option("extra_float_digits", "3",
3618  GUC_ACTION_SAVE, true, 0, false);
3619 
3620  return nestlevel;
3621 }
int IntervalStyle
Definition: globals.c:118
#define USE_ISO_DATES
Definition: miscadmin.h:215
int extra_float_digits
Definition: float.c:42
int DateStyle
Definition: globals.c:116
int NewGUCNestLevel(void)
Definition: guc.c:6005
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:7092
#define INTSTYLE_POSTGRES
Definition: miscadmin.h:235