From 3aea74f631fee1a2950af15e54711a989d734e6f Mon Sep 17 00:00:00 2001
From: Amit Langote <amitlan@postgresql.org>
Date: Wed, 23 Sep 2026 17:46:11 +0900
Subject: [PATCH] Simplify RI fast-path active-snapshot regression test

The test added by 1390182683 reached the per-row fast path through
another FK's cast, which was needed only to get past batching.  Since
25649d6e79 removed batching, insert into the referencing table directly
and drop that scaffolding.  The simplified test still covers the
1390182683 fix; it fails without the PushActiveSnapshot() added there.

REL_19_STABLE only; master retains the batching.

Discussion: https://postgr.es/m/
---
 src/test/regress/expected/foreign_key.out | 19 +++----------------
 src/test/regress/sql/foreign_key.sql      | 20 +++-----------------
 2 files changed, 6 insertions(+), 33 deletions(-)

diff --git a/src/test/regress/expected/foreign_key.out b/src/test/regress/expected/foreign_key.out
index d0c93ac8744..8ef1f38dcfb 100644
--- a/src/test/regress/expected/foreign_key.out
+++ b/src/test/regress/expected/foreign_key.out
@@ -3733,7 +3733,7 @@ DROP TABLE fp_fk_cci, fp_pk_cci;
 DROP FUNCTION fp_auto_pk;
 -- A STABLE cast used by an FK check must see changes made by earlier AFTER
 -- triggers, using the check's snapshot rather than the outer query's snapshot.
--- Compare the per-row fast path with a partitioned-parent SPI check.
+-- Compare the fast path with a partitioned-parent SPI check.
 BEGIN;
 CREATE SCHEMA ri_snapshot;
 SET LOCAL search_path = ri_snapshot, pg_catalog;
@@ -3769,22 +3769,9 @@ CREATE TRIGGER "AAA_lookup" AFTER INSERT ON fk_fast
     FOR EACH ROW EXECUTE FUNCTION add_lookup_row();
 CREATE TRIGGER "AAA_lookup" AFTER INSERT ON fk_spi
     FOR EACH ROW EXECUTE FUNCTION add_lookup_row();
--- Invoke the fast-path check from another FK's cast.  Even with batching
--- enabled, a check nested inside the end-of-batch flush takes the per-row path.
-CREATE TYPE driver_key AS (v int);
-CREATE FUNCTION driver_key_to_int(k driver_key) RETURNS int
-LANGUAGE plpgsql VOLATILE AS $$
-BEGIN
-    INSERT INTO fk_fast VALUES (ROW(k.v)::lookup_key);
-    RETURN k.v;
-END;
-$$;
-CREATE CAST (driver_key AS int)
-    WITH FUNCTION driver_key_to_int(driver_key) AS IMPLICIT;
-CREATE TABLE driver (k driver_key REFERENCES pk_fast(v));
--- Both checks must succeed.  Without an active snapshot for the per-row
+-- Both checks must succeed.  Without an active snapshot for the fast-path
 -- check, its STABLE cast misses the lookup row and returns -1 instead of 1.
-INSERT INTO driver VALUES (ROW(1)::driver_key);
+INSERT INTO fk_fast VALUES (ROW(1)::lookup_key);
 SELECT count(*) FROM fk_fast;
  count 
 -------
diff --git a/src/test/regress/sql/foreign_key.sql b/src/test/regress/sql/foreign_key.sql
index 5e27b9b2d24..296735aa35a 100644
--- a/src/test/regress/sql/foreign_key.sql
+++ b/src/test/regress/sql/foreign_key.sql
@@ -2714,7 +2714,7 @@ DROP FUNCTION fp_auto_pk;
 
 -- A STABLE cast used by an FK check must see changes made by earlier AFTER
 -- triggers, using the check's snapshot rather than the outer query's snapshot.
--- Compare the per-row fast path with a partitioned-parent SPI check.
+-- Compare the fast path with a partitioned-parent SPI check.
 BEGIN;
 CREATE SCHEMA ri_snapshot;
 SET LOCAL search_path = ri_snapshot, pg_catalog;
@@ -2754,23 +2754,9 @@ CREATE TRIGGER "AAA_lookup" AFTER INSERT ON fk_fast
 CREATE TRIGGER "AAA_lookup" AFTER INSERT ON fk_spi
     FOR EACH ROW EXECUTE FUNCTION add_lookup_row();
 
--- Invoke the fast-path check from another FK's cast.  Even with batching
--- enabled, a check nested inside the end-of-batch flush takes the per-row path.
-CREATE TYPE driver_key AS (v int);
-CREATE FUNCTION driver_key_to_int(k driver_key) RETURNS int
-LANGUAGE plpgsql VOLATILE AS $$
-BEGIN
-    INSERT INTO fk_fast VALUES (ROW(k.v)::lookup_key);
-    RETURN k.v;
-END;
-$$;
-CREATE CAST (driver_key AS int)
-    WITH FUNCTION driver_key_to_int(driver_key) AS IMPLICIT;
-CREATE TABLE driver (k driver_key REFERENCES pk_fast(v));
-
--- Both checks must succeed.  Without an active snapshot for the per-row
+-- Both checks must succeed.  Without an active snapshot for the fast-path
 -- check, its STABLE cast misses the lookup row and returns -1 instead of 1.
-INSERT INTO driver VALUES (ROW(1)::driver_key);
+INSERT INTO fk_fast VALUES (ROW(1)::lookup_key);
 SELECT count(*) FROM fk_fast;
 DELETE FROM lookup_rows;
 INSERT INTO fk_spi VALUES (ROW(1)::lookup_key);
-- 
2.47.3

