|
24 | 24 | #include "optimizer/pathnode.h"
|
25 | 25 | #include "optimizer/paths.h"
|
26 | 26 | #include "optimizer/planmain.h"
|
| 27 | +#include "optimizer/restrictinfo.h" |
27 | 28 | #include "utils/typcache.h"
|
28 | 29 |
|
29 | 30 | /* Hook for plugins to get control in add_paths_to_joinrel() */
|
@@ -130,6 +131,7 @@ add_paths_to_joinrel(PlannerInfo *root,
|
130 | 131 | {
|
131 | 132 | JoinPathExtraData extra;
|
132 | 133 | bool mergejoin_allowed = true;
|
| 134 | + bool consider_join_pushdown = false; |
133 | 135 | ListCell *lc;
|
134 | 136 | Relids joinrelids;
|
135 | 137 |
|
@@ -321,21 +323,34 @@ add_paths_to_joinrel(PlannerInfo *root,
|
321 | 323 | hash_inner_and_outer(root, joinrel, outerrel, innerrel,
|
322 | 324 | jointype, &extra);
|
323 | 325 |
|
| 326 | + /* |
| 327 | + * createplan.c does not currently support handling of pseudoconstant |
| 328 | + * clauses assigned to joins pushed down by extensions; check if the |
| 329 | + * restrictlist has such clauses, and if so, disallow pushing down joins. |
| 330 | + */ |
| 331 | + if ((joinrel->fdwroutine && |
| 332 | + joinrel->fdwroutine->GetForeignJoinPaths) || |
| 333 | + set_join_pathlist_hook) |
| 334 | + consider_join_pushdown = !has_pseudoconstant_clauses(root, |
| 335 | + restrictlist); |
| 336 | + |
324 | 337 | /*
|
325 | 338 | * 5. If inner and outer relations are foreign tables (or joins) belonging
|
326 | 339 | * to the same server and assigned to the same user to check access
|
327 | 340 | * permissions as, give the FDW a chance to push down joins.
|
328 | 341 | */
|
329 | 342 | if (joinrel->fdwroutine &&
|
330 |
| - joinrel->fdwroutine->GetForeignJoinPaths) |
| 343 | + joinrel->fdwroutine->GetForeignJoinPaths && |
| 344 | + consider_join_pushdown) |
331 | 345 | joinrel->fdwroutine->GetForeignJoinPaths(root, joinrel,
|
332 | 346 | outerrel, innerrel,
|
333 | 347 | jointype, &extra);
|
334 | 348 |
|
335 | 349 | /*
|
336 | 350 | * 6. Finally, give extensions a chance to manipulate the path list.
|
337 | 351 | */
|
338 |
| - if (set_join_pathlist_hook) |
| 352 | + if (set_join_pathlist_hook && |
| 353 | + consider_join_pushdown) |
339 | 354 | set_join_pathlist_hook(root, joinrel, outerrel, innerrel,
|
340 | 355 | jointype, &extra);
|
341 | 356 | }
|
|
0 commit comments