summaryrefslogtreecommitdiff
path: root/contrib/postgres_fdw/specs
diff options
context:
space:
mode:
authorEtsuro Fujita <efujita@postgresql.org>2025-10-15 17:15:00 +0900
committerEtsuro Fujita <efujita@postgresql.org>2025-10-15 17:15:00 +0900
commit12609fbacb007698ec91101b6464436506518346 (patch)
tree0331d928cd3ded4bf8fec2bada7b4a3e7514ce68 /contrib/postgres_fdw/specs
parent29dc7a668753acee03a3140f541ae6de974244bc (diff)
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
Diffstat (limited to 'contrib/postgres_fdw/specs')
-rw-r--r--contrib/postgres_fdw/specs/eval_plan_qual.spec55
1 files changed, 55 insertions, 0 deletions
diff --git a/contrib/postgres_fdw/specs/eval_plan_qual.spec b/contrib/postgres_fdw/specs/eval_plan_qual.spec
new file mode 100644
index 00000000000..30a83e04058
--- /dev/null
+++ b/contrib/postgres_fdw/specs/eval_plan_qual.spec
@@ -0,0 +1,55 @@
+# Tests for the EvalPlanQual mechanism involving foreign tables
+
+setup
+{
+ DO $d$
+ BEGIN
+ EXECUTE $$CREATE SERVER loopback FOREIGN DATA WRAPPER postgres_fdw
+ OPTIONS (dbname '$$||current_database()||$$',
+ port '$$||current_setting('port')||$$'
+ )$$;
+ END;
+ $d$;
+ CREATE USER MAPPING FOR PUBLIC SERVER loopback;
+
+ CREATE TABLE a (i int);
+ CREATE TABLE b (i int);
+ CREATE TABLE c (i int);
+ CREATE FOREIGN TABLE fb (i int) SERVER loopback OPTIONS (table_name 'b');
+ CREATE FOREIGN TABLE fc (i int) SERVER loopback OPTIONS (table_name 'c');
+
+ INSERT INTO a VALUES (1);
+ INSERT INTO b VALUES (1);
+ INSERT INTO c VALUES (1);
+}
+
+teardown
+{
+ DROP TABLE a;
+ DROP TABLE b;
+ DROP TABLE c;
+ DROP SERVER loopback CASCADE;
+}
+
+session s0
+step s0_begin { BEGIN ISOLATION LEVEL READ COMMITTED; }
+step s0_update { UPDATE a SET i = i + 1; }
+step s0_commit { COMMIT; }
+
+session s1
+step s1_begin { BEGIN ISOLATION LEVEL READ COMMITTED; }
+step s1_tuplock {
+ -- Verify if the sub-select has a foreign-join plan
+ EXPLAIN (VERBOSE, COSTS OFF)
+ SELECT a.i,
+ (SELECT 1 FROM fb, fc WHERE a.i = fb.i AND fb.i = fc.i)
+ FROM a FOR UPDATE;
+ SELECT a.i,
+ (SELECT 1 FROM fb, fc WHERE a.i = fb.i AND fb.i = fc.i)
+ FROM a FOR UPDATE;
+}
+step s1_commit { COMMIT; }
+
+# This test exercises EvalPlanQual with a SubLink sub-select (which should
+# be unaffected by any EPQ recheck behavior in the outer query).
+permutation s0_begin s0_update s1_begin s1_tuplock s0_commit s1_commit