public inbox for [email protected]  
help / color / mirror / Atom feed
From: Peter Smith <[email protected]>
To: Shlok Kyal <[email protected]>
Cc: shveta malik <[email protected]>
Cc: vignesh C <[email protected]>
Cc: PostgreSQL Hackers <[email protected]>
Subject: Re: Support EXCEPT for ALL SEQUENCES publications
Date: Wed, 24 Jun 2026 18:04:27 +1200
Message-ID: <CAHut+PvMXOR73+WdvSWd3B8j6jDQQXRtO_bKEudi76n30GAApQ@mail.gmail.com> (raw)
In-Reply-To: <CANhcyEWfzDRCiny6A_swAD7WUgdb37-TA4xTAUQ3JJXK9UPBZQ@mail.gmail.com>
References: <CANhcyEVSXyQkvmrsOWPdQqnm2J3GMyQQrKhyCJiBQzqs6AvSow@mail.gmail.com>
	<CALDaNm125dv88fUDgBPBM-N-hXbF0NLqKe-ymEpMRNymUYRQAA@mail.gmail.com>
	<CANhcyEUxgzaNJNNO_-12wYwGLihpuKmsMH2g4TFnRPx5AQVZmg@mail.gmail.com>
	<CAJpy0uBB4N8KOrHchdgprVi2Ws1+gTcEr+bC2A_ziAHOcZcTqA@mail.gmail.com>
	<CAJpy0uCAJQvBjD7qNWWGnZP_LDwS8AiUJC7YMict9UcYqH=XeQ@mail.gmail.com>
	<CANhcyEU_Yq9ZJ2n5Sqa7RoHze0TD0RGxLQQgV1F6Jm2AROEh8g@mail.gmail.com>
	<CANhcyEWj-ECj=WC+HD_kv27Dn6FkTngFQCVJVTVZfJnjCTKMBQ@mail.gmail.com>
	<CANhcyEW03XO5tLb7opt1yQGHWJ7Ew=L65EWcdrKH=F0mUpuR3A@mail.gmail.com>
	<CAHut+Ptu0Bkwnr5eetdmFhJC7SsEtKjNe_cTwOg5wF65fjyV8w@mail.gmail.com>
	<CANhcyEU+4Z6NXMEk6OmctFv=_pY8K5AiazkfVmn7zxhwQO6CEQ@mail.gmail.com>
	<CAHut+PvOWjKJfNorGO8whnaAtqZb-4zN8u6aOajCw3hn-tMwyA@mail.gmail.com>
	<CANhcyEV_Sv+xQzsjo6hbowDbGV5J7RhFWuQQxWeUWPNPd0k1=w@mail.gmail.com>
	<CAHut+Pt6O3YD8h61RCtzMrRwgvS=RDRNf4KuXAUn1WYnoFU_uQ@mail.gmail.com>
	<CANhcyEU=Vi2oNRWTSph3x2884J7aTt5BTb4AzwmmY0uQAsEMMg@mail.gmail.com>
	<CAHut+Pv9ru8tNLz1LaPjuG-1X5dsLd36cFbb11e=bhYrHz60CQ@mail.gmail.com>
	<CANhcyEVDStqoR3qDSgsv5VEuBMzMX4YpdEfW-7VPX3c5Vf1YJA@mail.gmail.com>
	<CAHut+PsFNboBR8E+NRY_3hMqdpbj3y3jX1+vQTow2khgj4t=qw@mail.gmail.com>
	<CANhcyEW+aJ1rAAodQZDvCd-WpQ+b8r5wBs8H+mNdQS8URmkODg@mail.gmail.com>
	<CAHut+PvXpsFrNn2NOhepVOS7Zf_OvX-m71Wu+m-o_q9odYFXnA@mail.gmail.com>
	<CANhcyEWfzDRCiny6A_swAD7WUgdb37-TA4xTAUQ3JJXK9UPBZQ@mail.gmail.com>

Hi Shlok.

Some review comments for patches of v12

//////////
Patch v12-0001
//////////

======
src/backend/commands/publicationcmds.c

ObjectsInPublicationToOids:

1.
/*
 * Convert the PublicationObjSpecType list into schema oid list and
 * PublicationRelation list.
 */
static void
ObjectsInPublicationToOids(List *pubobjspec_list, ParseState *pstate,
   List **rels, List **excepttbls, List **exceptseqs,
   List **schemas)

I think this function comment can be made clearer. IIUC, there are 4
possible outputs from this function but the comment currently only
mentions 2. Also, it might be better to rearrange to make the
description use the same order as the output parameters.

SUGGESTION
Convert the PublicationObjSpecType list into PublicationRelation lists
(`rels`, `excepttbls`, `exceptseqs`) and a schema oid list
(`schemas`).

~~~

CreatePublication:

2.
+ if (stmt->for_all_sequences)
+ {
+ /* Process EXCEPT sequence list */
+ if (exceptseqs != NIL)
+ {
+ List    *rels = OpenRelationList(exceptseqs);
+
+ PublicationAddRelations(puboid, rels, true, NULL, RELKIND_SEQUENCE);
+ CloseRelationList(rels);
+ }
+ }

  if (stmt->for_all_tables)
  {
  /* Process EXCEPT table list */
- if (exceptrelations != NIL)
+ if (excepttbls != NIL)
  {
  List    *rels;

- rels = OpenTableList(exceptrelations);
- PublicationAddTables(puboid, rels, true, NULL);
- CloseTableList(rels);
+ rels = OpenRelationList(excepttbls);
+ PublicationAddRelations(puboid, rels, true, NULL, RELKIND_RELATION);
+ CloseRelationList(rels);

Here the 1st `rels` declaration does the assignment at the same time,
but the 2nd one does not. These code fragment are almost identical, so
let's make the declarations/assignments consistent.

~~~

3.
/* EXCEPT clause is not supported with ALTER PUBLICATION */
Assert(exceptseqs == NIL);
The comment is a bit misleading because:
- AFAIK this is only temporary for patch 0001.
- It is only EXCEPT (SEQUENCE ...) that is not supported yet; not
every EXCEPT clause.

SUGGESTION
TODO - The EXCEPT (SEQUENCE ...) clause is not yet supported with
ALTER PUBLICATION

======
src/backend/parser/gram.y

4.
static void
preprocess_pub_all_objtype_list(List *all_objects_list, List **pubobjects,
bool *all_tables, bool *all_sequences,
core_yyscan_t yyscanner)
{
if (!all_objects_list)
return;

*all_tables = false;
*all_sequences = false;

Shouldn't those assignments precede the "if (!all_objects_list)",
otherwise if the booleans are not set before the check you are relying
too much that the caller's makeNode() had set them already false on
entry.

======
src/bin/pg_dump/pg_dump.c

5.
+ /* Include EXCEPT (SEQUENCE) clause if there are except_sequences. */
+ for (SimplePtrListCell *cell = pubinfo->except_sequences.head; cell;
cell = cell->next)
+ {
+ TableInfo  *tbinfo = (TableInfo *) cell->ptr;
+
+ if (++n_except == 1)
+ appendPQExpBufferStr(query, " EXCEPT (");
+ else
+ appendPQExpBufferStr(query, ", ");
+ appendPQExpBuffer(query, "SEQUENCE %s", fmtQualifiedDumpable(tbinfo));
+ }

Unlike tables which might have qualifiers 'ONLY' and '*', there are no
additional qualifier needed for sequences, so perhaps it is better to
just generate one excluded list:

e.g.
EXCEPT (SEQUENCE a, b, c, d, e);
instead of
EXCEPT (SEQUENCE a, SEQUENCE b, SEQUENCE c, SEQUENCE d, SEQUENCE e);

~

SUGGESTION:
seqname = fmtQualifiedDumpable(tbinfo);
if (++n_except == 1)
  appendPQExpBufferStr(query, " EXCEPT (SEQUENCE %s", seqname);
else
  appendPQExpBufferStr(query, ", %s", seqname);

======
src/bin/psql/describe.c

6.
+ if (pset.sversion >= 190000)
+ {
+ appendPQExpBuffer(&buf, "\n AND NOT EXISTS (\n"
+   "     SELECT 1\n"
+   "     FROM pg_catalog.pg_publication_rel pr\n"
+   "     WHERE pr.prpubid = p.oid AND\n"
+   "     pr.prrelid = '%s')", oid);

IMO the first line should be split to make it more readable. Also the
other parts of this SQL statement put the \n at the beginning, so
maybe it is better to do same here too.

SUGGESTION
appendPQExpBuffer(&buf,
                  "\n AND NOT EXISTS ("
                  "\n     SELECT 1"
                  "\n     FROM pg_catalog.pg_publication_rel pr"
                  "\n     WHERE pr.prpubid = p.oid AND"
                  "\n     pr.prrelid = '%s')", oid);

//////////
Patch v12-0002.
//////////

======
src/backend/commands/publicationcmds.c

AlterPublicationRelations:

1.
  /*
- * In FOR ALL TABLES mode, relations are tracked as exclusions
- * (EXCEPT clause). Fetch the current excluded relations so they
- * can be reconciled with the specified EXCEPT list.
+ * In FOR ALL TABLES/ SEQUENCES mode, relations are tracked as
+ * exclusions (EXCEPT clause). Fetch the current excluded
+ * relations so they can be reconciled with the specified EXCEPT
+ * list.
  *
  * This applies only if the existing publication is already
- * defined as FOR ALL TABLES; otherwise, there are no exclusion
- * entries to process.
+ * defined as FOR ALL TABLES/ FOR ALL SEQUENCES; otherwise, there
+ * are no exclusion entries to process.
  */

One place refers to "FOR ALL TABLES/ SEQUENCES" and another says "FOR
ALL TABLES/ FOR ALL SEQUENCES". Should use consistent terminology. I
preferred the 2nd variant.

======
Kind Regards,
Peter Smith.
Fujitsu Australia






view thread (41+ messages)  latest in thread

reply

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: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected], [email protected]
  Subject: Re: Support EXCEPT for ALL SEQUENCES publications
  In-Reply-To: <CAHut+PvMXOR73+WdvSWd3B8j6jDQQXRtO_bKEudi76n30GAApQ@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox