Fix EvalPlanQual handling of foreign/custom joins in ExecScanFetch. REL_15_STABLE github/REL_15_STABLE
authorEtsuro Fujita <efujita@postgresql.org>
Wed, 15 Oct 2025 08:15:04 +0000 (17:15 +0900)
committerEtsuro Fujita <efujita@postgresql.org>
Wed, 15 Oct 2025 08:15:04 +0000 (17:15 +0900)
commit4a08603a232265b2ecd0595e80a15af3e92b04c8
tree6b6399856f6ec741d4b2728b4c3082df80626db8
parentf91666c836dd8915f0ee67a90c5d76e10bfde838
Fix EvalPlanQual handling of foreign/custom joins in ExecScanFetch.

If inside an EPQ recheck, ExecScanFetch would run the recheck method
function for foreign/custom joins even if they aren't descendant nodes
in the EPQ recheck plan tree, which is problematic at least in the
foreign-join case, because such a foreign join isn't guaranteed to have
an alternative local-join plan required for running the recheck method
function; in the postgres_fdw case this could lead to a segmentation
fault or an assert failure in an assert-enabled build when running the
recheck method function.

Even if inside an EPQ recheck, any scan nodes that aren't descendant
ones in the EPQ recheck plan tree should be normally processed by using
the access method function; fix by modifying ExecScanFetch so that if
inside an EPQ recheck, it runs the recheck method function for
foreign/custom joins that are descendant nodes in the EPQ recheck plan
tree as before and runs the access method function for foreign/custom
joins that aren't.

This fix also adds to postgres_fdw an isolation test for an EPQ recheck
that caused issues stated above.

Oversight in commit 385f337c9.

Reported-by: Kristian Lejao <kristianlejao@gmail.com>
Author: Masahiko Sawada <sawada.mshk@gmail.com>
Co-authored-by: Etsuro Fujita <etsuro.fujita@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Etsuro Fujita <etsuro.fujita@gmail.com>
Discussion: https://postgr.es/m/CAD21AoBpo6Gx55FBOW+9s5X=nUw3Xpq64v35fpDEKsTERnc4TQ@mail.gmail.com
Backpatch-through: 13
contrib/postgres_fdw/.gitignore
contrib/postgres_fdw/Makefile
contrib/postgres_fdw/expected/eval_plan_qual.out [new file with mode: 0644]
contrib/postgres_fdw/specs/eval_plan_qual.spec [new file with mode: 0644]
src/backend/executor/execScan.c