From: PostgreSQL relcache v3 Linux review
Subject: [PATCH 2/4] Test predicate locking with a rule-bearing table

Exercise TRUNCATE in a serializable transaction after rewrite-rule metadata
has populated the table side of the RelationData union.  The unfixed v3
series aborts in CheckTableForSerializableConflictIn().

Depends on patch 1.  Applies after David Geier's v3 patches 0001 through
0006, based on 9dbc53591a2de03e0cfdab61a78726f8b2c29eef.
---
diff --git a/src/test/regress/expected/relcache_union.out b/src/test/regress/expected/relcache_union.out
new file mode 100644
index 00000000000..8d77c4cf7d7
--- /dev/null
+++ b/src/test/regress/expected/relcache_union.out
@@ -0,0 +1,14 @@
+-- A rule-bearing table has table-side union members populated.
+CREATE TABLE relcache_union_tab (a integer PRIMARY KEY);
+CREATE RULE relcache_union_rule AS ON INSERT TO relcache_union_tab
+  DO ALSO SELECT 1;
+BEGIN ISOLATION LEVEL SERIALIZABLE;
+INSERT INTO relcache_union_tab VALUES (1);
+ ?column? 
+----------
+        1
+(1 row)
+
+TRUNCATE relcache_union_tab;
+COMMIT;
+DROP TABLE relcache_union_tab;
diff --git a/src/test/regress/parallel_schedule b/src/test/regress/parallel_schedule
index 75063f87a4a..bb9d90be51e 100644
--- a/src/test/regress/parallel_schedule
+++ b/src/test/regress/parallel_schedule
@@ -143,6 +143,9 @@ test: event_trigger_login
 # this test also uses event triggers, so likewise run it by itself
 test: fast_default
 
+# Exercise relcache union discrimination without concurrent DDL.
+test: relcache_union
+
 # run tablespace test at the end because it drops the tablespace created during
 # setup that other tests may use.
 test: tablespace
diff --git a/src/test/regress/sql/relcache_union.sql b/src/test/regress/sql/relcache_union.sql
new file mode 100644
index 00000000000..bdb708fa706
--- /dev/null
+++ b/src/test/regress/sql/relcache_union.sql
@@ -0,0 +1,11 @@
+-- A rule-bearing table has table-side union members populated.
+CREATE TABLE relcache_union_tab (a integer PRIMARY KEY);
+CREATE RULE relcache_union_rule AS ON INSERT TO relcache_union_tab
+  DO ALSO SELECT 1;
+
+BEGIN ISOLATION LEVEL SERIALIZABLE;
+INSERT INTO relcache_union_tab VALUES (1);
+TRUNCATE relcache_union_tab;
+COMMIT;
+
+DROP TABLE relcache_union_tab;
