From: Tom Lane Date: Sat, 12 Jun 2021 17:29:24 +0000 (-0400) Subject: Ensure pg_filenode_relation(0, 0) returns NULL. X-Git-Tag: REL9_6_23~79 X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=c1ffbbcbca93b3544c0b57b7ab063497794cb8ff;p=postgresql.git Ensure pg_filenode_relation(0, 0) returns NULL. Previously, a zero value for the relfilenode resulted in a confusing error message about "unexpected duplicate". This function returns NULL for other invalid relfilenode values, so zero should be treated likewise. It's been like this all along, so back-patch to all supported branches. Justin Pryzby Discussion: https://postgr.es/m/20210612023324.GT16435@telsasoft.com --- diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c index 74cdbb05510..2227ccc2c45 100644 --- a/src/backend/utils/adt/dbsize.c +++ b/src/backend/utils/adt/dbsize.c @@ -919,7 +919,11 @@ pg_filenode_relation(PG_FUNCTION_ARGS) { Oid reltablespace = PG_GETARG_OID(0); Oid relfilenode = PG_GETARG_OID(1); - Oid heaprel = InvalidOid; + Oid heaprel; + + /* test needed so RelidByRelfilenode doesn't misbehave */ + if (!OidIsValid(relfilenode)) + PG_RETURN_NULL(); heaprel = RelidByRelfilenode(reltablespace, relfilenode);