diff options
author | Etsuro Fujita <efujita@postgresql.org> | 2023-08-15 16:45:00 +0900 |
---|---|---|
committer | Etsuro Fujita <efujita@postgresql.org> | 2023-08-15 16:45:00 +0900 |
commit | 9e9931d2bf40e2fea447d779c2e133c2c1256ef3 (patch) | |
tree | 33ece047786463ecd497cdd8178ca51e5f65c200 /src/backend/optimizer/plan/createplan.c | |
parent | 5ffb7c775062ef18756e515ac96f06d012cbb950 (diff) | |
download | postgresql-9e9931d2bf40e2fea447d779c2e133c2c1256ef3.tar.gz postgresql-9e9931d2bf40e2fea447d779c2e133c2c1256ef3.zip |
Re-allow FDWs and custom scan providers to replace joins with pseudoconstant quals.
This was disabled in commit 6f80a8d9c due to the lack of support for
handling of pseudoconstant quals assigned to replaced joins in
createplan.c. To re-allow it, this patch adds the support by 1)
modifying the ForeignPath and CustomPath structs so that if they
represent foreign and custom scans replacing a join with a scan, they
store the list of RestrictInfo nodes to apply to the join, as in
JoinPaths, and by 2) modifying create_scan_plan() in createplan.c so
that it uses that list in that case, instead of the baserestrictinfo
list, to get pseudoconstant quals assigned to the join, as mentioned in
the commit message for that commit.
Important item for the release notes: this is non-backwards-compatible
since it modifies the ForeignPath and CustomPath structs, as mentioned
above, and changes the argument lists for FDW helper functions
create_foreignscan_path(), create_foreign_join_path(), and
create_foreign_upper_path().
Richard Guo, with some additional changes by me, reviewed by Nishant
Sharma, Suraj Kharage, and Richard Guo.
Discussion: https://postgr.es/m/CADrsxdbcN1vejBaf8a%2BQhrZY5PXL-04mCd4GDu6qm6FigDZd6Q%40mail.gmail.com
Diffstat (limited to 'src/backend/optimizer/plan/createplan.c')
-rw-r--r-- | src/backend/optimizer/plan/createplan.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c index af48109058d..34ca6d4ac21 100644 --- a/src/backend/optimizer/plan/createplan.c +++ b/src/backend/optimizer/plan/createplan.c @@ -599,8 +599,27 @@ create_scan_plan(PlannerInfo *root, Path *best_path, int flags) * Detect whether we have any pseudoconstant quals to deal with. Then, if * we'll need a gating Result node, it will be able to project, so there * are no requirements on the child's tlist. + * + * If this replaces a join, it must be a foreign scan or a custom scan, + * and the FDW or the custom scan provider would have stored in the best + * path the list of RestrictInfo nodes to apply to the join; check against + * that list in that case. */ - gating_clauses = get_gating_quals(root, scan_clauses); + if (IS_JOIN_REL(rel)) + { + List *join_clauses; + + Assert(best_path->pathtype == T_ForeignScan || + best_path->pathtype == T_CustomScan); + if (best_path->pathtype == T_ForeignScan) + join_clauses = ((ForeignPath *) best_path)->fdw_restrictinfo; + else + join_clauses = ((CustomPath *) best_path)->custom_restrictinfo; + + gating_clauses = get_gating_quals(root, join_clauses); + } + else + gating_clauses = get_gating_quals(root, scan_clauses); if (gating_clauses) flags = 0; |