From c390156f63b7dd7e0f1de74545f97451aff8b5a3 Mon Sep 17 00:00:00 2001 From: Shveta Malik Date: Tue, 15 Sep 2026 10:03:11 +0530 Subject: [PATCH] getPublicationRelationDescription function --- src/backend/catalog/objectaddress.c | 72 +++++++++++++++-------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/src/backend/catalog/objectaddress.c b/src/backend/catalog/objectaddress.c index 2cbb186e20f..ffcd97e7ce5 100644 --- a/src/backend/catalog/objectaddress.c +++ b/src/backend/catalog/objectaddress.c @@ -886,13 +886,14 @@ static void getRelationTypeDescription(StringInfo buffer, Oid relid, int32 objectSubId, bool missing_ok); static void getProcedureTypeDescription(StringInfo buffer, Oid procid, bool missing_ok); +static void getPublicationRelationDescription(StringInfo buffer, Oid pubreloid, + bool missing_ok); static void getConstraintTypeDescription(StringInfo buffer, Oid constroid, bool missing_ok); static void getOpFamilyIdentity(StringInfo buffer, Oid opfid, List **object, bool missing_ok); static void getRelationIdentity(StringInfo buffer, Oid relid, List **object, bool missing_ok); -static bool isPublicationRelationExcept(Oid pubreloid, bool missing_ok); /* * Translate an object name and arguments (as passed by the parser) to an @@ -1949,35 +1950,6 @@ get_object_address_publication_rel(List *object, return address; } -/* - * Return whether a pg_publication_rel entry represents a publication EXCEPT - * entry. - */ -static bool -isPublicationRelationExcept(Oid pubreloid, bool missing_ok) -{ - HeapTuple tup; - Form_pg_publication_rel prform; - bool result; - - tup = SearchSysCache1(PUBLICATIONREL, ObjectIdGetDatum(pubreloid)); - if (!HeapTupleIsValid(tup)) - { - if (!missing_ok) - elog(ERROR, "cache lookup failed for publication table %u", - pubreloid); - - /* fallback to a non-exclusion entry for an undefined object */ - return false; - } - - prform = (Form_pg_publication_rel) GETSTRUCT(tup); - result = prform->prexcept; - - ReleaseSysCache(tup); - - return result; -} /* * Find the ObjectAddress for a publication schema. The first element of the @@ -4747,10 +4719,7 @@ getObjectTypeDescription(const ObjectAddress *object, bool missing_ok) break; case PublicationRelRelationId: - if (isPublicationRelationExcept(object->objectId, missing_ok)) - appendStringInfoString(&buffer, "publication excluded relation"); - else - appendStringInfoString(&buffer, "publication relation"); + getPublicationRelationDescription(&buffer, object->objectId, missing_ok); break; case SubscriptionRelationId: @@ -4904,6 +4873,41 @@ getProcedureTypeDescription(StringInfo buffer, Oid procid, ReleaseSysCache(procTup); } +/* + * subroutine for getObjectTypeDescription: describe a publication relation + * + * Appends "publication excluded relation" for EXCEPT entries, or + * "publication relation" for published relations, to buffer. + */ +static void +getPublicationRelationDescription(StringInfo buffer, Oid pubreloid, + bool missing_ok) +{ + HeapTuple tup; + Form_pg_publication_rel prform; + + tup = SearchSysCache1(PUBLICATIONREL, ObjectIdGetDatum(pubreloid)); + if (!HeapTupleIsValid(tup)) + { + if (!missing_ok) + elog(ERROR, "cache lookup failed for publication relation %u", + pubreloid); + + /* fallback to "publication relation" for an undefined object */ + appendStringInfoString(buffer, "publication relation"); + return; + } + + prform = (Form_pg_publication_rel) GETSTRUCT(tup); + + if (prform->prexcept) + appendStringInfoString(buffer, "publication excluded relation"); + else + appendStringInfoString(buffer, "publication relation"); + + ReleaseSysCache(tup); +} + /* * Obtain a given object's identity, as a palloc'ed string. * -- 2.34.1