Re: pg_filenode_relation(0,0) elog

From: Justin Pryzby <pryzby(at)telsasoft(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: pg_filenode_relation(0,0) elog
Date: 2021-06-12 15:12:34
Message-ID: 20210612151234.GW16435@telsasoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Jun 11, 2021 at 11:51:35PM -0400, Tom Lane wrote:
> Justin Pryzby <pryzby(at)telsasoft(dot)com> writes:
> > Per sqlsmith.
> > postgres=# SELECT pg_filenode_relation(0,0);
> > ERROR: unexpected duplicate for tablespace 0, relfilenode 0
>
> Ugh.
>
> > The usual expectation is that sql callable functions should return null rather
> > than hitting elog().
>
> Agreed, but you should put the short-circuit into the SQL-callable
> function, ie pg_filenode_relation. Lower-level callers ought not be
> passing junk data.

Right. I spent inadequate time reading output of git grep.

> Likely it should check the reltablespace, too.

I don't think so. The docs say:
https://www.postgresql.org/docs/current/functions-admin.html#FUNCTIONS-ADMIN-DBLOCATION
|For a relation in the database's default tablespace, the tablespace can be specified as zero.

Also, that would breaks expected/alter_table.out for the same reason.

diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c
index 3c70bb5943..144aca1099 100644
--- a/src/backend/utils/adt/dbsize.c
+++ b/src/backend/utils/adt/dbsize.c
@@ -905,6 +905,9 @@ pg_filenode_relation(PG_FUNCTION_ARGS)
Oid relfilenode = PG_GETARG_OID(1);
Oid heaprel = InvalidOid;

+ if (!OidIsValid(relfilenode))
+ PG_RETURN_NULL();
+
heaprel = RelidByRelfilenode(reltablespace, relfilenode);

if (!OidIsValid(heaprel))

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Noah Misch 2021-06-12 15:21:39 Re: A new function to wait for the backend exit after termination
Previous Message David Rowley 2021-06-12 15:07:18 Add proper planner support for ORDER BY / DISTINCT aggregates