aboutsummaryrefslogtreecommitdiff
path: root/contrib/postgres_fdw/postgres_fdw.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2016-01-30 10:32:38 -0500
committerRobert Haas <rhaas@postgresql.org>2016-01-30 10:32:38 -0500
commitcc592c48c58d9c1920f8e2063756dcbcce79e4dd (patch)
treeb3c640bb4c286ffc04bae290a6f84c24e4ee83bc /contrib/postgres_fdw/postgres_fdw.c
parent2251179e6ad3a865d2f55e1832fab34608fcce43 (diff)
downloadpostgresql-cc592c48c58d9c1920f8e2063756dcbcce79e4dd.tar.gz
postgresql-cc592c48c58d9c1920f8e2063756dcbcce79e4dd.zip
postgres_fdw: More preliminary refactoring for upcoming join pushdown.
The code that generates a complete SQL query for a given foreign relation was repeated in two places, and they didn't quite agree: the EXPLAIN case left out the locking clause. Centralize the code so we get the same behavior everywhere, and adjust calling conventions and which functions are static vs. extern accordingly . Centralize the code so we get the same behavior everywhere, and adjust calling conventions and which functions are static vs. extern accordingly. Ashutosh Bapat, reviewed and slightly adjusted by me.
Diffstat (limited to 'contrib/postgres_fdw/postgres_fdw.c')
-rw-r--r--contrib/postgres_fdw/postgres_fdw.c38
1 files changed, 14 insertions, 24 deletions
diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c
index 0aa7fbeac04..2ab85f68a75 100644
--- a/contrib/postgres_fdw/postgres_fdw.c
+++ b/contrib/postgres_fdw/postgres_fdw.c
@@ -1003,19 +1003,9 @@ postgresGetForeignPlan(PlannerInfo *root,
* expressions to be sent as parameters.
*/
initStringInfo(&sql);
- deparseSelectSql(&sql, root, baserel, fpinfo->attrs_used,
- &retrieved_attrs);
- if (remote_conds)
- appendWhereClause(&sql, root, baserel, remote_conds,
- true, &params_list);
-
- /* Add ORDER BY clause if we found any useful pathkeys */
- if (best_path->path.pathkeys)
- appendOrderByClause(&sql, root, baserel, best_path->path.pathkeys);
-
- /* Add any necessary FOR UPDATE/SHARE. */
- deparseLockingClause(&sql, root, baserel);
-
+ deparseSelectStmtForRel(&sql, root, baserel, remote_conds,
+ best_path->path.pathkeys, &retrieved_attrs,
+ &params_list);
/*
* Build the fdw_private list that will be available to the executor.
* Items in the list must match enum FdwScanPrivateIndex, above.
@@ -1909,6 +1899,7 @@ estimate_path_cost_size(PlannerInfo *root,
PGconn *conn;
Selectivity local_sel;
QualCost local_cost;
+ List *remote_conds;
/*
* join_conds might contain both clauses that are safe to send across,
@@ -1918,23 +1909,22 @@ estimate_path_cost_size(PlannerInfo *root,
&remote_join_conds, &local_join_conds);
/*
+ * The complete list of remote conditions includes everything from
+ * baserestrictinfo plus any extra join_conds relevant to this
+ * particular path.
+ */
+ remote_conds = list_concat(list_copy(remote_join_conds),
+ fpinfo->remote_conds);
+
+ /*
* Construct EXPLAIN query including the desired SELECT, FROM, and
* WHERE clauses. Params and other-relation Vars are replaced by
* dummy values.
*/
initStringInfo(&sql);
appendStringInfoString(&sql, "EXPLAIN ");
- deparseSelectSql(&sql, root, baserel, fpinfo->attrs_used,
- &retrieved_attrs);
- if (fpinfo->remote_conds)
- appendWhereClause(&sql, root, baserel, fpinfo->remote_conds,
- true, NULL);
- if (remote_join_conds)
- appendWhereClause(&sql, root, baserel, remote_join_conds,
- (fpinfo->remote_conds == NIL), NULL);
-
- if (pathkeys)
- appendOrderByClause(&sql, root, baserel, pathkeys);
+ deparseSelectStmtForRel(&sql, root, baserel, remote_conds, pathkeys,
+ &retrieved_attrs, NULL);
/* Get the remote estimate */
conn = GetConnection(fpinfo->user, false);