Ensure pg_filenode_relation(0, 0) returns NULL.
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 12 Jun 2021 17:29:24 +0000 (13:29 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 12 Jun 2021 17:29:24 +0000 (13:29 -0400)
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

src/backend/utils/adt/dbsize.c

index 515e30d1777252c85b0bb78dc3b7568f1984bf3c..ff2a0160bfb4d5b4fed5bea10551739d6857ade4 100644 (file)
@@ -926,7 +926,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);