From 7f9694ec860b756e260c2c09d8ca16085b3445ea Mon Sep 17 00:00:00 2001
From: Shveta Malik <shveta.malik@gmail.com>
Date: Fri, 11 Sep 2026 09:38:33 +0530
Subject: [PATCH] patch003 check improvement

---
 src/backend/utils/cache/relcache.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index f475d703977..d002db08f57 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -5810,6 +5810,7 @@ RelationBuildPublicationDesc(Relation relation, PublicationDesc *pubdesc)
 	Oid			schemaid;
 	List	   *ancestors = NIL;
 	Oid			relid = RelationGetRelid(relation);
+	bool		am_partition = relation->rd_rel->relispartition;
 
 	/*
 	 * If not publishable, it publishes no actions.  (pgoutput_change() will
@@ -5846,12 +5847,22 @@ RelationBuildPublicationDesc(Relation relation, PublicationDesc *pubdesc)
 	schemaid = RelationGetNamespace(relation);
 	puboids = list_concat_unique_oid(puboids, GetSchemaPublications(schemaid));
 
-	if (relation->rd_rel->relispartition)
+	/*
+	 * A partition whose concurrent detach has been committed but not
+	 * finalized reports no ancestors, even though relispartition is still
+	 * set. It is handled below like the standalone table it has effectively
+	 * become, which is also how it is handled once the detach completes.
+	 */
+	if (am_partition)
+	{
+		ancestors = get_partition_ancestors(relid);
+		am_partition = (ancestors != NIL);
+	}
+
+	if (am_partition)
 	{
 		Oid			last_ancestor_relid;
 
-		/* Add publications that the ancestors are in too. */
-		ancestors = get_partition_ancestors(relid);
 		last_ancestor_relid = llast_oid(ancestors);
 
 		foreach(lc, ancestors)
-- 
2.34.1

