From 36c1cc22d5fb178c44d21a564899875816efe44f Mon Sep 17 00:00:00 2001 From: Hayato Kuroda Date: Sat, 11 Oct 2025 22:12:30 +0900 Subject: [PATCH] Fix 009_mateviews.pl --- src/test/subscription/t/009_matviews.pl | 40 +++++++++++++++++-------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/src/test/subscription/t/009_matviews.pl b/src/test/subscription/t/009_matviews.pl index 9316fd1bb6d..587dcd569bb 100644 --- a/src/test/subscription/t/009_matviews.pl +++ b/src/test/subscription/t/009_matviews.pl @@ -18,19 +18,20 @@ $node_subscriber->start; my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres'; -$node_publisher->safe_psql('postgres', - "CREATE PUBLICATION mypub FOR ALL TABLES;"); -$node_subscriber->safe_psql('postgres', - "CREATE SUBSCRIPTION mysub CONNECTION '$publisher_connstr' PUBLICATION mypub;" -); - $node_publisher->safe_psql('postgres', q{CREATE TABLE test1 (a int PRIMARY KEY, b text)}); $node_publisher->safe_psql('postgres', - q{INSERT INTO test1 (a, b) VALUES (1, 'one'), (2, 'two');}); - + q{CREATE MATERIALIZED VIEW testmv1 AS SELECT * FROM test1;}); $node_subscriber->safe_psql('postgres', q{CREATE TABLE test1 (a int PRIMARY KEY, b text);}); +$node_subscriber->safe_psql('postgres', + q{CREATE MATERIALIZED VIEW testmv1 AS SELECT * FROM test1;}); + +$node_publisher->safe_psql('postgres', + "CREATE PUBLICATION mypub FOR ALL TABLES;"); +$node_subscriber->safe_psql('postgres', + "CREATE SUBSCRIPTION mysub CONNECTION '$publisher_connstr' PUBLICATION mypub;" +); $node_publisher->wait_for_catchup('mysub'); @@ -38,15 +39,28 @@ $node_publisher->wait_for_catchup('mysub'); # logical decoding does produce change information for them, so we # need to make sure they are properly ignored. (bug #15044) -# create a MV with some data +# Ensure REFRESH MATERIALIZED VIEW on publisher won't affect subscriber $node_publisher->safe_psql('postgres', - q{CREATE MATERIALIZED VIEW testmv1 AS SELECT * FROM test1;}); + q{INSERT INTO test1 (a, b) VALUES (1, 'one'), (2, 'two');}); +$node_publisher->safe_psql('postgres', q{REFRESH MATERIALIZED VIEW testmv1;}); $node_publisher->wait_for_catchup('mysub'); -# There is no equivalent relation on the subscriber, but MV data is -# not replicated, so this does not hang. +my $result = + $node_publisher->safe_psql('postgres', "SELECT count(*) FROM testmv1"); +is($result, '2', 'materialized view on publisher has 2 rows'); + +$result = + $node_subscriber->safe_psql('postgres', "SELECT count(*) FROM testmv1"); +is($result, '0', 'materialized view on subscriber d otno have '); + +# Make sure REFRESH MATERIALIZED VIEW on subscriber works well +$node_subscriber->safe_psql('postgres', + q{REFRESH MATERIALIZED VIEW testmv1;}); -pass "materialized view data not replicated"; +$result = + $node_subscriber->safe_psql('postgres', "SELECT count(*) FROM testmv1"); +is($result, '2', + 'materialized view on subscriber has 2 rows after the refresh'); $node_subscriber->stop; $node_publisher->stop; -- 2.47.3