From 6a0457506c0607a935ae7c94caa8c45f46635f09 Mon Sep 17 00:00:00 2001 From: Shveta Malik Date: Tue, 10 Nov 2026 01:13:46 +0530 Subject: [PATCH] last table-fetch wrong-result fix --- src/backend/catalog/pg_publication.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c index 05cca134065..6825e7528c5 100644 --- a/src/backend/catalog/pg_publication.c +++ b/src/backend/catalog/pg_publication.c @@ -1728,10 +1728,37 @@ pg_get_publication_tables(FunctionCallInfo fcinfo, ArrayType *pubnames, !SearchSysCacheExists2(PUBLICATIONNAMESPACEMAP, ObjectIdGetDatum(schemaid), ObjectIdGetDatum(pub->oid))) + { pubtuple = SearchSysCacheCopy2(PUBLICATIONRELMAP, ObjectIdGetDatum(relid), ObjectIdGetDatum(pub->oid)); + /* + * No pg_publication_rel entry is normal for partitions published + * via their parent. However, it can also mean the publication was + * dropped concurrently, as the lookups above process pending + * invalidations when opening the catalogs with a cold cache. + * Distinguish these cases to avoid returning incorrect column + * lists and row filters. If an entry was found, it represents the + * publication definition before the drop. + */ + if (!HeapTupleIsValid(pubtuple) && + !SearchSysCacheExists1(PUBLICATIONOID, + ObjectIdGetDatum(pub->oid))) + { + if (!pub_missing_ok) + ereport(ERROR, + errcode(ERRCODE_UNDEFINED_OBJECT), + errmsg("publication \"%s\" does not exist", + get_pubname_from_list(ptstate->pubs, + table_info->pubid)), + errdetail("The publication was dropped concurrently.")); + + table_close(rel, AccessShareLock); + continue; + } + } + if (HeapTupleIsValid(pubtuple)) { /* Lookup the column list attribute. */ -- 2.34.1