RE: Data is copied twice when specifying both child and parent table in publication
Wei Wang (Fujitsu) <wangw.fnst@fujitsu.com>
From: "wangw.fnst@fujitsu.com" <wangw.fnst@fujitsu.com>
To: "shiy.fnst@fujitsu.com" <shiy.fnst@fujitsu.com>, Amit Kapila <amit.kapila16@gmail.com>
Cc: "houzj.fnst@fujitsu.com" <houzj.fnst@fujitsu.com>, Amit Langote <amitlangote09@gmail.com>, Peter Eisentraut <peter.eisentraut@enterprisedb.com>, "pgsql-hackers@lists.postgresql.org" <pgsql-hackers@lists.postgresql.org>, Dilip Kumar <dilipbalaut@gmail.com>, Greg Nancarrow <gregn4422@gmail.com>, vignesh C <vignesh21@gmail.com>
Date: 2022-05-09T01:51:09Z
Lists: pgsql-hackers
Attachments
- HEAD_v2-0001-Fix-data-replicated-twice-when-specifying-PUBLISH.patch (application/octet-stream) patch v2-0001
- REL14_v4-0001-Fix-data-replicated-twice-when-specifying-PUBLISH.patch (application/octet-stream) patch v4-0001
On Tue, Apr 28, 2022 9:22 AM Shi, Yu/侍 雨 <shiy.fnst@cn.fujitsu.com> wrote: > Thanks for your patches. > > Here's a comment on the patch for REL14. Thanks for your comments. > + appendStringInfo(&cmd, "SELECT DISTINCT ns.nspname, c.relname\n" > + " FROM > pg_catalog.pg_publication_tables t\n" > + " JOIN pg_catalog.pg_namespace > ns\n" > + " ON ns.nspname = > t.schemaname\n" > + " JOIN pg_catalog.pg_class c\n" > + " ON c.relname = t.tablename AND > c.relnamespace = ns.oid\n" > + " WHERE t.pubname IN (%s)\n" > + " AND (c.relispartition IS FALSE\n" > + " OR NOT EXISTS\n" > + " ( SELECT 1 FROM > pg_partition_ancestors(c.oid) as relid\n" > + " WHERE relid IN\n" > + " (SELECT DISTINCT (schemaname > || '.' || tablename)::regclass::oid\n" > + " FROM > pg_catalog.pg_publication_tables t\n" > + " WHERE t.pubname IN (%s))\n" > + " AND relid != c.oid))\n", > + pub_names.data, pub_names.data); > > I think we can use an alias like 'pa' for pg_partition_ancestors, and modify the > SQL as follows. > > + appendStringInfo(&cmd, "SELECT DISTINCT ns.nspname, c.relname\n" > + " FROM > pg_catalog.pg_publication_tables t\n" > + " JOIN pg_catalog.pg_namespace > ns\n" > + " ON ns.nspname = > t.schemaname\n" > + " JOIN pg_catalog.pg_class c\n" > + " ON c.relname = t.tablename AND > c.relnamespace = ns.oid\n" > + " WHERE t.pubname IN (%s)\n" > + " AND (c.relispartition IS FALSE\n" > + " OR NOT EXISTS\n" > + " ( SELECT 1 FROM > pg_partition_ancestors(c.oid) pa\n" > + " WHERE pa.relid IN\n" > + " (SELECT DISTINCT > (t.schemaname || '.' || t.tablename)::regclass::oid\n" > + " FROM > pg_catalog.pg_publication_tables t\n" > + " WHERE t.pubname IN (%s))\n" > + " AND pa.relid != c.oid))\n", > + pub_names.data, pub_names.data); Fix it. In addition, I try to modify the approach for the HEAD. I enhance the API of function pg_get_publication_tables. Change the parameter type from 'text' to 'any'. Then we can use this function to get tables from one publication or an array of publications. Any thoughts on this approach? Attach new patches. The patch for HEAD: 1. Modify the approach. Enhance the API of function pg_get_publication_tables to handle one publication or an array of publications. The patch for REL14: 1. Improve the table sync SQL. [suggestions by Shi yu] Regards, Wang wei
Commits
-
Avoid syncing data twice for the 'publish_via_partition_root' option.
- 062a84442424 16.0 landed
-
Fix partition table's REPLICA IDENTITY checking on the subscriber.
- 52d5ea9adb01 14.5 cited
-
Prohibit combining publications with different column lists.
- fd0b9dcebda7 15.0 cited
-
Fix double publish of child table's data.
- 3f06c00cf6dc 13.6 landed
- 614b77d65a38 14.2 landed
- 5e97905a2c76 15.0 landed
-
Support adding partitioned tables to publication
- 17b9e7f9fe23 13.0 cited