Add some additional tests for row filters in logical replication.
authorAmit Kapila <akapila@postgresql.org>
Fri, 4 Mar 2022 02:24:12 +0000 (07:54 +0530)
committerAmit Kapila <akapila@postgresql.org>
Fri, 4 Mar 2022 02:24:12 +0000 (07:54 +0530)
Commit 52e4f0cd47 didn't add tests for pg_dump support, so add a few tests
for it. Additionally, verify that catalogs are updated after few
ALTER PUBLICATION commands that modify row filters by using \d.

Reported-by: Tomas Vondra
Author: Shi yu, based on initial by Tomas Vondra
Reviewed-by: Euler Taveira and Amit Kapila
Discussion: https://postgr.es/m/6bdbd7fc-e81a-9a77-d963-24adeb95f29e@enterprisedb.com

src/bin/pg_dump/t/002_pg_dump.pl
src/test/regress/expected/publication.out
src/test/regress/sql/publication.sql

index dd065c758fa9b54c6c77df5f5b688aa6c35c3d51..d9bc267f6da029abad6ab4777fceb9803af9e813 100644 (file)
@@ -2382,6 +2382,15 @@ my %tests = (
        like => { %full_runs, section_post_data => 1, },
    },
 
+   'CREATE PUBLICATION pub4' => {
+       create_order => 50,
+       create_sql   => 'CREATE PUBLICATION pub4;',
+       regexp => qr/^
+           \QCREATE PUBLICATION pub4 WITH (publish = 'insert, update, delete, truncate');\E
+           /xm,
+       like => { %full_runs, section_post_data => 1, },
+   },
+
    'CREATE SUBSCRIPTION sub1' => {
        create_order => 50,
        create_sql   => 'CREATE SUBSCRIPTION sub1
@@ -2439,6 +2448,31 @@ my %tests = (
        like => { %full_runs, section_post_data => 1, },
    },
 
+   'ALTER PUBLICATION pub4 ADD TABLE test_table WHERE (col1 > 0);' => {
+       create_order => 51,
+       create_sql =>
+         'ALTER PUBLICATION pub4 ADD TABLE dump_test.test_table WHERE (col1 > 0);',
+       regexp => qr/^
+           \QALTER PUBLICATION pub4 ADD TABLE ONLY dump_test.test_table WHERE ((col1 > 0));\E
+           /xm,
+       like => { %full_runs, section_post_data => 1, },
+       unlike => {
+           exclude_dump_test_schema => 1,
+           exclude_test_table       => 1,
+       },
+   },
+
+   'ALTER PUBLICATION pub4 ADD TABLE test_second_table WHERE (col2 = \'test\');' => {
+       create_order => 52,
+       create_sql =>
+         'ALTER PUBLICATION pub4 ADD TABLE dump_test.test_second_table WHERE (col2 = \'test\');',
+       regexp => qr/^
+           \QALTER PUBLICATION pub4 ADD TABLE ONLY dump_test.test_second_table WHERE ((col2 = 'test'::text));\E
+           /xm,
+       like => { %full_runs, section_post_data => 1, },
+       unlike => { exclude_dump_test_schema => 1, },
+   },
+
    'CREATE SCHEMA public' => {
        regexp => qr/^CREATE SCHEMA public;/m,
 
index 3c382e520e4d95108f02bba49d3691bc083a9083..4e191c120ace0c113d4a7da9b568376a57bc263b 100644 (file)
@@ -263,6 +263,12 @@ Tables:
     "public.testpub_rf_tbl1"
     "public.testpub_rf_tbl2" WHERE ((c <> 'test'::text) AND (d < 5))
 
+\d testpub_rf_tbl3
+          Table "public.testpub_rf_tbl3"
+ Column |  Type   | Collation | Nullable | Default 
+--------+---------+-----------+----------+---------
+ e      | integer |           |          | 
+
 ALTER PUBLICATION testpub5 ADD TABLE testpub_rf_tbl3 WHERE (e > 1000 AND e < 2000);
 \dRp+ testpub5
                                     Publication testpub5
@@ -274,6 +280,14 @@ Tables:
     "public.testpub_rf_tbl2" WHERE ((c <> 'test'::text) AND (d < 5))
     "public.testpub_rf_tbl3" WHERE ((e > 1000) AND (e < 2000))
 
+\d testpub_rf_tbl3
+          Table "public.testpub_rf_tbl3"
+ Column |  Type   | Collation | Nullable | Default 
+--------+---------+-----------+----------+---------
+ e      | integer |           |          | 
+Publications:
+    "testpub5" WHERE ((e > 1000) AND (e < 2000))
+
 ALTER PUBLICATION testpub5 DROP TABLE testpub_rf_tbl2;
 \dRp+ testpub5
                                     Publication testpub5
@@ -294,6 +308,14 @@ ALTER PUBLICATION testpub5 SET TABLE testpub_rf_tbl3 WHERE (e > 300 AND e < 500)
 Tables:
     "public.testpub_rf_tbl3" WHERE ((e > 300) AND (e < 500))
 
+\d testpub_rf_tbl3
+          Table "public.testpub_rf_tbl3"
+ Column |  Type   | Collation | Nullable | Default 
+--------+---------+-----------+----------+---------
+ e      | integer |           |          | 
+Publications:
+    "testpub5" WHERE ((e > 300) AND (e < 500))
+
 -- test \d <tablename> (now it displays filter information)
 SET client_min_messages = 'ERROR';
 CREATE PUBLICATION testpub_rf_yes FOR TABLE testpub_rf_tbl1 WHERE (a > 1) WITH (publish = 'insert');
index 3f04d34264a24034fe9fe5b92c69f23b3de942a5..5457c56b33f80f0906ea87e5a26fd9ca5ba139a3 100644 (file)
@@ -150,13 +150,16 @@ SET client_min_messages = 'ERROR';
 CREATE PUBLICATION testpub5 FOR TABLE testpub_rf_tbl1, testpub_rf_tbl2 WHERE (c <> 'test' AND d < 5) WITH (publish = 'insert');
 RESET client_min_messages;
 \dRp+ testpub5
+\d testpub_rf_tbl3
 ALTER PUBLICATION testpub5 ADD TABLE testpub_rf_tbl3 WHERE (e > 1000 AND e < 2000);
 \dRp+ testpub5
+\d testpub_rf_tbl3
 ALTER PUBLICATION testpub5 DROP TABLE testpub_rf_tbl2;
 \dRp+ testpub5
 -- remove testpub_rf_tbl1 and add testpub_rf_tbl3 again (another WHERE expression)
 ALTER PUBLICATION testpub5 SET TABLE testpub_rf_tbl3 WHERE (e > 300 AND e < 500);
 \dRp+ testpub5
+\d testpub_rf_tbl3
 -- test \d <tablename> (now it displays filter information)
 SET client_min_messages = 'ERROR';
 CREATE PUBLICATION testpub_rf_yes FOR TABLE testpub_rf_tbl1 WHERE (a > 1) WITH (publish = 'insert');