PostgreSQL Source Code git master
Data Structures | Typedefs | Enumerations | Functions | Variables
postgres_fdw.h File Reference
#include "foreign/foreign.h"
#include "lib/stringinfo.h"
#include "libpq/libpq-be-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 PgFdwConnState  PgFdwConnState
 
 

Enumerations

 

Functions

 
void  reset_transmission_modes (int nestlevel)
 
 
PGconnGetConnection (UserMapping *user, bool will_prep_stmt, PgFdwConnState **state)
 
 
unsigned int  GetCursorNumber (PGconn *conn)
 
unsigned int  GetPrepStmtNumber (PGconn *conn)
 
void  do_sql_command (PGconn *conn, const char *sql)
 
 
 
pg_noreturn void  pgfdw_report_error (PGresult *res, PGconn *conn, const char *sql)
 
void  pgfdw_report (int elevel, PGresult *res, PGconn *conn, 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)
 
bool  is_foreign_pathkey (PlannerInfo *root, RelOptInfo *baserel, PathKey *pathkey)
 
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  deparseAnalyzeSql (StringInfo buf, Relation rel, PgFdwSamplingMethod sample_method, double sample_frac, List **retrieved_attrs)
 
void  deparseTruncateSql (StringInfo buf, List *rels, DropBehavior behavior, bool restart_seqs)
 
void  deparseStringLiteral (StringInfo buf, const char *val)
 
 
 
 
void  deparseSelectStmtForRel (StringInfo buf, PlannerInfo *root, RelOptInfo *rel, 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

 

Typedef Documentation

PgFdwConnState

PgFdwRelationInfo

PgFdwSamplingMethod

Enumeration Type Documentation

PgFdwSamplingMethod

Enumerator
ANALYZE_SAMPLE_OFF 
ANALYZE_SAMPLE_AUTO 
ANALYZE_SAMPLE_RANDOM 
ANALYZE_SAMPLE_SYSTEM 
ANALYZE_SAMPLE_BERNOULLI 

Definition at line 145 of file postgres_fdw.h.

146{
147 ANALYZE_SAMPLE_OFF, /* no remote sampling */
148 ANALYZE_SAMPLE_AUTO, /* choose by server version */
149 ANALYZE_SAMPLE_RANDOM, /* remote random() */
150 ANALYZE_SAMPLE_SYSTEM, /* TABLESAMPLE system */
151 ANALYZE_SAMPLE_BERNOULLI, /* TABLESAMPLE bernoulli */
PgFdwSamplingMethod
Definition: postgres_fdw.h:146
@ ANALYZE_SAMPLE_AUTO
Definition: postgres_fdw.h:148
@ ANALYZE_SAMPLE_OFF
Definition: postgres_fdw.h:147
@ ANALYZE_SAMPLE_BERNOULLI
Definition: postgres_fdw.h:151
@ ANALYZE_SAMPLE_SYSTEM
Definition: postgres_fdw.h:150
@ ANALYZE_SAMPLE_RANDOM
Definition: postgres_fdw.h:149

Function Documentation

build_tlist_to_deparse()

List * build_tlist_to_deparse ( RelOptInfoforeignrel )

Definition at line 1209 of file deparse.c.

1210{
1211 List *tlist = NIL;
1212 PgFdwRelationInfo *fpinfo = (PgFdwRelationInfo *) foreignrel->fdw_private;
1213 ListCell *lc;
1214
1215 /*
1216 * For an upper relation, we have already built the target list while
1217 * checking shippability, so just return that.
1218 */
1219 if (IS_UPPER_REL(foreignrel))
1220 return fpinfo->grouped_tlist;
1221
1222 /*
1223 * We require columns specified in foreignrel->reltarget->exprs and those
1224 * required for evaluating the local conditions.
1225 */
1226 tlist = add_to_flat_tlist(tlist,
1227 pull_var_clause((Node *) foreignrel->reltarget->exprs,
1229 foreach(lc, fpinfo->local_conds)
1230 {
1232
1233 tlist = add_to_flat_tlist(tlist,
1234 pull_var_clause((Node *) rinfo->clause,
1236 }
1237
1238 return tlist;
1239}
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:81
#define PVC_RECURSE_PLACEHOLDERS
Definition: optimizer.h:191
#define IS_UPPER_REL(rel)
Definition: pathnodes.h:908
#define lfirst_node(type, lc)
Definition: pg_list.h:176
#define NIL
Definition: pg_list.h:68
Definition: pg_list.h:54
Definition: nodes.h:135
List * exprs
Definition: pathnodes.h:1782
List * grouped_tlist
Definition: postgres_fdw.h:113
List * local_conds
Definition: postgres_fdw.h:44
struct PathTarget * reltarget
Definition: pathnodes.h:952
Expr * clause
Definition: pathnodes.h:2795
List * add_to_flat_tlist(List *tlist, List *exprs)
Definition: tlist.c:132
Definition: pg_list.h:46
List * pull_var_clause(Node *node, int flags)
Definition: var.c:653

References add_to_flat_tlist(), RestrictInfo::clause, PathTarget::exprs, 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 ( PlannerInforoot,
RelOptInfobaserel,
Listinput_conds,
List **  remote_conds,
List **  local_conds 
)

Definition at line 218 of file deparse.c.

223{
224 ListCell *lc;
225
226 *remote_conds = NIL;
227 *local_conds = NIL;
228
229 foreach(lc, input_conds)
230 {
232
233 if (is_foreign_expr(root, baserel, ri->clause))
234 *remote_conds = lappend(*remote_conds, ri);
235 else
236 *local_conds = lappend(*local_conds, ri);
237 }
238}
bool is_foreign_expr(PlannerInfo *root, RelOptInfo *baserel, Expr *expr)
Definition: deparse.c:244
List * lappend(List *list, void *datum)
Definition: list.c:339
tree ctl root
Definition: radixtree.h:1857

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

Referenced by estimate_path_cost_size(), and postgresGetForeignRelSize().

deparseAnalyzeInfoSql()

void deparseAnalyzeInfoSql ( StringInfo  buf,
Relation  rel 
)

Definition at line 2554 of file deparse.c.

2555{
2557
2558 /* We'll need the remote relation name as a literal. */
2560 deparseRelation(&relname, rel);
2561
2562 appendStringInfoString(buf, "SELECT reltuples, relkind FROM pg_catalog.pg_class WHERE oid = ");
2564 appendStringInfoString(buf, "::pg_catalog.regclass");
2565}
void deparseStringLiteral(StringInfo buf, const char *val)
Definition: deparse.c:2882
static void deparseRelation(StringInfo buf, Relation rel)
Definition: deparse.c:2842
NameData relname
Definition: pg_class.h:38
static char * buf
Definition: pg_test_fsync.c:72
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:230
void initStringInfo(StringInfo str)
Definition: stringinfo.c:97
char data[NAMEDATALEN]
Definition: c.h:747

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

Referenced by postgresGetAnalyzeInfoForForeignTable().

deparseAnalyzeSizeSql()

void deparseAnalyzeSizeSql ( StringInfo  buf,
Relation  rel 
)

Definition at line 2532 of file deparse.c.

2533{
2535
2536 /* We'll need the remote relation name as a literal. */
2538 deparseRelation(&relname, rel);
2539
2540 appendStringInfoString(buf, "SELECT pg_catalog.pg_relation_size(");
2542 appendStringInfo(buf, "::pg_catalog.regclass) / %d", BLCKSZ);
2543}
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:145

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

Referenced by postgresAnalyzeForeignTable().

deparseAnalyzeSql()

void deparseAnalyzeSql ( StringInfo  buf,
Relation  rel,
PgFdwSamplingMethod  sample_method,
double  sample_frac,
List **  retrieved_attrs 
)

Definition at line 2594 of file deparse.c.

2597{
2598 Oid relid = RelationGetRelid(rel);
2599 TupleDesc tupdesc = RelationGetDescr(rel);
2600 int i;
2601 char *colname;
2602 List *options;
2603 ListCell *lc;
2604 bool first = true;
2605
2606 *retrieved_attrs = NIL;
2607
2608 appendStringInfoString(buf, "SELECT ");
2609 for (i = 0; i < tupdesc->natts; i++)
2610 {
2611 /* Ignore dropped columns. */
2612 if (TupleDescAttr(tupdesc, i)->attisdropped)
2613 continue;
2614
2615 if (!first)
2617 first = false;
2618
2619 /* Use attribute name or column_name option. */
2620 colname = NameStr(TupleDescAttr(tupdesc, i)->attname);
2621 options = GetForeignColumnOptions(relid, i + 1);
2622
2623 foreach(lc, options)
2624 {
2625 DefElem *def = (DefElem *) lfirst(lc);
2626
2627 if (strcmp(def->defname, "column_name") == 0)
2628 {
2629 colname = defGetString(def);
2630 break;
2631 }
2632 }
2633
2635
2636 *retrieved_attrs = lappend_int(*retrieved_attrs, i + 1);
2637 }
2638
2639 /* Don't generate bad syntax for zero-column relation. */
2640 if (first)
2641 appendStringInfoString(buf, "NULL");
2642
2643 /*
2644 * Construct FROM clause, and perhaps WHERE clause too, depending on the
2645 * selected sampling method.
2646 */
2647 appendStringInfoString(buf, " FROM ");
2648 deparseRelation(buf, rel);
2649
2650 switch (sample_method)
2651 {
2652 case ANALYZE_SAMPLE_OFF:
2653 /* nothing to do here */
2654 break;
2655
2657 appendStringInfo(buf, " WHERE pg_catalog.random() < %f", sample_frac);
2658 break;
2659
2661 appendStringInfo(buf, " TABLESAMPLE SYSTEM(%f)", (100.0 * sample_frac));
2662 break;
2663
2665 appendStringInfo(buf, " TABLESAMPLE BERNOULLI(%f)", (100.0 * sample_frac));
2666 break;
2667
2669 /* should have been resolved into actual method */
2670 elog(ERROR, "unexpected sampling method");
2671 break;
2672 }
2673}
#define NameStr(name)
Definition: c.h:751
char * defGetString(DefElem *def)
Definition: define.c:35
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:226
List * GetForeignColumnOptions(Oid relid, AttrNumber attnum)
Definition: foreign.c:293
i
int i
Definition: isn.c:77
List * lappend_int(List *list, int datum)
Definition: list.c:357
NameData attname
Definition: pg_attribute.h:41
#define lfirst(lc)
Definition: pg_list.h:172
static char ** options
Definition: pg_recvlogical.c:59
unsigned int Oid
Definition: postgres_ext.h:32
#define RelationGetRelid(relation)
Definition: rel.h:514
#define RelationGetDescr(relation)
Definition: rel.h:540
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:13058
char * defname
Definition: parsenodes.h:843
int natts
Definition: tupdesc.h:137
Definition: oid2name.c:30
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
Definition: tupdesc.h:160

References ANALYZE_SAMPLE_AUTO, ANALYZE_SAMPLE_BERNOULLI, ANALYZE_SAMPLE_OFF, ANALYZE_SAMPLE_RANDOM, ANALYZE_SAMPLE_SYSTEM, appendStringInfo(), appendStringInfoString(), attname, buf, defGetString(), DefElem::defname, deparseRelation(), elog, ERROR, GetForeignColumnOptions(), i, lappend_int(), lfirst, NameStr, TupleDescData::natts, NIL, options, quote_identifier(), RelationGetDescr, RelationGetRelid, and TupleDescAttr().

Referenced by postgresAcquireSampleRowsFunc().

deparseDeleteSql()

void deparseDeleteSql ( StringInfo  buf,
RangeTblEntryrte,
Index  rtindex,
Relation  rel,
ListreturningList,
List **  retrieved_attrs 
)

Definition at line 2395 of file deparse.c.

2399{
2400 appendStringInfoString(buf, "DELETE FROM ");
2401 deparseRelation(buf, rel);
2402 appendStringInfoString(buf, " WHERE ctid = 1ドル");
2403
2404 deparseReturningList(buf, rte, rtindex, rel,
2406 NIL, returningList, retrieved_attrs);
2407}
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:2475
TriggerDesc * trigdesc
Definition: rel.h:117
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,
PlannerInforoot,
Index  rtindex,
Relation  rel,
RelOptInfoforeignrel,
Listremote_conds,
List **  params_list,
ListreturningList,
List **  retrieved_attrs 
)

Definition at line 2424 of file deparse.c.

2431{
2432 deparse_expr_cxt context;
2433 List *additional_conds = NIL;
2434
2435 /* Set up context struct for recursion */
2436 context.root = root;
2437 context.foreignrel = foreignrel;
2438 context.scanrel = foreignrel;
2439 context.buf = buf;
2440 context.params_list = params_list;
2441
2442 appendStringInfoString(buf, "DELETE FROM ");
2443 deparseRelation(buf, rel);
2444 if (foreignrel->reloptkind == RELOPT_JOINREL)
2445 appendStringInfo(buf, " %s%d", REL_ALIAS_PREFIX, rtindex);
2446
2447 if (foreignrel->reloptkind == RELOPT_JOINREL)
2448 {
2449 List *ignore_conds = NIL;
2450
2451 appendStringInfoString(buf, " USING ");
2452 deparseFromExprForRel(buf, root, foreignrel, true, rtindex,
2453 &ignore_conds, &additional_conds, params_list);
2454 remote_conds = list_concat(remote_conds, ignore_conds);
2455 }
2456
2457 appendWhereClause(remote_conds, additional_conds, &context);
2458
2459 if (additional_conds != NIL)
2460 list_free_deep(additional_conds);
2461
2462 if (foreignrel->reloptkind == RELOPT_JOINREL)
2463 deparseExplicitTargetList(returningList, true, retrieved_attrs,
2464 &context);
2465 else
2467 rtindex, rel, false,
2468 NIL, returningList, retrieved_attrs);
2469}
#define REL_ALIAS_PREFIX
Definition: deparse.c:109
static void deparseExplicitTargetList(List *tlist, bool is_returning, List **retrieved_attrs, deparse_expr_cxt *context)
Definition: deparse.c:1714
static void deparseFromExprForRel(StringInfo buf, PlannerInfo *root, RelOptInfo *foreignrel, bool use_alias, Index ignore_rel, List **ignore_conds, List **additional_conds, List **params_list)
Definition: deparse.c:1794
static void appendWhereClause(List *exprs, List *additional_conds, deparse_expr_cxt *context)
Definition: deparse.c:1641
List * list_concat(List *list1, const List *list2)
Definition: list.c:561
void list_free_deep(List *list)
Definition: list.c:1560
#define planner_rt_fetch(rti, root)
Definition: pathnodes.h:613
@ RELOPT_JOINREL
Definition: pathnodes.h:887
RelOptKind reloptkind
Definition: pathnodes.h:924
PlannerInfo * root
Definition: deparse.c:100
List ** params_list
Definition: deparse.c:106
RelOptInfo * foreignrel
Definition: deparse.c:101
StringInfo buf
Definition: deparse.c:105
RelOptInfo * scanrel
Definition: deparse.c:102

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

Referenced by postgresPlanDirectModify().

deparseDirectUpdateSql()

void deparseDirectUpdateSql ( StringInfo  buf,
PlannerInforoot,
Index  rtindex,
Relation  rel,
RelOptInfoforeignrel,
Listtargetlist,
ListtargetAttrs,
Listremote_conds,
List **  params_list,
ListreturningList,
List **  retrieved_attrs 
)

Definition at line 2309 of file deparse.c.

2318{
2319 deparse_expr_cxt context;
2320 int nestlevel;
2321 bool first;
2322 RangeTblEntry *rte = planner_rt_fetch(rtindex, root);
2323 ListCell *lc,
2324 *lc2;
2325 List *additional_conds = NIL;
2326
2327 /* Set up context struct for recursion */
2328 context.root = root;
2329 context.foreignrel = foreignrel;
2330 context.scanrel = foreignrel;
2331 context.buf = buf;
2332 context.params_list = params_list;
2333
2334 appendStringInfoString(buf, "UPDATE ");
2335 deparseRelation(buf, rel);
2336 if (foreignrel->reloptkind == RELOPT_JOINREL)
2337 appendStringInfo(buf, " %s%d", REL_ALIAS_PREFIX, rtindex);
2338 appendStringInfoString(buf, " SET ");
2339
2340 /* Make sure any constants in the exprs are printed portably */
2341 nestlevel = set_transmission_modes();
2342
2343 first = true;
2344 forboth(lc, targetlist, lc2, targetAttrs)
2345 {
2347 int attnum = lfirst_int(lc2);
2348
2349 /* update's new-value expressions shouldn't be resjunk */
2350 Assert(!tle->resjunk);
2351
2352 if (!first)
2354 first = false;
2355
2356 deparseColumnRef(buf, rtindex, attnum, rte, false);
2358 deparseExpr((Expr *) tle->expr, &context);
2359 }
2360
2361 reset_transmission_modes(nestlevel);
2362
2363 if (foreignrel->reloptkind == RELOPT_JOINREL)
2364 {
2365 List *ignore_conds = NIL;
2366
2367
2368 appendStringInfoString(buf, " FROM ");
2369 deparseFromExprForRel(buf, root, foreignrel, true, rtindex,
2370 &ignore_conds, &additional_conds, params_list);
2371 remote_conds = list_concat(remote_conds, ignore_conds);
2372 }
2373
2374 appendWhereClause(remote_conds, additional_conds, &context);
2375
2376 if (additional_conds != NIL)
2377 list_free_deep(additional_conds);
2378
2379 if (foreignrel->reloptkind == RELOPT_JOINREL)
2380 deparseExplicitTargetList(returningList, true, retrieved_attrs,
2381 &context);
2382 else
2383 deparseReturningList(buf, rte, rtindex, rel, false,
2384 NIL, returningList, retrieved_attrs);
2385}
static void deparseColumnRef(StringInfo buf, int varno, int varattno, RangeTblEntry *rte, bool qualify_col)
Definition: deparse.c:2714
static void deparseExpr(Expr *node, deparse_expr_cxt *context)
Definition: deparse.c:2917
Assert(PointerIsAligned(start, uint64))
int16 attnum
Definition: pg_attribute.h:74
#define forboth(cell1, list1, cell2, list2)
Definition: pg_list.h:518
#define lfirst_int(lc)
Definition: pg_list.h:173
void reset_transmission_modes(int nestlevel)
Definition: postgres_fdw.c:3929
int set_transmission_modes(void)
Definition: postgres_fdw.c:3893
Definition: primnodes.h:189
Expr * expr
Definition: primnodes.h:2239

References appendStringInfo(), appendStringInfoString(), appendWhereClause(), 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(), list_free_deep(), NIL, deparse_expr_cxt::params_list, planner_rt_fetch, REL_ALIAS_PREFIX, RELOPT_JOINREL, RelOptInfo::reloptkind, reset_transmission_modes(), deparse_expr_cxt::root, root, deparse_expr_cxt::scanrel, and set_transmission_modes().

Referenced by postgresPlanDirectModify().

deparseInsertSql()

void deparseInsertSql ( StringInfo  buf,
RangeTblEntryrte,
Index  rtindex,
Relation  rel,
ListtargetAttrs,
bool  doNothing,
ListwithCheckOptionList,
ListreturningList,
List **  retrieved_attrs,
int *  values_end_len 
)

Definition at line 2116 of file deparse.c.

2121{
2122 TupleDesc tupdesc = RelationGetDescr(rel);
2123 AttrNumber pindex;
2124 bool first;
2125 ListCell *lc;
2126
2127 appendStringInfoString(buf, "INSERT INTO ");
2128 deparseRelation(buf, rel);
2129
2130 if (targetAttrs)
2131 {
2133
2134 first = true;
2135 foreach(lc, targetAttrs)
2136 {
2137 int attnum = lfirst_int(lc);
2138
2139 if (!first)
2141 first = false;
2142
2143 deparseColumnRef(buf, rtindex, attnum, rte, false);
2144 }
2145
2146 appendStringInfoString(buf, ") VALUES (");
2147
2148 pindex = 1;
2149 first = true;
2150 foreach(lc, targetAttrs)
2151 {
2152 int attnum = lfirst_int(lc);
2153 Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum - 1);
2154
2155 if (!first)
2157 first = false;
2158
2159 if (attr->attgenerated)
2160 appendStringInfoString(buf, "DEFAULT");
2161 else
2162 {
2163 appendStringInfo(buf, "$%d", pindex);
2164 pindex++;
2165 }
2166 }
2167
2169 }
2170 else
2171 appendStringInfoString(buf, " DEFAULT VALUES");
2172 *values_end_len = buf->len;
2173
2174 if (doNothing)
2175 appendStringInfoString(buf, " ON CONFLICT DO NOTHING");
2176
2177 deparseReturningList(buf, rte, rtindex, rel,
2179 withCheckOptionList, returningList, retrieved_attrs);
2180}
int16 AttrNumber
Definition: attnum.h:21
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:202
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:242
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,
PlannerInforoot,
RelOptInforel,
Listtlist,
Listremote_conds,
Listpathkeys,
bool  has_final_sort,
bool  has_limit,
bool  is_subquery,
List **  retrieved_attrs,
List **  params_list 
)

Definition at line 1266 of file deparse.c.

1270{
1271 deparse_expr_cxt context;
1272 PgFdwRelationInfo *fpinfo = (PgFdwRelationInfo *) rel->fdw_private;
1273 List *quals;
1274
1275 /*
1276 * We handle relations for foreign tables, joins between those and upper
1277 * relations.
1278 */
1279 Assert(IS_JOIN_REL(rel) || IS_SIMPLE_REL(rel) || IS_UPPER_REL(rel));
1280
1281 /* Fill portions of context common to upper, join and base relation */
1282 context.buf = buf;
1283 context.root = root;
1284 context.foreignrel = rel;
1285 context.scanrel = IS_UPPER_REL(rel) ? fpinfo->outerrel : rel;
1286 context.params_list = params_list;
1287
1288 /* Construct SELECT clause */
1289 deparseSelectSql(tlist, is_subquery, retrieved_attrs, &context);
1290
1291 /*
1292 * For upper relations, the WHERE clause is built from the remote
1293 * conditions of the underlying scan relation; otherwise, we can use the
1294 * supplied list of remote conditions directly.
1295 */
1296 if (IS_UPPER_REL(rel))
1297 {
1298 PgFdwRelationInfo *ofpinfo;
1299
1300 ofpinfo = (PgFdwRelationInfo *) fpinfo->outerrel->fdw_private;
1301 quals = ofpinfo->remote_conds;
1302 }
1303 else
1304 quals = remote_conds;
1305
1306 /* Construct FROM and WHERE clauses */
1307 deparseFromExpr(quals, &context);
1308
1309 if (IS_UPPER_REL(rel))
1310 {
1311 /* Append GROUP BY clause */
1312 appendGroupByClause(tlist, &context);
1313
1314 /* Append HAVING clause */
1315 if (remote_conds)
1316 {
1317 appendStringInfoString(buf, " HAVING ");
1318 appendConditions(remote_conds, &context);
1319 }
1320 }
1321
1322 /* Add ORDER BY clause if we found any useful pathkeys */
1323 if (pathkeys)
1324 appendOrderByClause(pathkeys, has_final_sort, &context);
1325
1326 /* Add LIMIT clause if necessary */
1327 if (has_limit)
1328 appendLimitClause(&context);
1329
1330 /* Add any necessary FOR UPDATE/SHARE. */
1331 deparseLockingClause(&context);
1332}
static void appendGroupByClause(List *tlist, deparse_expr_cxt *context)
Definition: deparse.c:3916
static void deparseFromExpr(List *quals, deparse_expr_cxt *context)
Definition: deparse.c:1406
static void deparseLockingClause(deparse_expr_cxt *context)
Definition: deparse.c:1514
static void appendOrderByClause(List *pathkeys, bool has_final_sort, deparse_expr_cxt *context)
Definition: deparse.c:3964
static void appendConditions(List *exprs, deparse_expr_cxt *context)
Definition: deparse.c:1604
static void appendLimitClause(deparse_expr_cxt *context)
Definition: deparse.c:4058
static void deparseSelectSql(List *tlist, bool is_subquery, List **retrieved_attrs, deparse_expr_cxt *context)
Definition: deparse.c:1348
#define IS_SIMPLE_REL(rel)
Definition: pathnodes.h:898
#define IS_JOIN_REL(rel)
Definition: pathnodes.h:903
RelOptInfo * outerrel
Definition: postgres_fdw.h:103
List * remote_conds
Definition: postgres_fdw.h:43

References appendConditions(), appendGroupByClause(), appendLimitClause(), appendOrderByClause(), appendStringInfoString(), Assert(), deparse_expr_cxt::buf, buf, deparseFromExpr(), deparseLockingClause(), deparseSelectSql(), 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, 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 2882 of file deparse.c.

2883{
2884 const char *valptr;
2885
2886 /*
2887 * Rather than making assumptions about the remote server's value of
2888 * standard_conforming_strings, always use E'foo' syntax if there are any
2889 * backslashes. This will fail on remote servers before 8.1, but those
2890 * are long out of support.
2891 */
2892 if (strchr(val, '\\') != NULL)
2895 for (valptr = val; *valptr; valptr++)
2896 {
2897 char ch = *valptr;
2898
2899 if (SQL_STR_DOUBLE(ch, true))
2902 }
2904}
#define ESCAPE_STRING_SYNTAX
Definition: c.h:1165
#define SQL_STR_DOUBLE(ch, escape_backslash)
Definition: c.h:1162
long val
Definition: informix.c:689

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

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

deparseTruncateSql()

void deparseTruncateSql ( StringInfo  buf,
Listrels,
DropBehavior  behavior,
bool  restart_seqs 
)

Definition at line 2679 of file deparse.c.

2683{
2684 ListCell *cell;
2685
2686 appendStringInfoString(buf, "TRUNCATE ");
2687
2688 foreach(cell, rels)
2689 {
2690 Relation rel = lfirst(cell);
2691
2692 if (cell != list_head(rels))
2694
2695 deparseRelation(buf, rel);
2696 }
2697
2698 appendStringInfo(buf, " %s IDENTITY",
2699 restart_seqs ? "RESTART" : "CONTINUE");
2700
2701 if (behavior == DROP_RESTRICT)
2702 appendStringInfoString(buf, " RESTRICT");
2703 else if (behavior == DROP_CASCADE)
2704 appendStringInfoString(buf, " CASCADE");
2705}
@ DROP_CASCADE
Definition: parsenodes.h:2399
@ DROP_RESTRICT
Definition: parsenodes.h:2398
static ListCell * list_head(const List *l)
Definition: pg_list.h:128
Definition: rel.h:56

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

Referenced by postgresExecForeignTruncate().

deparseUpdateSql()

void deparseUpdateSql ( StringInfo  buf,
RangeTblEntryrte,
Index  rtindex,
Relation  rel,
ListtargetAttrs,
ListwithCheckOptionList,
ListreturningList,
List **  retrieved_attrs 
)

Definition at line 2249 of file deparse.c.

2254{
2255 TupleDesc tupdesc = RelationGetDescr(rel);
2256 AttrNumber pindex;
2257 bool first;
2258 ListCell *lc;
2259
2260 appendStringInfoString(buf, "UPDATE ");
2261 deparseRelation(buf, rel);
2262 appendStringInfoString(buf, " SET ");
2263
2264 pindex = 2; /* ctid is always the first param */
2265 first = true;
2266 foreach(lc, targetAttrs)
2267 {
2268 int attnum = lfirst_int(lc);
2269 Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum - 1);
2270
2271 if (!first)
2273 first = false;
2274
2275 deparseColumnRef(buf, rtindex, attnum, rte, false);
2276 if (attr->attgenerated)
2277 appendStringInfoString(buf, " = DEFAULT");
2278 else
2279 {
2280 appendStringInfo(buf, " = $%d", pindex);
2281 pindex++;
2282 }
2283 }
2284 appendStringInfoString(buf, " WHERE ctid = 1ドル");
2285
2286 deparseReturningList(buf, rte, rtindex, rel,
2288 withCheckOptionList, returningList, retrieved_attrs);
2289}
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 ( PGconnconn,
const char *  sql 
)

Definition at line 811 of file connection.c.

812{
814 do_sql_command_end(conn, sql, false);
815}
static void do_sql_command_end(PGconn *conn, const char *sql, bool consume_input)
Definition: connection.c:825
static void do_sql_command_begin(PGconn *conn, const char *sql)
Definition: connection.c:818
PGconn * conn
Definition: streamutil.c:52

References conn, do_sql_command_begin(), and do_sql_command_end().

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

ExtractConnectionOptions()

int ExtractConnectionOptions ( Listdefelems,
const char **  keywords,
const char **  values 
)

Definition at line 414 of file option.c.

416{
417 ListCell *lc;
418 int i;
419
420 /* Build our options lists if we didn't yet. */
422
423 i = 0;
424 foreach(lc, defelems)
425 {
426 DefElem *d = (DefElem *) lfirst(lc);
427
428 if (is_libpq_option(d->defname))
429 {
430 keywords[i] = d->defname;
431 values[i] = defGetString(d);
432 i++;
433 }
434 }
435 return i;
436}
static Datum values[MAXATTR]
Definition: bootstrap.c:153
static bool is_libpq_option(const char *keyword)
Definition: option.c:393
static void InitPgFdwOptions(void)
Definition: option.c:234
static const JsonPathKeyword keywords[]
Definition: jsonpath_scan.l:402

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

Referenced by connect_pg_server().

ExtractExtensionList()

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

Definition at line 445 of file option.c.

446{
447 List *extensionOids = NIL;
448 List *extlist;
449 ListCell *lc;
450
451 /* SplitIdentifierString scribbles on its input, so pstrdup first */
452 if (!SplitIdentifierString(pstrdup(extensionsString), ',', &extlist))
453 {
454 /* syntax error in name list */
456 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
457 errmsg("parameter \"%s\" must be a list of extension names",
458 "extensions")));
459 }
460
461 foreach(lc, extlist)
462 {
463 const char *extension_name = (const char *) lfirst(lc);
464 Oid extension_oid = get_extension_oid(extension_name, true);
465
466 if (OidIsValid(extension_oid))
467 {
468 extensionOids = lappend_oid(extensionOids, extension_oid);
469 }
470 else if (warnOnMissing)
471 {
473 (errcode(ERRCODE_UNDEFINED_OBJECT),
474 errmsg("extension \"%s\" is not installed",
475 extension_name)));
476 }
477 }
478
479 list_free(extlist);
480 return extensionOids;
481}
#define OidIsValid(objectId)
Definition: c.h:774
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define WARNING
Definition: elog.h:36
#define ereport(elevel,...)
Definition: elog.h:150
Oid get_extension_oid(const char *extname, bool missing_ok)
Definition: extension.c:167
List * lappend_oid(List *list, Oid datum)
Definition: list.c:375
void list_free(List *list)
Definition: list.c:1546
char * pstrdup(const char *in)
Definition: mcxt.c:1759
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:2744

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

EquivalenceMember * find_em_for_rel ( PlannerInforoot,
RelOptInforel 
)

Definition at line 7751 of file postgres_fdw.c.

7752{
7753 PgFdwRelationInfo *fpinfo = (PgFdwRelationInfo *) rel->fdw_private;
7756
7757 setup_eclass_member_iterator(&it, ec, rel->relids);
7758 while ((em = eclass_member_iterator_next(&it)) != NULL)
7759 {
7760 /*
7761 * Note we require !bms_is_empty, else we'd accept constant
7762 * expressions which are not suitable for the purpose.
7763 */
7764 if (bms_is_subset(em->em_relids, rel->relids) &&
7765 !bms_is_empty(em->em_relids) &&
7766 bms_is_empty(bms_intersect(em->em_relids, fpinfo->hidden_subquery_rels)) &&
7767 is_foreign_expr(root, rel, em->em_expr))
7768 return em;
7769 }
7770
7771 return NULL;
7772}
Bitmapset * bms_intersect(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:292
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:412
#define bms_is_empty(a)
Definition: bitmapset.h:118
void setup_eclass_member_iterator(EquivalenceMemberIterator *it, EquivalenceClass *ec, Relids child_relids)
Definition: equivclass.c:3156
EquivalenceMember * eclass_member_iterator_next(EquivalenceMemberIterator *it)
Definition: equivclass.c:3175
Relids hidden_subquery_rels
Definition: postgres_fdw.h:122
Relids relids
Definition: pathnodes.h:930

References bms_intersect(), bms_is_empty, bms_is_subset(), eclass_member_iterator_next(), PgFdwRelationInfo::hidden_subquery_rels, is_foreign_expr(), RelOptInfo::relids, root, and setup_eclass_member_iterator().

Referenced by appendOrderByClause(), get_useful_pathkeys_for_relation(), and is_foreign_pathkey().

find_em_for_rel_target()

EquivalenceMember * find_em_for_rel_target ( PlannerInforoot,
RelOptInforel 
)

Definition at line 7786 of file postgres_fdw.c.

7788{
7789 PathTarget *target = rel->reltarget;
7790 ListCell *lc1;
7791 int i;
7792
7793 i = 0;
7794 foreach(lc1, target->exprs)
7795 {
7796 Expr *expr = (Expr *) lfirst(lc1);
7797 Index sgref = get_pathtarget_sortgroupref(target, i);
7798 ListCell *lc2;
7799
7800 /* Ignore non-sort expressions */
7801 if (sgref == 0 ||
7803 root->parse->sortClause) == NULL)
7804 {
7805 i++;
7806 continue;
7807 }
7808
7809 /* We ignore binary-compatible relabeling on both ends */
7810 while (expr && IsA(expr, RelabelType))
7811 expr = ((RelabelType *) expr)->arg;
7812
7813 /*
7814 * Locate an EquivalenceClass member matching this expr, if any.
7815 * Ignore child members.
7816 */
7817 foreach(lc2, ec->ec_members)
7818 {
7820 Expr *em_expr;
7821
7822 /* Don't match constants */
7823 if (em->em_is_const)
7824 continue;
7825
7826 /* Child members should not exist in ec_members */
7827 Assert(!em->em_is_child);
7828
7829 /* Match if same expression (after stripping relabel) */
7830 em_expr = em->em_expr;
7831 while (em_expr && IsA(em_expr, RelabelType))
7832 em_expr = ((RelabelType *) em_expr)->arg;
7833
7834 if (!equal(em_expr, expr))
7835 continue;
7836
7837 /* Check that expression (including relabels!) is shippable */
7838 if (is_foreign_expr(root, rel, em->em_expr))
7839 return em;
7840 }
7841
7842 i++;
7843 }
7844
7845 return NULL;
7846}
unsigned int Index
Definition: c.h:619
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:223
#define IsA(nodeptr, _type_)
Definition: nodes.h:164
#define get_pathtarget_sortgroupref(target, colno)
Definition: pathnodes.h:1798
List * ec_members
Definition: pathnodes.h:1566
Expr * em_expr
Definition: pathnodes.h:1624
SortGroupClause * get_sortgroupref_clause_noerr(Index sortref, List *clauses)
Definition: tlist.c:443

References Assert(), EquivalenceClass::ec_members, EquivalenceMember::em_expr, EquivalenceMember::em_is_child, EquivalenceMember::em_is_const, equal(), PathTarget::exprs, get_pathtarget_sortgroupref, get_sortgroupref_clause_noerr(), i, is_foreign_expr(), IsA, lfirst, RelOptInfo::reltarget, and root.

Referenced by add_foreign_ordered_paths(), and appendOrderByClause().

get_jointype_name()

const char * get_jointype_name ( JoinType  jointype )

Definition at line 1674 of file deparse.c.

1675{
1676 switch (jointype)
1677 {
1678 case JOIN_INNER:
1679 return "INNER";
1680
1681 case JOIN_LEFT:
1682 return "LEFT";
1683
1684 case JOIN_RIGHT:
1685 return "RIGHT";
1686
1687 case JOIN_FULL:
1688 return "FULL";
1689
1690 case JOIN_SEMI:
1691 return "SEMI";
1692
1693 default:
1694 /* Shouldn't come here, but protect from buggy code. */
1695 elog(ERROR, "unsupported join type %d", jointype);
1696 }
1697
1698 /* Keep compiler happy */
1699 return NULL;
1700}
@ JOIN_SEMI
Definition: nodes.h:317
@ JOIN_FULL
Definition: nodes.h:305
@ JOIN_INNER
Definition: nodes.h:303
@ JOIN_RIGHT
Definition: nodes.h:306
@ JOIN_LEFT
Definition: nodes.h:304

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

Referenced by deparseFromExprForRel(), and foreign_join_ok().

GetConnection()

PGconn * GetConnection ( UserMappinguser,
bool  will_prep_stmt,
PgFdwConnState **  state 
)

Definition at line 206 of file connection.c.

207{
208 bool found;
209 bool retry = false;
210 ConnCacheEntry *entry;
213
214 /* First time through, initialize connection cache hashtable */
215 if (ConnectionHash == NULL)
216 {
217 HASHCTL ctl;
218
219 if (pgfdw_we_get_result == 0)
221 WaitEventExtensionNew("PostgresFdwGetResult");
222
223 ctl.keysize = sizeof(ConnCacheKey);
224 ctl.entrysize = sizeof(ConnCacheEntry);
225 ConnectionHash = hash_create("postgres_fdw connections", 8,
226 &ctl,
228
229 /*
230 * Register some callback functions that manage connection cleanup.
231 * This should be done just once in each backend.
232 */
235 CacheRegisterSyscacheCallback(FOREIGNSERVEROID,
237 CacheRegisterSyscacheCallback(USERMAPPINGOID,
239 }
240
241 /* Set flag that we did GetConnection during the current transaction */
242 xact_got_connection = true;
243
244 /* Create hash key for the entry. Assume no pad bytes in key struct */
245 key = user->umid;
246
247 /*
248 * Find or create cached entry for requested connection.
249 */
250 entry = hash_search(ConnectionHash, &key, HASH_ENTER, &found);
251 if (!found)
252 {
253 /*
254 * We need only clear "conn" here; remaining fields will be filled
255 * later when "conn" is set.
256 */
257 entry->conn = NULL;
258 }
259
260 /* Reject further use of connections which failed abort cleanup. */
262
263 /*
264 * If the connection needs to be remade due to invalidation, disconnect as
265 * soon as we're out of all transactions.
266 */
267 if (entry->conn != NULL && entry->invalidated && entry->xact_depth == 0)
268 {
269 elog(DEBUG3, "closing connection %p for option changes to take effect",
270 entry->conn);
272 }
273
274 /*
275 * If cache entry doesn't have a connection, we have to establish a new
276 * connection. (If connect_pg_server throws an error, the cache entry
277 * will remain in a valid empty state, ie conn == NULL.)
278 */
279 if (entry->conn == NULL)
281
282 /*
283 * We check the health of the cached connection here when using it. In
284 * cases where we're out of all transactions, if a broken connection is
285 * detected, we try to reestablish a new connection later.
286 */
287 PG_TRY();
288 {
289 /* Process a pending asynchronous request if any. */
290 if (entry->state.pendingAreq)
292 /* Start a new transaction or subtransaction if needed. */
293 begin_remote_xact(entry);
294 }
295 PG_CATCH();
296 {
298 ErrorData *errdata = CopyErrorData();
299
300 /*
301 * Determine whether to try to reestablish the connection.
302 *
303 * After a broken connection is detected in libpq, any error other
304 * than connection failure (e.g., out-of-memory) can be thrown
305 * somewhere between return from libpq and the expected ereport() call
306 * in pgfdw_report_error(). In this case, since PQstatus() indicates
307 * CONNECTION_BAD, checking only PQstatus() causes the false detection
308 * of connection failure. To avoid this, we also verify that the
309 * error's sqlstate is ERRCODE_CONNECTION_FAILURE. Note that also
310 * checking only the sqlstate can cause another false detection
311 * because pgfdw_report_error() may report ERRCODE_CONNECTION_FAILURE
312 * for any libpq-originated error condition.
313 */
314 if (errdata->sqlerrcode != ERRCODE_CONNECTION_FAILURE ||
315 PQstatus(entry->conn) != CONNECTION_BAD ||
316 entry->xact_depth > 0)
317 {
319 PG_RE_THROW();
320 }
321
322 /* Clean up the error state */
324 FreeErrorData(errdata);
325 errdata = NULL;
326
327 retry = true;
328 }
329 PG_END_TRY();
330
331 /*
332 * If a broken connection is detected, disconnect it, reestablish a new
333 * connection and retry a new remote transaction. If connection failure is
334 * reported again, we give up getting a connection.
335 */
336 if (retry)
337 {
338 Assert(entry->xact_depth == 0);
339
341 (errmsg_internal("could not start remote transaction on connection %p",
342 entry->conn)),
344
345 elog(DEBUG3, "closing connection %p to reestablish a new one",
346 entry->conn);
348
350
351 begin_remote_xact(entry);
352 }
353
354 /* Remember if caller will prepare statements */
355 entry->have_prep_stmt |= will_prep_stmt;
356
357 /* If caller needs access to the per-connection state, return it. */
358 if (state)
359 *state = &entry->state;
360
361 return entry->conn;
362}
Oid ConnCacheKey
Definition: connection.c:53
static void disconnect_pg_server(ConnCacheEntry *entry)
Definition: connection.c:659
static uint32 pgfdw_we_get_result
Definition: connection.c:91
static bool xact_got_connection
Definition: connection.c:86
struct ConnCacheEntry ConnCacheEntry
static HTAB * ConnectionHash
Definition: connection.c:79
static void make_new_connection(ConnCacheEntry *entry, UserMapping *user)
Definition: connection.c:369
static void pgfdw_subxact_callback(SubXactEvent event, SubTransactionId mySubid, SubTransactionId parentSubid, void *arg)
Definition: connection.c:1199
static void pgfdw_reject_incomplete_xact_state_change(ConnCacheEntry *entry)
Definition: connection.c:1362
static void pgfdw_inval_callback(Datum arg, int cacheid, uint32 hashvalue)
Definition: connection.c:1312
static void pgfdw_xact_callback(XactEvent event, void *arg)
Definition: connection.c:1049
static void begin_remote_xact(ConnCacheEntry *entry)
Definition: connection.c:854
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:952
HTAB * hash_create(const char *tabname, int64 nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:358
int errmsg_internal(const char *fmt,...)
Definition: elog.c:1161
void FreeErrorData(ErrorData *edata)
Definition: elog.c:1826
int errdetail_internal(const char *fmt,...)
Definition: elog.c:1234
ErrorData * CopyErrorData(void)
Definition: elog.c:1754
void FlushErrorState(void)
Definition: elog.c:1875
#define PG_RE_THROW()
Definition: elog.h:405
#define DEBUG3
Definition: elog.h:28
#define PG_TRY(...)
Definition: elog.h:372
#define PG_END_TRY(...)
Definition: elog.h:397
#define PG_CATCH(...)
Definition: elog.h:382
ConnStatusType PQstatus(const PGconn *conn)
Definition: fe-connect.c:7616
char * PQerrorMessage(const PGconn *conn)
Definition: fe-connect.c:7679
@ 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:1812
@ CONNECTION_BAD
Definition: libpq-fe.h:85
char * pchomp(const char *in)
Definition: mcxt.c:1787
MemoryContext CurrentMemoryContext
Definition: mcxt.c:160
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
static char * user
Definition: pg_regress.c:119
uint64_t Datum
Definition: postgres.h:70
void process_pending_request(AsyncRequest *areq)
Definition: postgres_fdw.c:7424
tree ctl
Definition: radixtree.h:1838
PGconn * conn
Definition: connection.c:58
bool have_prep_stmt
Definition: connection.c:62
PgFdwConnState state
Definition: connection.c:73
bool invalidated
Definition: connection.c:67
int xact_depth
Definition: connection.c:60
Definition: elog.h:420
int sqlerrcode
Definition: elog.h:431
Definition: hsearch.h:66
AsyncRequest * pendingAreq
Definition: postgres_fdw.h:139
Definition: regguts.h:323
uint32 WaitEventExtensionNew(const char *wait_event_name)
Definition: wait_event.c:163
void RegisterXactCallback(XactCallback callback, void *arg)
Definition: xact.c:3816
void RegisterSubXactCallback(SubXactCallback callback, void *arg)
Definition: xact.c:3876

References Assert(), begin_remote_xact(), CacheRegisterSyscacheCallback(), ConnCacheEntry::conn, CONNECTION_BAD, ConnectionHash, CopyErrorData(), ctl, CurrentMemoryContext, DEBUG3, disconnect_pg_server(), elog, ereport, errdetail_internal(), errmsg_internal(), FlushErrorState(), FreeErrorData(), HASH_BLOBS, hash_create(), HASH_ELEM, HASH_ENTER, hash_search(), ConnCacheEntry::have_prep_stmt, ConnCacheEntry::invalidated, sort-test::key, 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_we_get_result, pgfdw_xact_callback(), PQerrorMessage(), PQstatus(), process_pending_request(), RegisterSubXactCallback(), RegisterXactCallback(), ErrorData::sqlerrcode, ConnCacheEntry::state, user, WaitEventExtensionNew(), ConnCacheEntry::xact_depth, and xact_got_connection.

Referenced by create_foreign_modify(), dumpDatabase(), dumpDatabaseConfig(), dumpLOs(), 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(), postgresGetAnalyzeInfoForForeignTable(), postgresImportForeignSchema(), setup_connection(), StartLogStreamer(), StreamLog(), and StreamLogicalLog().

GetCursorNumber()

unsigned int GetCursorNumber ( PGconnconn )

Definition at line 918 of file connection.c.

919{
920 return ++cursor_number;
921}
static unsigned int cursor_number
Definition: connection.c:82

References cursor_number.

Referenced by postgresAcquireSampleRowsFunc(), and postgresBeginForeignScan().

GetPrepStmtNumber()

unsigned int GetPrepStmtNumber ( PGconnconn )

Definition at line 932 of file connection.c.

933{
934 return ++prep_stmt_number;
935}
static unsigned int prep_stmt_number
Definition: connection.c:83

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 ( PlannerInforoot,
RelOptInfobaserel,
Exprexpr 
)

Definition at line 244 of file deparse.c.

247{
248 foreign_glob_cxt glob_cxt;
249 foreign_loc_cxt loc_cxt;
250 PgFdwRelationInfo *fpinfo = (PgFdwRelationInfo *) (baserel->fdw_private);
251
252 /*
253 * Check that the expression consists of nodes that are safe to execute
254 * remotely.
255 */
256 glob_cxt.root = root;
257 glob_cxt.foreignrel = baserel;
258
259 /*
260 * For an upper relation, use relids from its underneath scan relation,
261 * because the upperrel's own relids currently aren't set to anything
262 * meaningful by the core code. For other relation, use their own relids.
263 */
264 if (IS_UPPER_REL(baserel))
265 glob_cxt.relids = fpinfo->outerrel->relids;
266 else
267 glob_cxt.relids = baserel->relids;
268 loc_cxt.collation = InvalidOid;
269 loc_cxt.state = FDW_COLLATE_NONE;
270 if (!foreign_expr_walker((Node *) expr, &glob_cxt, &loc_cxt, NULL))
271 return false;
272
273 /*
274 * If the expression has a valid collation that does not arise from a
275 * foreign var, the expression can not be sent over.
276 */
277 if (loc_cxt.state == FDW_COLLATE_UNSAFE)
278 return false;
279
280 /*
281 * An expression which includes any mutable functions can't be sent over
282 * because its result is not stable. For example, sending now() remote
283 * side could cause confusion from clock offsets. Future versions might
284 * be able to make this choice with more granularity. (We check this last
285 * because it requires a lot of expensive catalog lookups.)
286 */
287 if (contain_mutable_functions((Node *) expr))
288 return false;
289
290 /* OK to evaluate on the remote server */
291 return true;
292}
bool contain_mutable_functions(Node *clause)
Definition: clauses.c:374
@ FDW_COLLATE_UNSAFE
Definition: deparse.c:85
@ FDW_COLLATE_NONE
Definition: deparse.c:81
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:312
#define InvalidOid
Definition: postgres_ext.h:37
RelOptInfo * foreignrel
Definition: deparse.c:70
Relids relids
Definition: deparse.c:71
PlannerInfo * root
Definition: deparse.c:69
Oid collation
Definition: deparse.c:91
FDWCollateState state
Definition: deparse.c:92

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

Referenced by add_foreign_final_paths(), classifyConditions(), find_em_for_rel(), find_em_for_rel_target(), foreign_grouping_ok(), foreign_join_ok(), postgresGetForeignPaths(), postgresGetForeignPlan(), and postgresPlanDirectModify().

is_foreign_param()

bool is_foreign_param ( PlannerInforoot,
RelOptInfobaserel,
Exprexpr 
)

Definition at line 1115 of file deparse.c.

1118{
1119 if (expr == NULL)
1120 return false;
1121
1122 switch (nodeTag(expr))
1123 {
1124 case T_Var:
1125 {
1126 /* It would have to be sent unless it's a foreign Var */
1127 Var *var = (Var *) expr;
1128 PgFdwRelationInfo *fpinfo = (PgFdwRelationInfo *) (baserel->fdw_private);
1129 Relids relids;
1130
1131 if (IS_UPPER_REL(baserel))
1132 relids = fpinfo->outerrel->relids;
1133 else
1134 relids = baserel->relids;
1135
1136 if (bms_is_member(var->varno, relids) && var->varlevelsup == 0)
1137 return false; /* foreign Var, so not a param */
1138 else
1139 return true; /* it'd have to be a param */
1140 break;
1141 }
1142 case T_Param:
1143 /* Params always have to be sent to the foreign server */
1144 return true;
1145 default:
1146 break;
1147 }
1148 return false;
1149}
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:510
#define nodeTag(nodeptr)
Definition: nodes.h:139
Definition: primnodes.h:262
int varno
Definition: primnodes.h:269
Index varlevelsup
Definition: primnodes.h:294

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

Referenced by foreign_grouping_ok().

is_foreign_pathkey()

bool is_foreign_pathkey ( PlannerInforoot,
RelOptInfobaserel,
PathKeypathkey 
)

Definition at line 1156 of file deparse.c.

1159{
1160 EquivalenceClass *pathkey_ec = pathkey->pk_eclass;
1161 PgFdwRelationInfo *fpinfo = (PgFdwRelationInfo *) baserel->fdw_private;
1162
1163 /*
1164 * is_foreign_expr would detect volatile expressions as well, but checking
1165 * ec_has_volatile here saves some cycles.
1166 */
1167 if (pathkey_ec->ec_has_volatile)
1168 return false;
1169
1170 /* can't push down the sort if the pathkey's opfamily is not shippable */
1171 if (!is_shippable(pathkey->pk_opfamily, OperatorFamilyRelationId, fpinfo))
1172 return false;
1173
1174 /* can push if a suitable EC member exists */
1175 return (find_em_for_rel(root, pathkey_ec, baserel) != NULL);
1176}
EquivalenceMember * find_em_for_rel(PlannerInfo *root, EquivalenceClass *ec, RelOptInfo *rel)
Definition: postgres_fdw.c:7751
bool is_shippable(Oid objectId, Oid classId, PgFdwRelationInfo *fpinfo)
Definition: shippable.c:162
bool ec_has_volatile
Definition: pathnodes.h:1576
Oid pk_opfamily
Definition: pathnodes.h:1718

References EquivalenceClass::ec_has_volatile, find_em_for_rel(), if(), is_shippable(), PathKey::pk_opfamily, and root.

Referenced by get_useful_pathkeys_for_relation().

is_shippable()

bool is_shippable ( Oid  objectId,
Oid  classId,
PgFdwRelationInfofpinfo 
)

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. */
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
188 if (!entry)
189 {
190 /* Not found in cache, so perform shippability lookup. */
191 bool shippable = lookup_shippable(objectId, classId, fpinfo);
192
193 /*
194 * Don't create a new hash entry until *after* we have the shippable
195 * result in hand, as the underlying catalog lookups might trigger a
196 * cache invalidation.
197 */
198 entry = (ShippableCacheEntry *)
200
201 entry->shippable = shippable;
202 }
203
204 return entry->shippable;
205}
@ 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:82
ForeignServer * server
Definition: postgres_fdw.h:87

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 add_foreign_ordered_paths(), foreign_expr_walker(), get_useful_pathkeys_for_relation(), and is_foreign_pathkey().

pgfdw_exec_query()

PGresult * pgfdw_exec_query ( PGconnconn,
const char *  query,
PgFdwConnStatestate 
)

Definition at line 947 of file connection.c.

948{
949 /* First, process a pending asynchronous request, if any. */
950 if (state && state->pendingAreq)
951 process_pending_request(state->pendingAreq);
952
953 if (!PQsendQuery(conn, query))
954 return NULL;
955 return pgfdw_get_result(conn);
956}
PGresult * pgfdw_get_result(PGconn *conn)
Definition: connection.c:964
int PQsendQuery(PGconn *conn, const char *query)
Definition: fe-exec.c:1427

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

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

pgfdw_get_result()

PGresult * pgfdw_get_result ( PGconnconn )

Definition at line 964 of file connection.c.

965{
967}
static PGresult * libpqsrv_get_result_last(PGconn *conn, uint32 wait_event_info)

References conn, libpqsrv_get_result_last(), and pgfdw_we_get_result.

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

pgfdw_report()

void pgfdw_report ( int  elevel,
PGresultres,
PGconnconn,
const char *  sql 
)

Definition at line 995 of file connection.c.

996{
997 Assert(elevel < ERROR); /* use pgfdw_report_error for that */
998 pgfdw_report_internal(elevel, res, conn, sql);
999}
static void pgfdw_report_internal(int elevel, PGresult *res, PGconn *conn, const char *sql)
Definition: connection.c:1002

References Assert(), conn, ERROR, and pgfdw_report_internal().

Referenced by pgfdw_exec_cleanup_query_begin(), and pgfdw_exec_cleanup_query_end().

pgfdw_report_error()

pg_noreturn void pgfdw_report_error ( PGresultres,
PGconnconn,
const char *  sql 
)

Definition at line 988 of file connection.c.

989{
990 pgfdw_report_internal(ERROR, res, conn, sql);
992}
#define pg_unreachable()
Definition: c.h:331

References conn, ERROR, pg_unreachable, and pgfdw_report_internal().

Referenced by close_cursor(), create_cursor(), deallocate_query(), do_sql_command_begin(), do_sql_command_end(), execute_dml_stmt(), execute_foreign_modify(), fetch_more_data(), fetch_more_data_begin(), get_remote_estimate(), postgresAcquireSampleRowsFunc(), postgresAnalyzeForeignTable(), postgresForeignAsyncNotify(), postgresGetAnalyzeInfoForForeignTable(), postgresImportForeignSchema(), postgresReScanForeignScan(), and prepare_foreign_modify().

process_pending_request()

void process_pending_request ( AsyncRequestareq )

Definition at line 7424 of file postgres_fdw.c.

7425{
7427 PgFdwScanState *fsstate = (PgFdwScanState *) node->fdw_state;
7428
7429 /* The request would have been pending for a callback */
7430 Assert(areq->callback_pending);
7431
7432 /* The request should be currently in-process */
7433 Assert(fsstate->conn_state->pendingAreq == areq);
7434
7435 fetch_more_data(node);
7436
7437 /*
7438 * If we didn't get any tuples, must be end of data; complete the request
7439 * now. Otherwise, we postpone completing the request until we are called
7440 * from postgresForeignAsyncConfigureWait()/postgresForeignAsyncNotify().
7441 */
7442 if (fsstate->next_tuple >= fsstate->num_tuples)
7443 {
7444 /* Unlike AsyncNotify, we unset callback_pending ourselves */
7445 areq->callback_pending = false;
7446 /* Mark the request as complete */
7447 ExecAsyncRequestDone(areq, NULL);
7448 /* Unlike AsyncNotify, we call ExecAsyncResponse ourselves */
7449 ExecAsyncResponse(areq);
7450 }
7451}
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)
Definition: postgres_fdw.c:3798
bool callback_pending
Definition: execnodes.h:642
PlanState * requestee
Definition: execnodes.h:640
void * fdw_state
Definition: execnodes.h:2111

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 491 of file option.c.

492{
493 const char *p;
495
497
498 for (p = appname; *p != '0円'; p++)
499 {
500 if (*p != '%')
501 {
502 /* literal char, just copy */
504 continue;
505 }
506
507 /* must be a '%', so skip to the next char */
508 p++;
509 if (*p == '0円')
510 break; /* format error - ignore it */
511 else if (*p == '%')
512 {
513 /* string contains %% */
515 continue;
516 }
517
518 /* process the option */
519 switch (*p)
520 {
521 case 'a':
523 break;
524 case 'c':
525 appendStringInfo(&buf, "%" PRIx64 ".%x", MyStartTime, MyProcPid);
526 break;
527 case 'C':
529 break;
530 case 'd':
531 if (MyProcPort)
532 {
533 const char *dbname = MyProcPort->database_name;
534
535 if (dbname)
537 else
538 appendStringInfoString(&buf, "[unknown]");
539 }
540 break;
541 case 'p':
543 break;
544 case 'u':
545 if (MyProcPort)
546 {
547 const char *username = MyProcPort->user_name;
548
549 if (username)
551 else
552 appendStringInfoString(&buf, "[unknown]");
553 }
554 break;
555 default:
556 /* format error - ignore it */
557 break;
558 }
559 }
560
561 return buf.data;
562}
int MyProcPid
Definition: globals.c:47
struct Port * MyProcPort
Definition: globals.c:51
pg_time_t MyStartTime
Definition: globals.c:48
char * cluster_name
Definition: guc_tables.c:555
char * application_name
Definition: guc_tables.c:561
static char * username
Definition: initdb.c:153
char * dbname
Definition: streamutil.c:49
char * user_name
Definition: libpq-be.h:151
char * database_name
Definition: libpq-be.h:150

References appendStringInfo(), appendStringInfoChar(), appendStringInfoString(), application_name, buf, cluster_name, Port::database_name, dbname, initStringInfo(), MyProcPid, MyProcPort, MyStartTime, Port::user_name, and username.

Referenced by connect_pg_server().

rebuildInsertSql()

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

Definition at line 2189 of file deparse.c.

2193{
2194 TupleDesc tupdesc = RelationGetDescr(rel);
2195 int i;
2196 int pindex;
2197 bool first;
2198 ListCell *lc;
2199
2200 /* Make sure the values_end_len is sensible */
2201 Assert((values_end_len > 0) && (values_end_len <= strlen(orig_query)));
2202
2203 /* Copy up to the end of the first record from the original query */
2204 appendBinaryStringInfo(buf, orig_query, values_end_len);
2205
2206 /*
2207 * Add records to VALUES clause (we already have parameters for the first
2208 * row, so start at the right offset).
2209 */
2210 pindex = num_params + 1;
2211 for (i = 0; i < num_rows; i++)
2212 {
2214
2215 first = true;
2216 foreach(lc, target_attrs)
2217 {
2218 int attnum = lfirst_int(lc);
2219 Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum - 1);
2220
2221 if (!first)
2223 first = false;
2224
2225 if (attr->attgenerated)
2226 appendStringInfoString(buf, "DEFAULT");
2227 else
2228 {
2229 appendStringInfo(buf, "$%d", pindex);
2230 pindex++;
2231 }
2232 }
2233
2235 }
2236
2237 /* Copy stuff after VALUES clause from the original query */
2238 appendStringInfoString(buf, orig_query + values_end_len);
2239}
void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)
Definition: stringinfo.c:281

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

Referenced by execute_foreign_modify().

ReleaseConnection()

void ReleaseConnection ( PGconnconn )

Definition at line 897 of file connection.c.

898{
899 /*
900 * Currently, we don't actually track connection references because all
901 * cleanup is managed on a transaction or subtransaction basis instead. So
902 * there's nothing to do here.
903 */
904}

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

reset_transmission_modes()

void reset_transmission_modes ( int  nestlevel )

Definition at line 3929 of file postgres_fdw.c.

3930{
3931 AtEOXact_GUC(true, nestlevel);
3932}
void AtEOXact_GUC(bool isCommit, int nestLevel)
Definition: guc.c:2268

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 3893 of file postgres_fdw.c.

3894{
3895 int nestlevel = NewGUCNestLevel();
3896
3897 /*
3898 * The values set here should match what pg_dump does. See also
3899 * configure_remote_session in connection.c.
3900 */
3901 if (DateStyle != USE_ISO_DATES)
3902 (void) set_config_option("datestyle", "ISO",
3904 GUC_ACTION_SAVE, true, 0, false);
3906 (void) set_config_option("intervalstyle", "postgres",
3908 GUC_ACTION_SAVE, true, 0, false);
3909 if (extra_float_digits < 3)
3910 (void) set_config_option("extra_float_digits", "3",
3912 GUC_ACTION_SAVE, true, 0, false);
3913
3914 /*
3915 * In addition force restrictive search_path, in case there are any
3916 * regproc or similar constants to be printed.
3917 */
3918 (void) set_config_option("search_path", "pg_catalog",
3920 GUC_ACTION_SAVE, true, 0, false);
3921
3922 return nestlevel;
3923}
int extra_float_digits
Definition: float.c:40
int DateStyle
Definition: globals.c:125
int IntervalStyle
Definition: globals.c:127
int NewGUCNestLevel(void)
Definition: guc.c:2241
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:3348
@ GUC_ACTION_SAVE
Definition: guc.h:205
@ PGC_S_SESSION
Definition: guc.h:126
@ PGC_USERSET
Definition: guc.h:79
#define USE_ISO_DATES
Definition: miscadmin.h:236
#define INTSTYLE_POSTGRES
Definition: miscadmin.h:256

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 46 of file option.c.

Referenced by _PG_init(), and connect_pg_server().

AltStyle によって変換されたページ (->オリジナル) /