From: Tomas Vondra <tomas.vondra@enterprisedb.com>
To: Amit Kapila <amit.kapila16@gmail.com>
To: Euler Taveira <euler@eulerto.com>
Cc: houzj.fnst@fujitsu.com <houzj.fnst@fujitsu.com>
Cc: Peter Smith <smithpb2250@gmail.com>
Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: Greg Nancarrow <gregn4422@gmail.com>
Cc: vignesh C <vignesh21@gmail.com>
Cc: Ajin Cherian <itsajin@gmail.com>
Cc: tanghy.fnst@fujitsu.com <tanghy.fnst@fujitsu.com>
Cc: Dilip Kumar <dilipbalaut@gmail.com>
Cc: Rahila Syed <rahilasyed90@gmail.com>
Cc: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Cc: Önder Kalacı <onderkalaci@gmail.com>
Cc: japin <japinli@hotmail.com>
Cc: Michael Paquier <michael@paquier.xyz>
Cc: David Steele <david@pgmasters.net>
Cc: Craig Ringer <craig@2ndquadrant.com>
Cc: Amit Langote <amitlangote09@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: row filtering for logical replication
Date: Wed, 2 Mar 2022 12:45:30 +0100
Message-ID: <6bdbd7fc-e81a-9a77-d963-24adeb95f29e@enterprisedb.com> (raw)
In-Reply-To: <CAA4eK1J+ufXi_nDxiNTaiAuj7nWfvHFW9q2JLTkOu2B=kBdSiA@mail.gmail.com>
References: <CAA4eK1KDtwUcuFHOJ4zCCTEY4+_-X3fKTjn=kyaZwBeeqRF-oA@mail.gmail.com>
<CAHut+PtTtAG+5T7rGA1FaAKM-JofSBOOxXhVtnCqcY22jH7MyA@mail.gmail.com>
<OS0PR01MB571648124C5BAE8B795CEDD9942D9@OS0PR01MB5716.jpnprd01.prod.outlook.com>
<CAHut+Pue8wSU7TTZ5Hy9p6wQ32LVFS1NezT9UtSK-FsDWMYP=Q@mail.gmail.com>
<OS0PR01MB5716B2A4901563E44637B7E2942F9@OS0PR01MB5716.jpnprd01.prod.outlook.com>
<CAA4eK1Kj1Frxo_L1edy40VzwWWRTyRt_QbnCLy21WcYL-DtdnA@mail.gmail.com>
<OS0PR01MB5716C373F6169B9570394EAA94309@OS0PR01MB5716.jpnprd01.prod.outlook.com>
<OS0PR01MB5716834CABD0F0E0D0FDBBEB94339@OS0PR01MB5716.jpnprd01.prod.outlook.com>
<OS0PR01MB5716F7B8AB42FC253A85FE0394349@OS0PR01MB5716.jpnprd01.prod.outlook.com>
<CAA4eK1LHQ+hoj_A5TPuhEfK90aK1psacVZ9TRdUpsyRWnKPH7A@mail.gmail.com>
<CAA4eK1LGQt=SnAiUMQUSbZMqBDVfK0kiQGqBOTo5jagGQQQJhw@mail.gmail.com>
<8da43807-06d8-44a5-a69a-fdea623622de@www.fastmail.com>
<CAA4eK1J+ufXi_nDxiNTaiAuj7nWfvHFW9q2JLTkOu2B=kBdSiA@mail.gmail.com>
Hi,
While working on the column filtering patch, which touches about the
same places, I noticed two minor gaps in testing:
1) The regression tests do perform multiple ALTER PUBLICATION commands,
tweaking the row filter. But there are no checks the row filter was
actually modified / stored in the catalog. It might be just thrown away
and no one would notice.
2) There are no pg_dump tests.
So attached are two trivial patched, addressing this. The first one adds
a couple \dRp and \d commands, to show what the catalogs contain. The
second one adds a simple pg_dump test.
regards
--
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
Attachments:download all (2 files, .tar.gz)0001-Verify-changing-WHERE-condition-for-a-publi-20220302.patch (text/x-patch, 6.9K) download
From e781f840e38701c63d8b57ff36bd520f2cced6ad Mon Sep 17 00:00:00 2001
From: Tomas Vondra <tomas@2ndquadrant.com>
Date: Sat, 26 Feb 2022 17:33:09 +0100
Subject: [PATCH 1/3] Verify changing WHERE condition for a publication
Commit 52e4f0cd47 added support for row filters in logical replication,
including regression tests with multiple ALTER PUBLICATION commands,
modifying the row filter. But the tests never verified that the row
filter was actually updated in the catalog. This adds a couple \d and
\dRp commands, to verify the catalog was updated.
---
src/test/regress/expected/publication.out | 66 +++++++++++++++++++++++
src/test/regress/sql/publication.sql | 8 +++
2 files changed, 74 insertions(+)
diff --git a/src/test/regress/expected/publication.out b/src/test/regress/expected/publication.outindex 3c382e520e4..227ce759486 100644--- a/src/test/regress/expected/publication.out+++ b/src/test/regress/expected/publication.out@@ -395,15 +395,81 @@ LINE 1: ...ICATION testpub5 ADD TABLE testpub_rf_tbl1 WHERE (b < '2' CO...
DETAIL: User-defined collations are not allowed.
-- ok - NULLIF is allowed
ALTER PUBLICATION testpub5 SET TABLE testpub_rf_tbl1 WHERE (NULLIF(1,2) = a);
+\d+ testpub_rf_tbl1+ Table "public.testpub_rf_tbl1"+ Column | Type | Collation | Nullable | Default | Storage | Stats target | Description +--------+---------+-----------+----------+---------+----------+--------------+-------------+ a | integer | | | | plain | | + b | text | | | | extended | | +Publications:+ "testpub5" WHERE (NULLIF(1, 2) = a)++\dRp+ testpub5+ Publication testpub5+ Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root +--------------------------+------------+---------+---------+---------+-----------+----------+ regress_publication_user | f | t | f | f | f | f+Tables:+ "public.testpub_rf_tbl1" WHERE (NULLIF(1, 2) = a)+
-- ok - built-in operators are allowed
ALTER PUBLICATION testpub5 SET TABLE testpub_rf_tbl1 WHERE (a IS NULL);
+\d+ testpub_rf_tbl1+ Table "public.testpub_rf_tbl1"+ Column | Type | Collation | Nullable | Default | Storage | Stats target | Description +--------+---------+-----------+----------+---------+----------+--------------+-------------+ a | integer | | | | plain | | + b | text | | | | extended | | +Publications:+ "testpub5" WHERE (a IS NULL)++\dRp+ testpub5+ Publication testpub5+ Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root +--------------------------+------------+---------+---------+---------+-----------+----------+ regress_publication_user | f | t | f | f | f | f+Tables:+ "public.testpub_rf_tbl1" WHERE (a IS NULL)+
ALTER PUBLICATION testpub5 SET TABLE testpub_rf_tbl1 WHERE ((a > 5) IS FALSE);
ALTER PUBLICATION testpub5 SET TABLE testpub_rf_tbl1 WHERE (a IS DISTINCT FROM 5);
ALTER PUBLICATION testpub5 SET TABLE testpub_rf_tbl1 WHERE ((a, a + 1) < (2, 3));
-- ok - built-in type coercions between two binary compatible datatypes are allowed
ALTER PUBLICATION testpub5 SET TABLE testpub_rf_tbl1 WHERE (b::varchar < '2');
+\d+ testpub_rf_tbl1+ Table "public.testpub_rf_tbl1"+ Column | Type | Collation | Nullable | Default | Storage | Stats target | Description +--------+---------+-----------+----------+---------+----------+--------------+-------------+ a | integer | | | | plain | | + b | text | | | | extended | | +Publications:+ "testpub5" WHERE (((b)::character varying)::text < '2'::text)++\dRp+ testpub5+ Publication testpub5+ Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root +--------------------------+------------+---------+---------+---------+-----------+----------+ regress_publication_user | f | t | f | f | f | f+Tables:+ "public.testpub_rf_tbl1" WHERE (((b)::character varying)::text < '2'::text)+
-- ok - immutable built-in functions are allowed
ALTER PUBLICATION testpub5 SET TABLE testpub_rf_tbl4 WHERE (length(g) < 6);
+\d+ testpub_rf_tbl1+ Table "public.testpub_rf_tbl1"+ Column | Type | Collation | Nullable | Default | Storage | Stats target | Description +--------+---------+-----------+----------+---------+----------+--------------+-------------+ a | integer | | | | plain | | + b | text | | | | extended | | ++\dRp+ testpub5+ Publication testpub5+ Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root +--------------------------+------------+---------+---------+---------+-----------+----------+ regress_publication_user | f | t | f | f | f | f+Tables:+ "public.testpub_rf_tbl4" WHERE (length(g) < 6)+
-- fail - user-defined types are not allowed
CREATE TYPE rf_bug_status AS ENUM ('new', 'open', 'closed');
CREATE TABLE rf_bug (id serial, description text, status rf_bug_status);
diff --git a/src/test/regress/sql/publication.sql b/src/test/regress/sql/publication.sqlindex 3f04d34264a..cd7e0182716 100644--- a/src/test/regress/sql/publication.sql+++ b/src/test/regress/sql/publication.sql@@ -203,15 +203,23 @@ CREATE COLLATION user_collation FROM "C";
ALTER PUBLICATION testpub5 ADD TABLE testpub_rf_tbl1 WHERE (b < '2' COLLATE user_collation);
-- ok - NULLIF is allowed
ALTER PUBLICATION testpub5 SET TABLE testpub_rf_tbl1 WHERE (NULLIF(1,2) = a);
+\d+ testpub_rf_tbl1+\dRp+ testpub5
-- ok - built-in operators are allowed
ALTER PUBLICATION testpub5 SET TABLE testpub_rf_tbl1 WHERE (a IS NULL);
+\d+ testpub_rf_tbl1+\dRp+ testpub5
ALTER PUBLICATION testpub5 SET TABLE testpub_rf_tbl1 WHERE ((a > 5) IS FALSE);
ALTER PUBLICATION testpub5 SET TABLE testpub_rf_tbl1 WHERE (a IS DISTINCT FROM 5);
ALTER PUBLICATION testpub5 SET TABLE testpub_rf_tbl1 WHERE ((a, a + 1) < (2, 3));
-- ok - built-in type coercions between two binary compatible datatypes are allowed
ALTER PUBLICATION testpub5 SET TABLE testpub_rf_tbl1 WHERE (b::varchar < '2');
+\d+ testpub_rf_tbl1+\dRp+ testpub5
-- ok - immutable built-in functions are allowed
ALTER PUBLICATION testpub5 SET TABLE testpub_rf_tbl4 WHERE (length(g) < 6);
+\d+ testpub_rf_tbl1+\dRp+ testpub5
-- fail - user-defined types are not allowed
CREATE TYPE rf_bug_status AS ENUM ('new', 'open', 'closed');
CREATE TABLE rf_bug (id serial, description text, status rf_bug_status);
--
2.34.1
0002-Test-publication-row-filters-in-pg_dump-tes-20220302.patch (text/x-patch, 1.3K) download
From 8ee67dd52a1fc08837aa85979dfc0842cc968012 Mon Sep 17 00:00:00 2001
From: Tomas Vondra <tomas.vondra@postgresql.org>
Date: Tue, 1 Mar 2022 15:25:56 +0100
Subject: [PATCH 2/3] Test publication row filters in pg_dump tests
Commit 52e4f0cd47 added support for row filters when replicating tables,
but the commit added no pg_dump tests for this feature. So add at least
a simple test.
---
src/bin/pg_dump/t/002_pg_dump.pl | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.plindex dd065c758fa..c3bcef8c0ec 100644--- a/src/bin/pg_dump/t/002_pg_dump.pl+++ b/src/bin/pg_dump/t/002_pg_dump.pl@@ -2407,12 +2407,12 @@ my %tests = (
},
},
- 'ALTER PUBLICATION pub1 ADD TABLE test_second_table' => {+ 'ALTER PUBLICATION pub1 ADD TABLE test_second_table WHERE (col1 = 1)' => {
create_order => 52,
create_sql =>
- 'ALTER PUBLICATION pub1 ADD TABLE dump_test.test_second_table;',+ 'ALTER PUBLICATION pub1 ADD TABLE dump_test.test_second_table WHERE (col1 = 1);',
regexp => qr/^
- \QALTER PUBLICATION pub1 ADD TABLE ONLY dump_test.test_second_table;\E+ \QALTER PUBLICATION pub1 ADD TABLE ONLY dump_test.test_second_table WHERE ((col1 = 1));\E
/xm,
like => { %full_runs, section_post_data => 1, },
unlike => { exclude_dump_test_schema => 1, },
--
2.34.1
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: tomas.vondra@enterprisedb.com, amit.kapila16@gmail.com, euler@eulerto.com, houzj.fnst@fujitsu.com, smithpb2250@gmail.com, alvherre@alvh.no-ip.org, gregn4422@gmail.com, vignesh21@gmail.com, itsajin@gmail.com, tanghy.fnst@fujitsu.com, dilipbalaut@gmail.com, rahilasyed90@gmail.com, peter.eisentraut@enterprisedb.com, onderkalaci@gmail.com, japinli@hotmail.com, michael@paquier.xyz, david@pgmasters.net, craig@2ndquadrant.com, amitlangote09@gmail.com, pgsql-hackers@lists.postgresql.org
Subject: Re: row filtering for logical replication
In-Reply-To: <6bdbd7fc-e81a-9a77-d963-24adeb95f29e@enterprisedb.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox