Disallow replacing joins with scans in problematic cases.
authorEtsuro Fujita <efujita@postgresql.org>
Fri, 28 Jul 2023 06:45:06 +0000 (15:45 +0900)
committerEtsuro Fujita <efujita@postgresql.org>
Fri, 28 Jul 2023 06:45:06 +0000 (15:45 +0900)
commit730f983effa51f578e85db27a5b4b906725ecd7a
tree9a7a02ee9707ca1612391daceccc1fa39f8722f7
parent288b4288c3db3af24404cf6d4c1d9d5a9c9c1922
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
contrib/postgres_fdw/expected/postgres_fdw.out
contrib/postgres_fdw/sql/postgres_fdw.sql
src/backend/optimizer/path/joinpath.c
src/backend/optimizer/util/restrictinfo.c
src/include/optimizer/restrictinfo.h