De-duplicate the result of pg_publication_tables view.
authorAmit Kapila <akapila@postgresql.org>
Wed, 8 Dec 2021 05:45:25 +0000 (11:15 +0530)
committerAmit Kapila <akapila@postgresql.org>
Wed, 8 Dec 2021 05:45:25 +0000 (11:15 +0530)
We show duplicate values for child tables in publications that have both
child and parent tables and are published with publish_via_partition_root
as false which is not what the user would expect.

We decided not to backpatch this as there is no user complaint about this
and it doesn't seem to be a critical issue.

Author: Hou Zhijie
Reviewed-by: Bharath Rupireddy, Amit Langote, Amit Kapila
Discussion: https://postgr.es/m/OS0PR01MB5716E97F00732B52DC2BBC2594989@OS0PR01MB5716.jpnprd01.prod.outlook.com

src/backend/catalog/pg_publication.c
src/test/regress/expected/publication.out
src/test/regress/sql/publication.sql

index 63579b2f82c745e95e5b14cdbb5cdb84ce0e04ff..b40293fcb31ae031e3923d952e498e7ec67c4b19 100644 (file)
@@ -487,6 +487,10 @@ GetPublicationRelations(Oid pubid, PublicationPartOpt pub_partopt)
        systable_endscan(scan);
        table_close(pubrelsrel, AccessShareLock);
 
+       /* Now sort and de-duplicate the result list */
+       list_sort(result, list_oid_cmp);
+       list_deduplicate_oid(result);
+
        return result;
 }
 
index 1feb558968a455c9637336d324ddbcc3303f6f0d..a2115c1c6060d75e492bc71c3ea216b94490d05d 100644 (file)
@@ -832,6 +832,14 @@ SELECT * FROM pg_publication_tables;
  pub     | sch2       | tbl1_part1
 (1 row)
 
+-- Table publication that includes both the parent table and the child table
+ALTER PUBLICATION pub ADD TABLE sch1.tbl1;
+SELECT * FROM pg_publication_tables;
+ pubname | schemaname | tablename  
+---------+------------+------------
+ pub     | sch2       | tbl1_part1
+(1 row)
+
 DROP PUBLICATION pub;
 DROP TABLE sch2.tbl1_part1;
 DROP TABLE sch1.tbl1;
index 8fa0435c322c8c91eba5076cffadacc1e4d67551..2fe41b07ae2ab95704a903ad40d81b5043fd36db 100644 (file)
@@ -469,6 +469,10 @@ DROP PUBLICATION pub;
 CREATE PUBLICATION pub FOR TABLE sch2.tbl1_part1 WITH (PUBLISH_VIA_PARTITION_ROOT=0);
 SELECT * FROM pg_publication_tables;
 
+-- Table publication that includes both the parent table and the child table
+ALTER PUBLICATION pub ADD TABLE sch1.tbl1;
+SELECT * FROM pg_publication_tables;
+
 DROP PUBLICATION pub;
 DROP TABLE sch2.tbl1_part1;
 DROP TABLE sch1.tbl1;