From 00a956cbcd64f164b850dcf917705d3c9da528a1 Mon Sep 17 00:00:00 2001
From: Shlok Kyal <shlok.kyal.oss@gmail.com>
Date: Wed, 4 Feb 2026 12:27:57 +0530
Subject: [PATCH v46 2/2] Extended tests for EXCEPT TABLE patch

This patch contains extra tests for EXCEPT TABLE patch. Purpose of this
tests to keep track of tests which once broke the patch.

Based on discussion in future we may pick up some test to include in
the main patch.
---
 src/test/subscription/t/101_test.pl | 136 ++++++++++++++++++++++++++++
 1 file changed, 136 insertions(+)
 create mode 100644 src/test/subscription/t/101_test.pl

diff --git a/src/test/subscription/t/101_test.pl b/src/test/subscription/t/101_test.pl
new file mode 100644
index 00000000000..6e4dfc3a713
--- /dev/null
+++ b/src/test/subscription/t/101_test.pl
@@ -0,0 +1,136 @@
+# Copyright (c) 2026, PostgreSQL Global Development Group
+#
+# Extended test for EXCEPT TABLE
+
+use strict;
+use warnings FATAL => 'all';
+
+use PostgreSQL::Test::Cluster;
+use PostgreSQL::Test::Utils;
+use Test::More;
+
+# --------
+# Publisher
+# --------
+my $publisher = PostgreSQL::Test::Cluster->new('publisher');
+$publisher->init(allows_streaming => 'logical');
+$publisher->append_conf(
+	'postgresql.conf', q(
+wal_level = logical
+log_min_messages = INFO
+log_statement = all
+wal_receiver_timeout = 0
+wal_sender_timeout = 0
+));
+$publisher->start;
+
+# Create a partition structure:
+# sc1.t1
+#   - sc1.child1
+#       - sc1.child1_1
+#       - sc1.child1_2
+#   - sc1.child2
+$publisher->safe_psql(
+	'postgres', q(
+	CREATE SCHEMA sc1;
+	CREATE TABLE sc1.t1(id int) PARTITION BY RANGE(id);
+	CREATE TABLE sc1.child1(id int) PARTITION BY RANGE(id);
+	CREATE TABLE sc1.child2 PARTITION OF sc1.t1 FOR VALUES FROM (101) TO (200);
+	CREATE TABLE sc1.child1_1 PARTITION OF sc1.child1 FOR VALUES FROM (0) TO (50);
+	CREATE TABLE sc1.child1_2 PARTITION OF sc1.child1 FOR VALUES FROM (51) TO (100);
+	ALTER TABLE sc1.t1 ATTACH PARTITION sc1.child1 FOR VALUES FROM (0) TO (100);
+));
+
+# ----------
+# Subscriber
+# ----------
+my $connstr = $publisher->connstr . ' dbname=postgres';
+my $subscriber = PostgreSQL::Test::Cluster->new('subscriber');
+$subscriber->init(allows_streaming => 'logical');
+$subscriber->append_conf(
+	'postgresql.conf', q(
+wal_level = logical
+log_min_messages = INFO
+log_statement = all
+wal_receiver_timeout = 0
+wal_sender_timeout = 0
+));
+$subscriber->start;
+
+$subscriber->safe_psql(
+	'postgres', q(
+	CREATE SCHEMA sc1;
+	CREATE TABLE sc1.t1(id int);
+	CREATE TABLE sc1.child1(id int);
+	CREATE TABLE sc1.child1_1(id int);
+	CREATE TABLE sc1.child1_2(id int);
+	CREATE TABLE sc1.child2(id int);
+));
+
+# Test 1:
+# Create two publications, one with "ALL TABLES EXCEPT", other with "FOR TABLE"
+# Tables specified in "EXCEPT" and "FOR TABLE" are part of same partition tree
+$publisher->safe_psql(
+	'postgres', q(
+	INSERT INTO sc1.t1 VALUES (1), (51), (101);
+	CREATE PUBLICATION pub1 FOR ALL TABLES EXCEPT TABLE (sc1.child2) WITH (publish_via_partition_root = true);
+	CREATE PUBLICATION pub2 FOR TABLE sc1.child1_1 WITH (publish_via_partition_root = true);
+));
+$subscriber->safe_psql('postgres',
+	"CREATE SUBSCRIPTION sub1 CONNECTION '$connstr' PUBLICATION pub1, pub2;");
+
+# Check for tablesync
+$subscriber->wait_for_subscription_sync($publisher, 'sub1');
+my $result =
+  $subscriber->safe_psql('postgres', "SELECT * FROM sc1.t1 ORDER BY id");
+is( $result, qq(1
+51), 'check data after tablesync');
+
+# Check for incremental sync
+$publisher->safe_psql('postgres',
+	"INSERT INTO sc1.t1 VALUES (1), (51), (101)");
+$subscriber->wait_for_subscription_sync($publisher, 'sub1');
+$result =
+  $subscriber->safe_psql('postgres', "SELECT * FROM sc1.t1 ORDER BY id");
+is( $result, qq(1
+1
+51
+51), 'check data after incremental sync');
+
+# cleanup
+$publisher->safe_psql(
+	'postgres', q(
+	DROP PUBLICATION pub1, pub2;
+	TRUNCATE sc1.t1;
+));
+$subscriber->safe_psql(
+	'postgres', q(
+	DROP SUBSCRIPTION sub1;
+	TRUNCATE sc1.t1;
+));
+
+# Test 2: Create publication with EXCEPT TABLE list having all partitions of
+# particular level
+$publisher->safe_psql(
+	'postgres', q(
+	INSERT INTO sc1.t1 VALUES (1), (51), (101);
+	CREATE PUBLICATION pub1 FOR ALL TABLES EXCEPT TABLE (sc1.child2, sc1.child1) WITH (publish_via_partition_root = true);
+));
+$subscriber->safe_psql('postgres',
+	"CREATE SUBSCRIPTION sub1 CONNECTION '$connstr' PUBLICATION pub1;");
+
+# Check for tablesync
+$subscriber->wait_for_subscription_sync($publisher, 'sub1');
+$result =
+  $subscriber->safe_psql('postgres', "SELECT * FROM sc1.t1 ORDER BY id");
+is($result, qq(), 'check data after tablesync');
+
+# Check for incremental sync
+$publisher->safe_psql('postgres',
+	"INSERT INTO sc1.t1 VALUES (1), (51), (101)");
+$subscriber->wait_for_subscription_sync($publisher, 'sub1');
+$result =
+  $subscriber->safe_psql('postgres', "SELECT * FROM sc1.t1 ORDER BY id");
+is($result, qq(), 'check data after incremental sync');
+
+done_testing();
-- 
2.34.1

