45 #define DEFAULT_FDW_STARTUP_COST 100.0
48 #define DEFAULT_FDW_TUPLE_COST 0.01
51 #define DEFAULT_FDW_SORT_MULTIPLIER 1.2
297 Index resultRelation,
321 Index resultRelation,
356 double *p_rows,
int *p_width,
357 Cost *p_startup_cost,
Cost *p_total_cost);
383 const char ***param_values);
387 const char **param_values);
391 double *totaldeadrows);
398 List *retrieved_attrs,
478 const char *
namespace;
510 if (strcmp(def->
defname,
"use_remote_estimate") == 0)
512 else if (strcmp(def->
defname,
"fdw_startup_cost") == 0)
514 else if (strcmp(def->
defname,
"fdw_tuple_cost") == 0)
516 else if (strcmp(def->
defname,
"extensions") == 0)
519 else if (strcmp(def->
defname,
"fetch_size") == 0)
526 if (strcmp(def->
defname,
"use_remote_estimate") == 0)
528 else if (strcmp(def->
defname,
"fetch_size") == 0)
657 if (*refname && strcmp(refname, relname) != 0)
685 List *useful_eclass_list =
NIL;
700 useful_eclass_list =
lappend(useful_eclass_list, cur_ec);
710 return useful_eclass_list;
763 return useful_eclass_list;
778 List *useful_pathkeys_list =
NIL;
779 List *useful_eclass_list;
790 bool query_pathkeys_ok =
true;
812 query_pathkeys_ok =
false;
817 if (query_pathkeys_ok)
831 return useful_pathkeys_list;
851 foreach(lc, useful_eclass_list)
858 if (cur_ec == query_ec)
871 useful_pathkeys_list =
lappend(useful_pathkeys_list,
875 return useful_pathkeys_list;
1012 foreach(lc, clauses)
1050 foreach(lc, ppi_list)
1062 &startup_cost, &total_cost);
1104 List *retrieved_attrs;
1115 scan_relid = foreignrel->
relid;
1149 foreach(lc, scan_clauses)
1161 remote_conds =
lappend(remote_conds, rinfo);
1168 remote_conds =
lappend(remote_conds, rinfo);
1198 foreach(lc, local_exprs)
1200 Join *join_plan = (
Join *) outer_plan;
1223 &retrieved_attrs, ¶ms_list);
1235 fdw_private =
lappend(fdw_private,
1320 fsstate->cursor_exists =
false;
1332 "postgres_fdw tuple data",
1337 "postgres_fdw temporary data",
1357 fsstate->numParams = numParams;
1362 &fsstate->param_flinfo,
1363 &fsstate->param_exprs,
1364 &fsstate->param_values);
1433 snprintf(sql,
sizeof(sql),
"CLOSE c%u",
1438 snprintf(sql,
sizeof(sql),
"MOVE BACKWARD ALL IN c%u",
1475 if (fsstate ==
NULL)
1499 const char *attrname;
1533 Index resultRelation,
1543 bool doNothing =
false;
1565 for (attnum = 1; attnum <= tupdesc->
natts; attnum++)
1569 if (!attr->attisdropped)
1584 elog(
ERROR,
"system-column update is not supported");
1604 elog(
ERROR,
"unexpected ON CONFLICT specification: %d",
1614 targetAttrs, doNothing, returningList,
1619 targetAttrs, returningList,
1628 elog(
ERROR,
"unexpected operation: %d", (
int) operation);
1706 "postgres_fdw temporary data",
1728 elog(
ERROR,
"could not find junk ctid column");
1744 Assert(!attr->attisdropped);
1768 const char **p_values;
1818 return (n_rows > 0) ? slot :
NULL;
1834 const char **p_values;
1894 return (n_rows > 0) ? slot :
NULL;
1910 const char **p_values;
1970 return (n_rows > 0) ? slot :
NULL;
1984 if (fmstate ==
NULL)
2038 if (strcmp(def->
defname,
"updatable") == 0)
2045 if (strcmp(def->
defname,
"updatable") == 0)
2094 Index resultRelation,
2161 elog(
ERROR,
"system-column update is not supported");
2166 elog(
ERROR,
"attribute number %d not found in subplan targetlist",
2206 ((
Plan *) fscan)->targetlist,
2208 remote_conds, ¶ms_list,
2209 returningList, &retrieved_attrs);
2213 remote_conds, ¶ms_list,
2214 returningList, &retrieved_attrs);
2217 elog(
ERROR,
"unexpected operation: %d", (
int) operation);
2277 userid = rte->checkAsUser ? rte->checkAsUser :
GetUserId();
2291 dmstate->num_tuples = -1;
2305 "postgres_fdw temporary data",
2311 if (dmstate->has_returning)
2318 dmstate->numParams = numParams;
2323 &dmstate->param_flinfo,
2324 &dmstate->param_exprs,
2325 &dmstate->param_values);
2337 ResultRelInfo *resultRelInfo = estate->es_result_relation_info;
2348 if (!resultRelInfo->ri_projectReturning)
2382 if (dmstate ==
NULL)
2483 List *param_join_conds,
2485 double *p_rows,
int *p_width,
2486 Cost *p_startup_cost,
Cost *p_total_cost)
2490 double retrieved_rows;
2505 List *remote_param_join_conds;
2506 List *local_param_join_conds;
2515 List *retrieved_attrs;
2522 &remote_param_join_conds, &local_param_join_conds);
2528 fdw_scan_tlist =
NIL;
2546 remote_conds, pathkeys, &retrieved_attrs,
2552 &startup_cost, &total_cost);
2555 retrieved_rows = rows;
2559 local_param_join_conds,
2571 startup_cost += local_cost.
startup;
2572 total_cost += local_cost.
per_tuple * retrieved_rows;
2589 rows = foreignrel->
rows;
2609 retrieved_rows =
Min(retrieved_rows, foreignrel->
tuples);
2622 run_cost += cpu_per_tuple * foreignrel->
tuples;
2639 nrows = fpinfo_i->
rows * fpinfo_o->
rows;
2641 retrieved_rows =
Min(retrieved_rows, nrows);
2662 startup_cost += join_cost.
startup;
2663 startup_cost += remote_conds_cost.
startup;
2683 run_cost += nrows * join_cost.
per_tuple;
2685 run_cost += nrows * remote_conds_cost.
per_tuple;
2698 if (pathkeys !=
NIL)
2704 total_cost = startup_cost + run_cost;
2716 if (pathkeys ==
NIL && param_join_conds ==
NIL)
2736 *p_startup_cost = startup_cost;
2737 *p_total_cost = total_cost;
2746 double *rows,
int *width,
2747 Cost *startup_cost,
Cost *total_cost)
2771 p = strrchr(line,
'(');
2773 elog(
ERROR,
"could not interpret EXPLAIN output: \"%s\"", line);
2774 n = sscanf(p,
"(cost=%lf..%lf rows=%lf width=%d)",
2775 startup_cost, total_cost, rows, width);
2777 elog(
ERROR,
"could not interpret EXPLAIN output: \"%s\"", line);
2920 snprintf(sql,
sizeof(sql),
"FETCH %d FROM c%u",
2934 for (i = 0; i < numrows; i++)
3027 snprintf(sql,
sizeof(sql),
"CLOSE c%u", cursor_number);
3051 snprintf(prep_name,
sizeof(prep_name),
"pgsql_fdw_prep_%u",
3081 fmstate->
p_name = p_name;
3093 static const char **
3098 const char **p_values;
3104 p_values = (
const char **)
palloc(
sizeof(
char *) * fmstate->
p_nums);
3107 if (tupleid !=
NULL)
3131 p_values[pindex] =
NULL;
3239 ResultRelInfo *resultRelInfo = estate->es_result_relation_info;
3242 Assert(resultRelInfo->ri_projectReturning);
3250 estate->es_processed += 1;
3289 resultRelInfo->ri_projectReturning->pi_exprContext->ecxt_scantuple = slot;
3303 const char ***param_values)
3314 foreach(lc, fdw_exprs)
3321 fmgr_info(typefnoid, &(*param_flinfo)[i]);
3336 *param_values = (
const char **)
palloc0(numParams *
sizeof(
char *));
3346 const char **param_values)
3355 foreach(lc, param_exprs)
3369 param_values[
i] =
NULL;
3426 elog(
ERROR,
"unexpected result from deparseAnalyzeSizeSql query");
3465 double *totaldeadrows)
3477 astate.
rel = relation;
3490 "postgres_fdw temporary data",
3545 if (strcmp(def->
defname,
"fetch_size") == 0)
3555 if (strcmp(def->
defname,
"fetch_size") == 0)
3563 snprintf(fetch_sql,
sizeof(fetch_sql),
"FETCH %d FROM c%u",
3564 fetch_size, cursor_number);
3573 for (i = 0; i < numrows; i++)
3580 if (numrows < fetch_size)
3598 *totaldeadrows = 0.0;
3607 (
errmsg(
"\"%s\": table contains %.0f rows, %d rows in sample",
3633 if (astate->
numrows < targrows)
3652 Assert(pos >= 0 && pos < targrows);
3690 bool import_collate =
true;
3691 bool import_default =
false;
3692 bool import_not_null =
true;
3707 if (strcmp(def->
defname,
"import_collate") == 0)
3709 else if (strcmp(def->
defname,
"import_default") == 0)
3711 else if (strcmp(def->
defname,
"import_not_null") == 0)
3715 (
errcode(ERRCODE_FDW_INVALID_OPTION_NAME),
3729 import_collate =
false;
3747 (
errcode(ERRCODE_FDW_SCHEMA_NOT_FOUND),
3748 errmsg(
"schema \"%s\" is not present on foreign server \"%s\"",
3772 " format_type(atttypid, atttypmod), "
3774 " pg_get_expr(adbin, adrelid), "
3778 " JOIN pg_namespace n ON "
3779 " relnamespace = n.oid "
3780 " LEFT JOIN pg_attribute a ON "
3781 " attrelid = c.oid AND attnum > 0 "
3782 " AND NOT attisdropped "
3783 " LEFT JOIN pg_attrdef ad ON "
3784 " adrelid = c.oid AND adnum = attnum "
3785 " LEFT JOIN pg_collation coll ON "
3786 " coll.oid = attcollation "
3787 " LEFT JOIN pg_namespace collnsp ON "
3788 " collnsp.oid = collnamespace ");
3793 " format_type(atttypid, atttypmod), "
3795 " pg_get_expr(adbin, adrelid), "
3798 " JOIN pg_namespace n ON "
3799 " relnamespace = n.oid "
3800 " LEFT JOIN pg_attribute a ON "
3801 " attrelid = c.oid AND attnum > 0 "
3802 " AND NOT attisdropped "
3803 " LEFT JOIN pg_attrdef ad ON "
3804 " adrelid = c.oid AND adnum = attnum ");
3807 "WHERE c.relkind IN ('r', 'v', 'f', 'm') "
3808 " AND n.nspname = ");
3815 bool first_item =
true;
3847 for (i = 0; i < numrows;)
3850 bool first_item =
true;
3864 char *collnamespace;
3900 if (import_collate && collname !=
NULL && collnamespace !=
NULL)
3906 if (import_default && attdefault !=
NULL)
3910 if (import_not_null && attnotnull[0] ==
't')
3913 while (++i < numrows &&
3914 strcmp(
PQgetvalue(res, i, 0), tablename) == 0);
4031 foreach(lc, joinclauses)
4050 foreach(lc, otherclauses)
4114 elog(
ERROR,
"unsupported join type %d", jointype);
4183 List *useful_pathkeys_list =
NIL;
4189 foreach(lc, useful_pathkeys_list)
4198 &rows, &width, &startup_cost, &total_cost);
4272 elog(
DEBUG3,
"could not push down foreign join because a local path suitable for EPQ checks was not found");
4279 if (!
foreign_join_ok(root, joinrel, jointype, outerrel, innerrel, extra))
4325 &width, &startup_cost, &total_cost);
4327 joinrel->
rows = rows;
4329 fpinfo->
rows = rows;
4330 fpinfo->
width = width;
4371 List *retrieved_attrs,
4403 tupdesc = fdw_sstate->
tupdesc;
4407 nulls = (
bool *)
palloc(tupdesc->
natts *
sizeof(
bool));
4409 memset(nulls,
true, tupdesc->
natts *
sizeof(
bool));
4418 errcallback.
arg = (
void *) &errpos;
4426 foreach(lc, retrieved_attrs)
4442 Assert(i <= tupdesc->natts);
4443 nulls[i - 1] = (valstr ==
NULL);
4474 elog(
ERROR,
"remote query result does not match the foreign table");
4517 const char *attname =
NULL;
4547 var = (
Var *) tle->expr;
4550 rte =
rt_fetch(var->varno, estate->es_range_table);
4555 if (attname && relname)
4556 errcontext(
"column \"%s\" of foreign table \"%s\"", attname, relname);
GetForeignPlan_function GetForeignPlan
Value * makeString(char *str)
BeginForeignScan_function BeginForeignScan
ExecForeignDelete_function ExecForeignDelete
#define PG_RETURN_POINTER(x)
RelOptInfo * find_childrel_top_parent(PlannerInfo *root, RelOptInfo *rel)
EndDirectModify_function EndDirectModify
void deparseUpdateSql(StringInfo buf, PlannerInfo *root, Index rtindex, Relation rel, List *targetAttrs, List *returningList, List **retrieved_attrs)
TupleTableSlot * ExecStoreTuple(HeapTuple tuple, TupleTableSlot *slot, Buffer buffer, bool shouldFree)
Datum postgres_fdw_handler(PG_FUNCTION_ARGS)
static List * get_useful_pathkeys_for_relation(PlannerInfo *root, RelOptInfo *rel)
int PQnfields(const PGresult *res)
#define SizeofHeapTupleHeader
TupleTableSlot * ExecProcNode(PlanState *node)
#define IsA(nodeptr, _type_)
static ForeignScan * postgresGetForeignPlan(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid, ForeignPath *best_path, List *tlist, List *scan_clauses, Plan *outer_plan)
static void postgresExplainForeignModify(ModifyTableState *mtstate, ResultRelInfo *rinfo, List *fdw_private, int subplan_index, ExplainState *es)
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
void add_path(RelOptInfo *parent_rel, Path *new_path)
static List * postgresPlanForeignModify(PlannerInfo *root, ModifyTable *plan, Index resultRelation, int subplan_index)
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
ExplainForeignScan_function ExplainForeignScan
Instrumentation * instrument
int PQsendQueryParams(PGconn *conn, const char *command, int nParams, const Oid *paramTypes, const char *const *paramValues, const int *paramLengths, const int *paramFormats, int resultFormat)
const char * quote_identifier(const char *ident)
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
static bool ec_member_matches_foreign(PlannerInfo *root, RelOptInfo *rel, EquivalenceClass *ec, EquivalenceMember *em, void *arg)
static TupleTableSlot * postgresExecForeignUpdate(EState *estate, ResultRelInfo *resultRelInfo, TupleTableSlot *slot, TupleTableSlot *planSlot)
static void add_paths_with_pathkeys_for_rel(PlannerInfo *root, RelOptInfo *rel, Path *epq_path)
static HeapTuple make_tuple_from_result_row(PGresult *res, int row, Relation rel, AttInMetadata *attinmeta, List *retrieved_attrs, ForeignScanState *fsstate, MemoryContext temp_context)
void extract_actual_join_clauses(List *restrictinfo_list, List **joinquals, List **otherquals)
TupleTableSlot * ExecStoreAllNullTuple(TupleTableSlot *slot)
AttrNumber ExecFindJunkAttributeInTlist(List *targetlist, const char *attrName)
bool equal(const void *a, const void *b)
#define RelationGetDescr(relation)
AnalyzeForeignTable_function AnalyzeForeignTable
static void create_cursor(ForeignScanState *node)
const char ** param_values
#define PointerGetDatum(X)
char * PQcmdTuples(PGresult *res)
static void prepare_query_params(PlanState *node, List *fdw_exprs, int numParams, FmgrInfo **param_flinfo, List **param_exprs, const char ***param_values)
int(* AcquireSampleRowsFunc)(Relation relation, int elevel, HeapTuple *rows, int targrows, double *totalrows, double *totaldeadrows)
ExecForeignInsert_function ExecForeignInsert
bool eclass_useful_for_merging(PlannerInfo *root, EquivalenceClass *eclass, RelOptInfo *rel)
char * pstrdup(const char *in)
ExprContext * ps_ExprContext
static void postgresBeginForeignScan(ForeignScanState *node, int eflags)
PG_FUNCTION_INFO_V1(postgres_fdw_handler)
AttInMetadata * attinmeta
StringInfo makeStringInfo(void)
void deparseSelectStmtForRel(StringInfo buf, PlannerInfo *root, RelOptInfo *rel, List *tlist, List *remote_conds, List *pathkeys, List **retrieved_attrs, List **params_list)
int bms_next_member(const Bitmapset *a, int prevbit)
static List * get_useful_ecs_for_relation(PlannerInfo *root, RelOptInfo *rel)
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Form_pg_attribute * attrs
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
#define IS_OUTER_JOIN(jointype)
double sampler_random_fract(SamplerRandomState randstate)
static void process_query_params(ExprContext *econtext, FmgrInfo *param_flinfo, List *param_exprs, const char **param_values)
void classifyConditions(PlannerInfo *root, RelOptInfo *baserel, List *input_conds, List **remote_conds, List **local_conds)
int set_transmission_modes(void)
List * list_copy(const List *oldlist)
int errcode(int sqlerrcode)
ForeignTable * GetForeignTable(Oid relid)
static void store_returning_result(PgFdwModifyState *fmstate, TupleTableSlot *slot, PGresult *res)
List * list_concat(List *list1, List *list2)
PathKey * make_canonical_pathkey(PlannerInfo *root, EquivalenceClass *eclass, Oid opfamily, int strategy, bool nulls_first)
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define FirstLowInvalidHeapAttributeNumber
TupleTableSlot * ss_ScanTupleSlot
void MemoryContextReset(MemoryContext context)
EquivalenceClass * right_ec
void reservoir_init_selection_state(ReservoirState rs, int n)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
#define DirectFunctionCall1(func, arg1)
Relation ss_currentRelation
static void postgresGetForeignRelSize(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid)
void heap_freetuple(HeapTuple htup)
int PQserverVersion(const PGconn *conn)
static int postgresIsForeignRelUpdatable(Relation rel)
int PQntuples(const PGresult *res)
static bool postgresAnalyzeForeignTable(Relation relation, AcquireSampleRowsFunc *func, BlockNumber *totalpages)
struct ErrorContextCallback * previous
#define OidIsValid(objectId)
static bool foreign_join_ok(PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinPathExtraData *extra)
static void postgresExplainDirectModify(ForeignScanState *node, ExplainState *es)
static TupleTableSlot * postgresExecForeignInsert(EState *estate, ResultRelInfo *resultRelInfo, TupleTableSlot *slot, TupleTableSlot *planSlot)
static void close_cursor(PGconn *conn, unsigned int cursor_number)
ExecStatusType PQresultStatus(const PGresult *res)
void pull_varattnos(Node *node, Index varno, Bitmapset **varattnos)
#define ALLOCSET_DEFAULT_MINSIZE
AddForeignUpdateTargets_function AddForeignUpdateTargets
#define ALLOCSET_SMALL_MINSIZE
static void postgresEndDirectModify(ForeignScanState *node)
void deparseInsertSql(StringInfo buf, PlannerInfo *root, Index rtindex, Relation rel, List *targetAttrs, bool doNothing, List *returningList, List **retrieved_attrs)
unsigned int cursor_number
struct RelOptInfo ** simple_rel_array
char * OutputFunctionCall(FmgrInfo *flinfo, Datum val)
ItemPointerData * ItemPointer
ErrorContextCallback * error_context_stack
void ReleaseConnection(PGconn *conn)
static char * relname(char const *dir, char const *base)
RecheckForeignScan_function RecheckForeignScan
IterateDirectModify_function IterateDirectModify
Value * makeInteger(long i)
void ExplainPropertyText(const char *qlabel, const char *value, ExplainState *es)
static void postgresEndForeignScan(ForeignScanState *node)
bool defGetBoolean(DefElem *def)
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
void pfree(void *pointer)
MemoryContext es_query_cxt
void deparseDeleteSql(StringInfo buf, PlannerInfo *root, Index rtindex, Relation rel, List *returningList, List **retrieved_attrs)
void appendStringInfo(StringInfo str, const char *fmt,...)
ForeignScanState * fsstate
#define planner_rt_fetch(rti, root)
GetForeignJoinPaths_function GetForeignJoinPaths
const char ** param_values
bool list_member(const List *list, const void *datum)
List * list_append_unique_ptr(List *list, void *datum)
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
void fmgr_info(Oid functionId, FmgrInfo *finfo)
char * defGetString(DefElem *def)
Selectivity local_conds_sel
static List * postgresImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid)
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
#define outerPlanState(node)
void appendStringInfoString(StringInfo str, const char *s)
static void postgresBeginDirectModify(ForeignScanState *node, int eflags)
char * get_namespace_name(Oid nspid)
void * list_nth(const List *list, int n)
List * ExtractExtensionList(const char *extensionsString, bool warnOnMissing)
Selectivity joinclause_sel
ForeignPath * create_foreignscan_path(PlannerInfo *root, RelOptInfo *rel, PathTarget *target, double rows, Cost startup_cost, Cost total_cost, List *pathkeys, Relids required_outer, Path *fdw_outerpath, List *fdw_private)
void AtEOXact_GUC(bool isCommit, int nestLevel)
const char * get_jointype_name(JoinType jointype)
GetForeignRelSize_function GetForeignRelSize
EndForeignScan_function EndForeignScan
#define CStringGetDatum(X)
ExplainDirectModify_function ExplainDirectModify
#define HeapTupleHeaderSetXmax(tup, xid)
static int postgresAcquireSampleRowsFunc(Relation relation, int elevel, HeapTuple *rows, int targrows, double *totalrows, double *totaldeadrows)
#define InvalidTransactionId
#define RelationGetRelationName(relation)
FormData_pg_attribute * Form_pg_attribute
void resetStringInfo(StringInfo str)
struct PgFdwDirectModifyState PgFdwDirectModifyState
void pgfdw_report_error(int elevel, PGresult *res, PGconn *conn, bool clear, const char *sql)
MemoryContext CurrentMemoryContext
ImportForeignSchema_function ImportForeignSchema
#define list_make5(x1, x2, x3, x4, x5)
PlanForeignModify_function PlanForeignModify
static unsigned int cursor_number
AttInMetadata * attinmeta
EndForeignModify_function EndForeignModify
void deparseDirectDeleteSql(StringInfo buf, PlannerInfo *root, Index rtindex, Relation rel, List *remote_conds, List **params_list, List *returningList, List **retrieved_attrs)
#define ereport(elevel, rest)
#define rt_fetch(rangetable_index, rangetable)
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
Var * makeVar(Index varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup)
ReservoirStateData rstate
void deparseAnalyzeSql(StringInfo buf, Relation rel, List **retrieved_attrs)
List * lappend_int(List *list, int datum)
List * lappend(List *list, void *datum)
GetForeignPaths_function GetForeignPaths
Relids lateral_referencers
static bool postgresPlanDirectModify(PlannerInfo *root, ModifyTable *plan, Index resultRelation, int subplan_index)
static TupleTableSlot * postgresIterateForeignScan(ForeignScanState *node)
bool bms_is_empty(const Bitmapset *a)
PlanDirectModify_function PlanDirectModify
void appendStringInfoChar(StringInfo str, char ch)
void initStringInfo(StringInfo str)
#define ALLOCSET_SMALL_INITSIZE
char * get_relid_attribute_name(Oid relid, AttrNumber attnum)
AttInMetadata * attinmeta
static void postgresGetForeignPaths(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid)
#define AttributeNumberIsValid(attributeNumber)
TupleDesc tts_tupleDescriptor
BeginDirectModify_function BeginDirectModify
void deparseStringLiteral(StringInfo buf, const char *val)
MemoryContext AllocSetContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
void * palloc0(Size size)
ForeignServer * GetForeignServer(Oid serverid)
static void conversion_error_callback(void *arg)
void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel)
AttInMetadata * TupleDescGetAttInMetadata(TupleDesc tupdesc)
Relation heap_open(Oid relationId, LOCKMODE lockmode)
static TupleTableSlot * get_returning_data(ForeignScanState *node)
Datum InputFunctionCall(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod)
bool list_member_ptr(const List *list, const void *datum)
void PQclear(PGresult *res)
ExecForeignUpdate_function ExecForeignUpdate
struct ConversionLocation ConversionLocation
static TupleTableSlot * postgresExecForeignDelete(EState *estate, ResultRelInfo *resultRelInfo, TupleTableSlot *slot, TupleTableSlot *planSlot)
PGconn * GetConnection(UserMapping *user, bool will_prep_stmt)
TupleTableSlot * ExecCopySlot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
PGresult * pgfdw_get_result(PGconn *conn, const char *query)
Datum tidin(PG_FUNCTION_ARGS)
static void estimate_path_cost_size(PlannerInfo *root, RelOptInfo *baserel, List *join_conds, List *pathkeys, double *p_rows, int *p_width, Cost *p_startup_cost, Cost *p_total_cost)
Expr * find_em_expr_for_rel(EquivalenceClass *ec, RelOptInfo *rel)
#define Assert(condition)
ReScanForeignScan_function ReScanForeignScan
static const char ** convert_prep_stmt_params(PgFdwModifyState *fmstate, ItemPointer tupleid, TupleTableSlot *slot)
OnConflictAction onConflictAction
static void fetch_more_data(ForeignScanState *node)
IterateForeignScan_function IterateForeignScan
Path * GetExistingLocalJoinPath(RelOptInfo *joinrel)
struct PgFdwScanState PgFdwScanState
EquivalenceClass * pk_eclass
void deparseAnalyzeSizeSql(StringInfo buf, Relation rel)
#define DEFAULT_FDW_SORT_MULTIPLIER
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
unsigned int GetCursorNumber(PGconn *conn)
void reset_transmission_modes(int nestlevel)
Oid exprType(const Node *expr)
static int list_length(const List *l)
List * extract_actual_clauses(List *restrictinfo_list, bool pseudoconstant)
ForeignScan * make_foreignscan(List *qptlist, List *qpqual, Index scanrelid, List *fdw_exprs, List *fdw_private, List *fdw_scan_tlist, List *fdw_recheck_quals, Plan *outer_plan)
#define InvalidAttrNumber
int PQsendQueryPrepared(PGconn *conn, const char *stmtName, int nParams, const char *const *paramValues, const int *paramLengths, const int *paramFormats, int resultFormat)
static bool postgresRecheckForeignScan(ForeignScanState *node, TupleTableSlot *slot)
#define DatumGetPointer(X)
bool join_clause_is_movable_to(RestrictInfo *rinfo, RelOptInfo *baserel)
static void postgresExplainForeignScan(ForeignScanState *node, ExplainState *es)
#define list_make4(x1, x2, x3, x4)
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
static Datum values[MAXATTR]
static void get_remote_estimate(const char *sql, PGconn *conn, double *rows, int *width, Cost *startup_cost, Cost *total_cost)
int NewGUCNestLevel(void)
List * build_tlist_to_deparse(RelOptInfo *foreignrel)
void(* callback)(void *arg)
static void postgresBeginForeignModify(ModifyTableState *mtstate, ResultRelInfo *resultRelInfo, List *fdw_private, int subplan_index, int eflags)
static void prepare_foreign_modify(PgFdwModifyState *fmstate)
#define ALLOCSET_SMALL_MAXSIZE
EquivalenceClass * left_ec
int errmsg(const char *fmt,...)
static void analyze_row_processor(PGresult *res, int row, PgFdwAnalyzeState *astate)
void deparseDirectUpdateSql(StringInfo buf, PlannerInfo *root, Index rtindex, Relation rel, List *targetlist, List *targetAttrs, List *remote_conds, List **params_list, List *returningList, List **retrieved_attrs)
FdwDirectModifyPrivateIndex
Datum ExecGetJunkAttribute(TupleTableSlot *slot, AttrNumber attno, bool *isNull)
ExplainForeignModify_function ExplainForeignModify
static void postgresAddForeignUpdateTargets(Query *parsetree, RangeTblEntry *target_rte, Relation target_relation)
bool is_foreign_expr(PlannerInfo *root, RelOptInfo *baserel, Expr *expr)
#define ALLOCSET_DEFAULT_INITSIZE
UserMapping * GetUserMappingById(Oid umid)
static void postgresEndForeignModify(EState *estate, ResultRelInfo *resultRelInfo)
struct PgFdwModifyState PgFdwModifyState
TargetEntry * get_tle_by_resno(List *tlist, AttrNumber resno)
Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
IsForeignRelUpdatable_function IsForeignRelUpdatable
UserMapping * GetUserMapping(Oid userid, Oid serverid)
static TupleTableSlot * postgresIterateDirectModify(ForeignScanState *node)
AttInMetadata * attinmeta
static void execute_dml_stmt(ForeignScanState *node)
#define ALLOCSET_DEFAULT_MAXSIZE
#define CHECK_FOR_INTERRUPTS()
#define SelfItemPointerAttributeNumber
#define DEFAULT_FDW_STARTUP_COST
unsigned int GetPrepStmtNumber(PGconn *conn)
Selectivity clauselist_selectivity(PlannerInfo *root, List *clauses, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo)
List * list_delete(List *list, void *datum)
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
#define BTLessStrategyNumber
static void postgresGetForeignJoinPaths(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, JoinPathExtraData *extra)
BeginForeignModify_function BeginForeignModify
struct PgFdwAnalyzeState PgFdwAnalyzeState
double clamp_row_est(double nrows)
List * shippable_extensions
Bitmapset * bms_del_member(Bitmapset *a, int x)
int set_config_option(const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
PGresult * pgfdw_exec_query(PGconn *conn, const char *query)
char * get_rel_name(Oid relid)
struct PathTarget * reltarget
#define EXEC_FLAG_EXPLAIN_ONLY
#define RelationGetRelid(relation)
QualCost baserestrictcost
void update_mergeclause_eclasses(PlannerInfo *root, RestrictInfo *restrictinfo)
static void postgresReScanForeignScan(ForeignScanState *node)
#define HeapTupleHeaderSetCmin(tup, cid)
#define DEFAULT_FDW_TUPLE_COST
int PQsendPrepare(PGconn *conn, const char *stmtName, const char *query, int nParams, const Oid *paramTypes)
QualCost local_conds_cost
SamplerRandomState randstate
double reservoir_get_next_S(ReservoirState rs, double t, int n)
List * generate_implied_equalities_for_column(PlannerInfo *root, RelOptInfo *rel, ec_matches_callback_type callback, void *callback_arg, Relids prohibited_rels)
#define INTSTYLE_POSTGRES
ImportForeignSchemaType list_type
#define ExecEvalExpr(expr, econtext, isNull, isDone)
#define HeapTupleHeaderSetXmin(tup, xid)