diff options
author | Etsuro Fujita <efujita@postgresql.org> | 2023-07-28 15:45:08 +0900 |
---|---|---|
committer | Etsuro Fujita <efujita@postgresql.org> | 2023-07-28 15:45:08 +0900 |
commit | 9edf72aa76441716ce62d1f1787988e160da8115 (patch) | |
tree | e7d773d1274cb0d1393d7ea6e37333372b926342 /src/backend/optimizer/util/restrictinfo.c | |
parent | 0660f74e861d0dc942af3e0b5f88cb2f0c72aee5 (diff) | |
download | postgresql-9edf72aa76441716ce62d1f1787988e160da8115.tar.gz postgresql-9edf72aa76441716ce62d1f1787988e160da8115.zip |
Disallow replacing joins with scans in problematic cases.
Commit e7cb7ee14, which introduced the infrastructure for FDWs and
custom scan providers to replace joins with scans, failed to add support
handling of pseudoconstant quals assigned to replaced joins in
createplan.c, leading to an incorrect plan without a gating Result node
when postgres_fdw replaced a join with such a qual.
To fix, we could add the support by 1) modifying the ForeignPath and
CustomPath structs to store the list of RestrictInfo nodes to apply to
the join, as in JoinPaths, if they represent foreign and custom scans
replacing a join with a scan, and by 2) modifying create_scan_plan() in
createplan.c to use that list in that case, instead of the
baserestrictinfo list, to get pseudoconstant quals assigned to the join;
but #1 would cause an ABI break. So fix by modifying the infrastructure
to just disallow replacing joins with such quals.
Back-patch to all supported branches.
Reported by Nishant Sharma. Patch by me, reviewed by Nishant Sharma and
Richard Guo.
Discussion: https://postgr.es/m/CADrsxdbcN1vejBaf8a%2BQhrZY5PXL-04mCd4GDu6qm6FigDZd6Q%40mail.gmail.com
Diffstat (limited to 'src/backend/optimizer/util/restrictinfo.c')
-rw-r--r-- | src/backend/optimizer/util/restrictinfo.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/backend/optimizer/util/restrictinfo.c b/src/backend/optimizer/util/restrictinfo.c index 2c3a6f2cf7c..e54580947c8 100644 --- a/src/backend/optimizer/util/restrictinfo.c +++ b/src/backend/optimizer/util/restrictinfo.c @@ -509,6 +509,35 @@ extract_actual_join_clauses(List *restrictinfo_list, } } +/* + * has_pseudoconstant_clauses + * + * Returns true if 'restrictinfo_list' includes pseudoconstant clauses. + * + * This is used when we determine whether to allow extensions to consider + * pushing down joins in add_paths_to_joinrel(). + */ +bool +has_pseudoconstant_clauses(PlannerInfo *root, + List *restrictinfo_list) +{ + ListCell *l; + + /* No need to look if we know there are no pseudoconstants */ + if (!root->hasPseudoConstantQuals) + return false; + + /* See if there are pseudoconstants in the RestrictInfo list */ + foreach(l, restrictinfo_list) + { + RestrictInfo *rinfo = lfirst_node(RestrictInfo, l); + + if (rinfo->pseudoconstant) + return true; + } + return false; +} + /* * join_clause_is_movable_to |