Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 83204e1

Browse files
committed
Fix contrib/postgres_fdw to handle multiple join conditions properly.
The previous coding supposed that it could consider just a single join condition in any one parameterized path for the foreign table. But in reality, the parameterized-path machinery forces all join clauses that are "movable to" the foreign table to be evaluated at that node; including clauses that we might not consider safe to send across. Such cases would result in an Assert failure in an assert-enabled build, and otherwise in sending an unsafe clause to the foreign server, which might result in errors or silently-wrong answers. A lesser problem was that the cost/rowcount estimates generated for the parameterized path failed to account for any additional join quals that get assigned to the scan. To fix, rewrite postgresGetForeignPaths so that it correctly collects all the movable quals for any one outer relation when generating parameterized paths; we'll now generate just one path per outer relation not one per join qual. Also fix bogus assumptions in postgresGetForeignPlan and estimate_path_cost_size that only safe-to-send join quals will be presented. Based on complaint from Etsuro Fujita that the path costs were being miscalculated, though this is significantly different from his proposed patch.
1 parent 4ea2e2d commit 83204e1

File tree

5 files changed

+252
-71
lines changed

5 files changed

+252
-71
lines changed

contrib/postgres_fdw/deparse.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,15 @@ static void deparseArrayExpr(ArrayExpr *node, deparse_expr_cxt *context);
134134

135135

136136
/*
137-
* Examine each restriction clause in baserel's baserestrictinfo list,
138-
* and classify them into two groups, which are returned as two lists:
137+
* Examine each qual clause in input_conds, and classify them into two groups,
138+
* which are returned as two lists:
139139
* - remote_conds contains expressions that can be evaluated remotely
140140
* - local_conds contains expressions that can't be evaluated remotely
141141
*/
142142
void
143143
classifyConditions(PlannerInfo *root,
144144
RelOptInfo *baserel,
145+
List *input_conds,
145146
List **remote_conds,
146147
List **local_conds)
147148
{
@@ -150,7 +151,7 @@ classifyConditions(PlannerInfo *root,
150151
*remote_conds = NIL;
151152
*local_conds = NIL;
152153

153-
foreach(lc, baserel->baserestrictinfo)
154+
foreach(lc, input_conds)
154155
{
155156
RestrictInfo *ri = (RestrictInfo *) lfirst(lc);
156157

0 commit comments

Comments
 (0)