From 2d6feef3d53ce1fc7f61d988af4f72257a6467b8 Mon Sep 17 00:00:00 2001 From: Vignesh C Date: Sat, 12 Sep 2026 19:12:48 +0530 Subject: [PATCH v1 2/2] Review comment fixes. Review comment fixes. --- src/backend/catalog/objectaddress.c | 52 +++++++++++++------- src/test/regress/expected/object_address.out | 17 +++++++ src/test/regress/expected/publication.out | 29 ++++++----- src/test/regress/sql/object_address.sql | 17 +++++++ src/test/regress/sql/publication.sql | 22 +++++---- 5 files changed, 96 insertions(+), 41 deletions(-) diff --git a/src/backend/catalog/objectaddress.c b/src/backend/catalog/objectaddress.c index 50b61140b47..a1506594b26 100644 --- a/src/backend/catalog/objectaddress.c +++ b/src/backend/catalog/objectaddress.c @@ -826,7 +826,7 @@ static const struct object_type_map "publication relation", OBJECT_PUBLICATION_REL }, { - "publication exclusion", OBJECT_PUBLICATION_REL + "publication excluded relation", OBJECT_PUBLICATION_REL }, { "subscription", OBJECT_SUBSCRIPTION @@ -1882,6 +1882,7 @@ get_object_address_publication_rel(List *object, List *relname; char *pubname; Publication *pub; + HeapTuple tup; ObjectAddressSet(address, PublicationRelRelationId, InvalidOid); @@ -1902,17 +1903,32 @@ get_object_address_publication_rel(List *object, return address; } - /* Find the publication relation mapping in syscache. */ - address.objectId = - GetSysCacheOid2(PUBLICATIONRELMAP, Anum_pg_publication_rel_oid, - ObjectIdGetDatum(RelationGetRelid(relation)), - ObjectIdGetDatum(pub->oid)); - if (OidIsValid(address.objectId) && - pubrel_is_exclusion == isPublicationRelationExcept(address.objectId, - missing_ok)) + /* + * Find the publication relation mapping in syscache. Fetch the tuple + * rather than just its OID, so that prexcept can be checked without a + * second lookup. A missing entry, or one of the other kind, falls + * through to the not-found handling below. + */ + tup = SearchSysCache2(PUBLICATIONRELMAP, + ObjectIdGetDatum(RelationGetRelid(relation)), + ObjectIdGetDatum(pub->oid)); + if (HeapTupleIsValid(tup)) { - *relp = relation; - return address; + /* Found row in pg_publication_rel */ + Form_pg_publication_rel prform = + (Form_pg_publication_rel) GETSTRUCT(tup); + Oid pubreloid = prform->oid; + bool isexcept = prform->prexcept; + + ReleaseSysCache(tup); + + /* Treat a prexcept mismatch as not found. */ + if (isexcept == pubrel_is_exclusion) + { + address.objectId = pubreloid; + *relp = relation; + return address; + } } if (!missing_ok) @@ -1920,7 +1936,7 @@ get_object_address_publication_rel(List *object, if (pubrel_is_exclusion) ereport(ERROR, (errcode(ERRCODE_UNDEFINED_OBJECT), - errmsg("publication exclusion \"%s\" from publication \"%s\" does not exist", + errmsg("publication excluded relation \"%s\" from publication \"%s\" does not exist", RelationGetRelationName(relation), pubname))); else ereport(ERROR, @@ -1929,15 +1945,13 @@ get_object_address_publication_rel(List *object, RelationGetRelationName(relation), pubname))); } - /* Treat a missing mapping or type/prexcept mismatch as not found. */ - address.objectId = InvalidOid; relation_close(relation, AccessShareLock); return address; } /* - * Return whether an existing pg_publication_rel entry represents a publication - * EXCEPT entry. + * Return whether a pg_publication_rel entry represents a publication EXCEPT + * entry. */ static bool isPublicationRelationExcept(Oid pubreloid, bool missing_ok) @@ -1953,6 +1967,7 @@ isPublicationRelationExcept(Oid pubreloid, bool missing_ok) elog(ERROR, "cache lookup failed for publication table %u", pubreloid); + /* fallback to a non-exclusion entry for an undefined object */ return false; } @@ -2183,7 +2198,6 @@ pg_get_object_address(PG_FUNCTION_ARGS) (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("unsupported object type \"%s\"", ttype))); type = (ObjectType) itype; - pubrel_is_exclusion = (strcmp(ttype, "publication exclusion") == 0); /* * Convert the text array to the representation appropriate for the given @@ -2415,6 +2429,8 @@ pg_get_object_address(PG_FUNCTION_ARGS) if (objnode == NULL) elog(ERROR, "unrecognized object type: %d", type); + pubrel_is_exclusion = + (strcmp(ttype, "publication excluded relation") == 0); if (pubrel_is_exclusion) { addr = get_object_address_publication_rel(castNode(List, objnode), @@ -4732,7 +4748,7 @@ getObjectTypeDescription(const ObjectAddress *object, bool missing_ok) case PublicationRelRelationId: if (isPublicationRelationExcept(object->objectId, missing_ok)) - appendStringInfoString(&buffer, "publication exclusion"); + appendStringInfoString(&buffer, "publication excluded relation"); else appendStringInfoString(&buffer, "publication relation"); break; diff --git a/src/test/regress/expected/object_address.out b/src/test/regress/expected/object_address.out index 4c266d7fa67..1ac9c0cc387 100644 --- a/src/test/regress/expected/object_address.out +++ b/src/test/regress/expected/object_address.out @@ -509,6 +509,23 @@ subscription|NULL|regress_addr_sub|regress_addr_sub|t publication|NULL|addr_pub|addr_pub|t publication relation|NULL|NULL|addr_nsp.gentable in publication addr_pub|t publication namespace|NULL|NULL|addr_nsp in publication addr_pub_schema|t +-- A FOR ALL TABLES publication is listed by \d for every table in the +-- database, which would disturb the other tests running concurrently in this +-- parallel group. Create it in a transaction that is rolled back, so that it +-- is never visible to another session. +BEGIN; +SET LOCAL client_min_messages = 'ERROR'; +CREATE PUBLICATION addr_pub_except FOR ALL TABLES EXCEPT (TABLE addr_nsp.gentable); +SELECT (pg_identify_object(addr1.classid, addr1.objid, addr1.objsubid)).*, + ROW(pg_identify_object(addr1.classid, addr1.objid, addr1.objsubid)) = + ROW(pg_identify_object(addr2.classid, addr2.objid, addr2.objsubid)) AS roundtrip +FROM pg_get_object_address('publication excluded relation', + '{addr_nsp, gentable}', + '{addr_pub_except}') AS addr1, + pg_identify_object_as_address(classid, objid, objsubid) AS ioa (typ, nms, args), + pg_get_object_address(typ, nms, ioa.args) AS addr2; +publication excluded relation|NULL|NULL|addr_nsp.gentable excluded from publication addr_pub_except|t +ROLLBACK; --- --- Cleanup resources --- diff --git a/src/test/regress/expected/publication.out b/src/test/regress/expected/publication.out index 51891405d9e..dd9e6d6cd6b 100644 --- a/src/test/regress/expected/publication.out +++ b/src/test/regress/expected/publication.out @@ -274,7 +274,7 @@ Excluded from publications: "testpub_foralltables_excepttable" "testpub_foralltables_excepttable1" --- Check object address handling for an EXCEPT entry +-- Check object address handling for an EXCEPT entry. \a\t SELECT (pg_identify_object('pg_publication_rel'::regclass, pr.oid, 0)).* FROM pg_publication_rel pr @@ -282,23 +282,26 @@ JOIN pg_publication p ON p.oid = pr.prpubid JOIN pg_class c ON c.oid = pr.prrelid WHERE p.pubname = 'testpub_foralltables_excepttable1' AND c.relname = 'testpub_tbl1'; -publication exclusion|||public.testpub_tbl1 excluded from publication testpub_foralltables_excepttable1 -SELECT (pg_identify_object(addr1.classid, addr1.objid, addr1.objsubid)).*, - ROW(pg_identify_object(addr1.classid, addr1.objid, addr1.objsubid)) = - ROW(pg_identify_object(addr2.classid, addr2.objid, addr2.objsubid)) AS roundtrip -FROM pg_get_object_address('publication exclusion', - '{public, testpub_tbl1}', - '{testpub_foralltables_excepttable1}') AS addr1, - pg_identify_object_as_address(classid, objid, objsubid) AS ioa (typ, nms, args), - pg_get_object_address(typ, nms, ioa.args) AS addr2; -publication exclusion|||public.testpub_tbl1 excluded from publication testpub_foralltables_excepttable1|t -SELECT pg_get_object_address('publication exclusion', +publication excluded relation|||public.testpub_tbl1 excluded from publication testpub_foralltables_excepttable1 +SELECT pg_get_object_address('publication excluded relation', '{public, testpub_tbl1}', '{testpub_fortable}'); -ERROR: publication exclusion "testpub_tbl1" from publication "testpub_fortable" does not exist +ERROR: publication excluded relation "testpub_tbl1" from publication "testpub_fortable" does not exist SELECT pg_get_object_address('publication relation', '{public, testpub_tbl1}', '{testpub_foralltables_excepttable1}'); ERROR: publication relation "testpub_tbl1" in publication "testpub_foralltables_excepttable1" does not exist +-- Check pg_describe_object output for both included and excluded entries +CREATE PUBLICATION testpub_describe FOR TABLE testpub_tbl1; +SELECT p.pubname, + pg_describe_object('pg_publication_rel'::regclass, pr.oid, 0) AS description, + pr.prexcept +FROM pg_publication_rel pr +JOIN pg_publication p ON p.oid = pr.prpubid +WHERE p.pubname IN ('testpub_describe', 'testpub_foralltables_excepttable1') +ORDER BY p.pubname; +testpub_describe|publication of table testpub_tbl1 in publication testpub_describe|f +testpub_foralltables_excepttable1|exclusion of table testpub_tbl1 from publication testpub_foralltables_excepttable1|t +DROP PUBLICATION testpub_describe; \a\t -- fail - first table in the EXCEPT list should use TABLE keyword CREATE PUBLICATION testpub_foralltables_excepttable2 FOR ALL TABLES EXCEPT (testpub_tbl1, testpub_tbl2); diff --git a/src/test/regress/sql/object_address.sql b/src/test/regress/sql/object_address.sql index 653a53038e3..518442bb641 100644 --- a/src/test/regress/sql/object_address.sql +++ b/src/test/regress/sql/object_address.sql @@ -225,6 +225,23 @@ FROM objects, pg_get_object_address(typ, nms, ioa.args) AS addr2 ORDER BY addr1.classid, addr1.objid, addr1.objsubid; +-- A FOR ALL TABLES publication is listed by \d for every table in the +-- database, which would disturb the other tests running concurrently in this +-- parallel group. Create it in a transaction that is rolled back, so that it +-- is never visible to another session. +BEGIN; +SET LOCAL client_min_messages = 'ERROR'; +CREATE PUBLICATION addr_pub_except FOR ALL TABLES EXCEPT (TABLE addr_nsp.gentable); +SELECT (pg_identify_object(addr1.classid, addr1.objid, addr1.objsubid)).*, + ROW(pg_identify_object(addr1.classid, addr1.objid, addr1.objsubid)) = + ROW(pg_identify_object(addr2.classid, addr2.objid, addr2.objsubid)) AS roundtrip +FROM pg_get_object_address('publication excluded relation', + '{addr_nsp, gentable}', + '{addr_pub_except}') AS addr1, + pg_identify_object_as_address(classid, objid, objsubid) AS ioa (typ, nms, args), + pg_get_object_address(typ, nms, ioa.args) AS addr2; +ROLLBACK; + --- --- Cleanup resources --- diff --git a/src/test/regress/sql/publication.sql b/src/test/regress/sql/publication.sql index 1e3e9f649d5..257262f0734 100644 --- a/src/test/regress/sql/publication.sql +++ b/src/test/regress/sql/publication.sql @@ -123,7 +123,7 @@ CREATE PUBLICATION testpub_foralltables_excepttable1 FOR ALL TABLES EXCEPT (TABL -- Check that the table description shows the publications where it is listed -- in the EXCEPT clause \d testpub_tbl1 --- Check object address handling for an EXCEPT entry +-- Check object address handling for an EXCEPT entry. \a\t SELECT (pg_identify_object('pg_publication_rel'::regclass, pr.oid, 0)).* FROM pg_publication_rel pr @@ -131,19 +131,21 @@ JOIN pg_publication p ON p.oid = pr.prpubid JOIN pg_class c ON c.oid = pr.prrelid WHERE p.pubname = 'testpub_foralltables_excepttable1' AND c.relname = 'testpub_tbl1'; -SELECT (pg_identify_object(addr1.classid, addr1.objid, addr1.objsubid)).*, - ROW(pg_identify_object(addr1.classid, addr1.objid, addr1.objsubid)) = - ROW(pg_identify_object(addr2.classid, addr2.objid, addr2.objsubid)) AS roundtrip -FROM pg_get_object_address('publication exclusion', - '{public, testpub_tbl1}', - '{testpub_foralltables_excepttable1}') AS addr1, - pg_identify_object_as_address(classid, objid, objsubid) AS ioa (typ, nms, args), - pg_get_object_address(typ, nms, ioa.args) AS addr2; -SELECT pg_get_object_address('publication exclusion', +SELECT pg_get_object_address('publication excluded relation', '{public, testpub_tbl1}', '{testpub_fortable}'); SELECT pg_get_object_address('publication relation', '{public, testpub_tbl1}', '{testpub_foralltables_excepttable1}'); +-- Check pg_describe_object output for both included and excluded entries +CREATE PUBLICATION testpub_describe FOR TABLE testpub_tbl1; +SELECT p.pubname, + pg_describe_object('pg_publication_rel'::regclass, pr.oid, 0) AS description, + pr.prexcept +FROM pg_publication_rel pr +JOIN pg_publication p ON p.oid = pr.prpubid +WHERE p.pubname IN ('testpub_describe', 'testpub_foralltables_excepttable1') +ORDER BY p.pubname; +DROP PUBLICATION testpub_describe; \a\t -- fail - first table in the EXCEPT list should use TABLE keyword CREATE PUBLICATION testpub_foralltables_excepttable2 FOR ALL TABLES EXCEPT (testpub_tbl1, testpub_tbl2); -- 2.55.0