44 #define DEFAULT_FDW_STARTUP_COST 100.0
47 #define DEFAULT_FDW_TUPLE_COST 0.01
259 Index resultRelation,
298 double *p_rows,
int *p_width,
299 Cost *p_startup_cost,
Cost *p_total_cost);
321 double *totaldeadrows);
328 List *retrieved_attrs,
409 if (strcmp(def->
defname,
"use_remote_estimate") == 0)
411 else if (strcmp(def->
defname,
"fdw_startup_cost") == 0)
413 else if (strcmp(def->
defname,
"fdw_tuple_cost") == 0)
420 if (strcmp(def->
defname,
"use_remote_estimate") == 0)
600 &startup_cost, &total_cost);
609 required_outer =
NULL;
676 &startup_cost, &total_cost);
683 required_outer =
NULL;
719 List *retrieved_attrs;
743 foreach(lc, scan_clauses)
754 remote_conds =
lappend(remote_conds, rinfo);
760 remote_conds =
lappend(remote_conds, rinfo);
879 userid = rte->checkAsUser ? rte->checkAsUser :
GetUserId();
895 fsstate->cursor_exists =
false;
905 "postgres_fdw tuple data",
910 "postgres_fdw temporary data",
920 fsstate->numParams = numParams;
931 fmgr_info(typefnoid, &fsstate->param_flinfo[
i]);
943 fsstate->param_exprs = (
List *)
951 fsstate->param_values = (
const char **)
palloc0(numParams *
sizeof(
char *));
953 fsstate->param_values =
NULL;
1022 snprintf(sql,
sizeof(sql),
"CLOSE c%u",
1027 snprintf(sql,
sizeof(sql),
"MOVE BACKWARD ALL IN c%u",
1064 if (fsstate ==
NULL)
1088 const char *attrname;
1129 Index resultRelation,
1160 for (attnum = 1; attnum <= tupdesc->
natts; attnum++)
1164 if (!attr->attisdropped)
1177 elog(
ERROR,
"system-column update is not supported");
1195 targetAttrs, returningList,
1200 targetAttrs, returningList,
1209 elog(
ERROR,
"unexpected operation: %d", (
int) operation);
1289 "postgres_fdw temporary data",
1311 elog(
ERROR,
"could not find junk ctid column");
1327 Assert(!attr->attisdropped);
1351 const char **p_values;
1395 return (n_rows > 0) ? slot :
NULL;
1411 const char **p_values;
1465 return (n_rows > 0) ? slot :
NULL;
1481 const char **p_values;
1535 return (n_rows > 0) ? slot :
NULL;
1549 if (fmstate ==
NULL)
1603 if (strcmp(def->
defname,
"updatable") == 0)
1610 if (strcmp(def->
defname,
"updatable") == 0)
1671 double *p_rows,
int *p_width,
1672 Cost *p_startup_cost,
Cost *p_total_cost)
1676 double retrieved_rows;
1693 List *retrieved_attrs;
1715 &startup_cost, &total_cost);
1718 retrieved_rows = rows;
1736 rows = baserel->
rows;
1737 width = baserel->
width;
1744 retrieved_rows =
Min(retrieved_rows, baserel->
tuples);
1757 run_cost += cpu_per_tuple * baserel->
tuples;
1759 total_cost = startup_cost + run_cost;
1776 *p_startup_cost = startup_cost;
1777 *p_total_cost = total_cost;
1786 double *rows,
int *width,
1787 Cost *startup_cost,
Cost *total_cost)
1811 p = strrchr(line,
'(');
1813 elog(
ERROR,
"could not interpret EXPLAIN output: \"%s\"", line);
1814 n = sscanf(p,
"(cost=%lf..%lf rows=%lf width=%d)",
1815 startup_cost, total_cost, rows, width);
1817 elog(
ERROR,
"could not interpret EXPLAIN output: \"%s\"", line);
1982 snprintf(sql,
sizeof(sql),
"FETCH %d FROM c%u",
1996 for (i = 0; i < numrows; i++)
2086 snprintf(sql,
sizeof(sql),
"CLOSE c%u", cursor_number);
2110 snprintf(prep_name,
sizeof(prep_name),
"pgsql_fdw_prep_%u",
2135 fmstate->
p_name = p_name;
2147 static const char **
2152 const char **p_values;
2158 p_values = (
const char **)
palloc(
sizeof(
char *) * fmstate->
p_nums);
2161 if (tupleid !=
NULL)
2185 p_values[pindex] =
NULL;
2284 elog(
ERROR,
"unexpected result from deparseAnalyzeSizeSql query");
2323 double *totaldeadrows)
2335 astate.
rel = relation;
2348 "postgres_fdw temporary data",
2400 snprintf(fetch_sql,
sizeof(fetch_sql),
"FETCH %d FROM c%u",
2401 fetch_size, cursor_number);
2403 res =
PQexec(conn, fetch_sql);
2410 for (i = 0; i < numrows; i++)
2417 if (numrows < fetch_size)
2435 *totaldeadrows = 0.0;
2444 (
errmsg(
"\"%s\": table contains %.0f rows, %d rows in sample",
2470 if (astate->
numrows < targrows)
2490 Assert(pos >= 0 && pos < targrows);
2533 List *retrieved_attrs,
2557 nulls = (
bool *)
palloc(tupdesc->
natts *
sizeof(
bool));
2559 memset(nulls,
true, tupdesc->
natts *
sizeof(
bool));
2567 errcallback.
arg = (
void *) &errpos;
2575 foreach(lc, retrieved_attrs)
2590 Assert(i <= tupdesc->natts);
2591 nulls[i - 1] = (valstr ==
NULL);
2623 elog(
ERROR,
"remote query result does not match the foreign table");
2652 errcontext(
"column \"%s\" of foreign table \"%s\"",