Re: Support EXCEPT for TABLES IN SCHEMA publications

From: shveta malik <shveta(dot)malik(at)gmail(dot)com>
To: Nisha Moond <nisha(dot)moond412(at)gmail(dot)com>
Cc: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org, Peter Smith <smithpb2250(at)gmail(dot)com>, shveta malik <shveta(dot)malik(at)gmail(dot)com>
Subject: Re: Support EXCEPT for TABLES IN SCHEMA publications
Date: 2026-07-16 10:32:14
Message-ID: CAJpy0uCj8NdSuWSWkn8iGriz1D1i1g-rMLs9Fk8SEf8uWs60ww@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I have reviewed a portion of v21-001 yet. The comments so far:

1)
check_publication_add_relation:

+ Oid relid = RelationGetRelid(targetrel);

Please move this inside :
+ if (targetrel->rd_rel->relispartition)

2)
Please shorten this comment:

+ /*
+ * If the partition root (the last element of ancestors) is excluded from
+ * this publication via its EXCEPT clause, the partition is not published
+ * through this publication at all, so we short-circuit and return
+ * InvalidOid without walking the ancestor list. Only the root of a
+ * partition hierarchy can ever appear in a publication's EXCEPT clause (a
+ * partition itself is rejected from EXCEPT elsewhere), so it's the only
+ * one worth a catalog lookup.
+ */

Suggestion:
/*
* If the partition root is excluded from this publication via its EXCEPT
* clause, the partition is not published through this publication, so return
* InvalidOid. Since only partition roots can appear in an EXCEPT clause, the
* root is the only ancestor worth a catalog lookup.
*/

3)
postgres=# ALTER TABLE s2.tab_root_new ATTACH PARTITION s2.tab_root
FOR VALUES FROM (1) TO (2000);
ERROR: cannot attach table "tab_root" as partition because it is
referenced in publication "pub1" EXCEPT clause
DETAIL: The publication EXCEPT clause cannot contain tables that are
partitions.
HINT: Change the publication's EXCEPT clause using ALTER PUBLICATION
... SET TABLES IN SCHEMA ... EXCEPT.

postgres=# ALTER publication pub1 add TABLE s2.tab_part_1_p2;
ERROR: cannot add partition "s2.tab_part_1_p2" to publication "pub1"
DETAIL: Ancestor "s2.tab_root" of partition "s2.tab_part_1_p2" is
currently listed in the EXCEPT clause of the publication.
HINT: Change EXCEPT list using ALTER PUBLICATION ... SET TABLES IN
SCHEMA ... EXCEPT.

Can we make HINT same? We can retain the wording of HINT given in
ATTACH PARTITION case as that is existing one.

4)
postgres=# create publication pub1 for tables in schema s2 except
(table s2.tab_root), table s2.tab_part_2, table s2.tab_part_1_p2;
ERROR: partition "s2.tab_part_2" cannot be both published and excluded
DETAIL: Ancestor "s2.tab_root" of partition "s2.tab_part_2" is
currently listed in the EXCEPT clause of this command.

postgres=# ALTER publication pub1 add TABLE s2.tab_part_1_p2;
ERROR: cannot add partition "s2.tab_part_1_p2" to publication "pub1"
DETAIL: Ancestor "s2.tab_root" of partition "s2.tab_part_1_p2" is
currently listed in the EXCEPT clause of the publication.
HINT: Change EXCEPT list using ALTER PUBLICATION ... SET TABLES IN
SCHEMA ... EXCEPT.

Should the DETAIL be just:
DETAIL: Partition root "s2.tab_root" is listed in the publication's
EXCEPT clause.

Thoughts?

thanks
Shveta

In response to

Browse pgsql-hackers by date

  From Date Subject
Previous Message Nisha Moond 2026-07-16 10:18:46 Re: Bug in ALTER SUBSCRIPTION ... SERVER / ... CONNECTION with broken old server