summaryrefslogtreecommitdiff
path: root/src/backend/optimizer/plan/createplan.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2016-01-28 14:05:36 -0500
committerRobert Haas <rhaas@postgresql.org>2016-01-28 14:05:36 -0500
commitfbe5a3fb73102c2cfec11aaaa4a67943f4474383 (patch)
tree44b327ff5aaceb5a20346ee4c914914450e51368 /src/backend/optimizer/plan/createplan.c
parent2f6b041f76e6de0fa2921131a23bda794ffb83bb (diff)
Only try to push down foreign joins if the user mapping OIDs match.
Previously, the foreign join pushdown infrastructure left the question of security entirely up to individual FDWs, but it would be easy for a foreign data wrapper to inadvertently open up subtle security holes that way. So, make it the core code's job to determine which user mapping OID is relevant, and don't attempt join pushdown unless it's the same for all relevant relations. Per a suggestion from Tom Lane. Shigeru Hanada and Ashutosh Bapat, reviewed by Etsuro Fujita and KaiGai Kohei, with some further changes by me.
Diffstat (limited to 'src/backend/optimizer/plan/createplan.c')
-rw-r--r--src/backend/optimizer/plan/createplan.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index fda4df64210..bdac0b1860b 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -2152,6 +2152,15 @@ create_foreignscan_plan(PlannerInfo *root, ForeignPath *best_path,
scan_plan->fs_relids = best_path->path.parent->relids;
/*
+ * If a join between foreign relations was pushed down, remember it. The
+ * push-down safety of the join depends upon the server and user mapping
+ * being same. That can change between planning and execution time, in which
+ * case the plan should be invalidated.
+ */
+ if (scan_relid == 0)
+ root->glob->hasForeignJoin = true;
+
+ /*
* Replace any outer-relation variables with nestloop params in the qual,
* fdw_exprs and fdw_recheck_quals expressions. We do this last so that
* the FDW doesn't have to be involved. (Note that parts of fdw_exprs