On Thu, 18 Dec 2025 at 12:37, Shlok Kyal <[email protected]> wrote:
>
> Hi Team,
>
> While working on another thread, I noticed a bug introduced by commit
> as part of this thread.
> In function pg_get_publication_tables, We have code:
> ```
>                      if (pub_elem->alltables)
> pub_elem_tables = GetAllPublicationRelations(RELKIND_RELATION,
>  pub_elem->pubviaroot);
> else
> {
> List     *relids,
>    *schemarelids;
>
> relids = GetPublicationRelations(pub_elem->oid,
>  pub_elem->pubviaroot ?
>  PUBLICATION_PART_ROOT :
>  PUBLICATION_PART_LEAF);
> schemarelids = GetAllSchemaPublicationRelations(pub_elem->oid,
> pub_elem->pubviaroot ?
> PUBLICATION_PART_ROOT :
> PUBLICATION_PART_LEAF);
> pub_elem_tables = list_concat_unique_oid(relids, schemarelids);
> }
> ```
>
> So, when we create an 'ALL SEQUENCE publication' and we execute
> 'SELECT * from pg_publication_tables'
> We will enter the else condition in the above code, which does not
> seem correct to me.
> It will call functions which are not required to be called. It will
> also call the function 'GetPublicationRelations' which contradicts the
> comment above this function.
>
> Similar issue is present for functions "InvalidatePubRelSyncCache" and
> "AlterPublicationOptions".

Thanks Shlok for reporting these issues,  In the areas highlighted, we
can skip processing for sequences-only publications. The attached
patch implements these changes.

Regards,
Vignesh
From f607b671dc6c009fb7f56412840f0e6c8e368239 Mon Sep 17 00:00:00 2001
From: Vignesh C <[email protected]>
Date: Thu, 18 Dec 2025 14:59:44 +0530
Subject: [PATCH] Skip table specific handling for sequences only publications

Skip trying to get the list of tables, publish_via_partition_root
handling, and invalidation where the publication does not publish
tables. This avoids unnecessary work and ensures table specific
logic is applied only to relevant publications.
---
 src/backend/catalog/pg_publication.c   | 11 ++++++++---
 src/backend/commands/alter.c           |  7 +++++--
 src/backend/commands/publicationcmds.c |  6 +++---
 3 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c
index 7aa3f179924..39410120f65 100644
--- a/src/backend/catalog/pg_publication.c
+++ b/src/backend/catalog/pg_publication.c
@@ -1170,7 +1170,7 @@ pg_get_publication_tables(PG_FUNCTION_ARGS)
 			if (pub_elem->alltables)
 				pub_elem_tables = GetAllPublicationRelations(RELKIND_RELATION,
 															 pub_elem->pubviaroot);
-			else
+			else if (!pub_elem->allsequences)
 			{
 				List	   *relids,
 						   *schemarelids;
@@ -1203,8 +1203,13 @@ pg_get_publication_tables(PG_FUNCTION_ARGS)
 				table_infos = lappend(table_infos, table_info);
 			}
 
-			/* At least one publication is using publish_via_partition_root. */
-			if (pub_elem->pubviaroot)
+			/*
+			 * At least one publication is using publish_via_partition_root.
+			 * Skip sequences only publications, as publish_via_partition_root
+			 * is applicable only to table publications.
+			 */
+			if (pub_elem->pubviaroot &&
+				(!pub_elem->allsequences || pub_elem->alltables))
 				viaroot = true;
 		}
 
diff --git a/src/backend/commands/alter.c b/src/backend/commands/alter.c
index cb75e11fced..e79756af7bb 100644
--- a/src/backend/commands/alter.c
+++ b/src/backend/commands/alter.c
@@ -349,9 +349,12 @@ AlterObjectRename_internal(Relation rel, Oid objectId, const char *new_name)
 		 * Unlike ALTER PUBLICATION ADD/SET/DROP commands, renaming a
 		 * publication does not impact the publication status of tables. So,
 		 * we don't need to invalidate relcache to rebuild the rd_pubdesc.
-		 * Instead, we invalidate only the relsyncache.
+		 * Instead, invalidate the relation sync cache for publications that
+		 * include tables. Invalidation is not required for sequences only
+		 * publications.
 		 */
-		InvalidatePubRelSyncCache(pub->oid, pub->puballtables);
+		if (!pub->puballsequences || pub->puballtables)
+			InvalidatePubRelSyncCache(pub->oid, pub->puballtables);
 	}
 
 	/* Release memory */
diff --git a/src/backend/commands/publicationcmds.c b/src/backend/commands/publicationcmds.c
index a1983508950..e128789a673 100644
--- a/src/backend/commands/publicationcmds.c
+++ b/src/backend/commands/publicationcmds.c
@@ -1028,8 +1028,8 @@ AlterPublicationOptions(ParseState *pstate, AlterPublicationStmt *stmt,
 	 * disallow using WHERE clause and column lists on partitioned table in
 	 * this case.
 	 */
-	if (!pubform->puballtables && publish_via_partition_root_given &&
-		!publish_via_partition_root)
+	if (!pubform->puballtables && !pubform->puballsequences &&
+		publish_via_partition_root_given && !publish_via_partition_root)
 	{
 		/*
 		 * Lock the publication so nobody else can do anything with it. This
@@ -1149,7 +1149,7 @@ AlterPublicationOptions(ParseState *pstate, AlterPublicationStmt *stmt,
 	{
 		CacheInvalidateRelcacheAll();
 	}
-	else
+	else if (!pubform->puballsequences)
 	{
 		List	   *relids = NIL;
 		List	   *schemarelids = NIL;
-- 
2.43.0

Reply via email to