pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feedpg_filenode_relation(0,0) elog
4+ messages / 2 participants
[nested] [flat]
Commits from this thread:
2021-06-12 1250aad425 7681b78fba 25d1ef1aaf c1ffbbcbca 26a0535334 f479ea94bd Ensure pg_filenode_relation(0, 0) returns NULL.
* pg_filenode_relation(0,0) elog
@ 2021-06-12 02:33 Justin Pryzby <pryzby@telsasoft.com>
0 siblings, 1 reply; 4+ messages in thread
From: Justin Pryzby @ 2021-06-12 02:33 UTC (permalink / raw)
To: pgsql-hackers@lists.postgresql.org
Per sqlsmith.
postgres=# SELECT pg_filenode_relation(0,0);
ERROR: unexpected duplicate for tablespace 0, relfilenode 0
postgres=# \errverbose
ERROR: XX000: unexpected duplicate for tablespace 0, relfilenode 0
LOCATION: RelidByRelfilenode, relfilenodemap.c:220
The usual expectation is that sql callable functions should return null rather
than hitting elog(). This also means that sqlsmith has one fewer
false-positive error.
I think it should return NULL if passed invalid relfilenode, rather than
searching pg_class and then writing a pretty scary message about duplicates.
inline patch 1: src/backend/utils/cache/relfilenodemap.c (+3/-0 lines) download inline-1.patch
diff --git a/src/backend/utils/cache/relfilenodemap.c b/src/backend/utils/cache/relfilenodemap.c
index 56d7c73d33..5a5cf853bd 100644
--- a/src/backend/utils/cache/relfilenodemap.c
+++ b/src/backend/utils/cache/relfilenodemap.c
@@ -146,6 +146,9 @@ RelidByRelfilenode(Oid reltablespace, Oid relfilenode)
ScanKeyData skey[2];
Oid relid;
+ if (!OidIsValid(relfilenode))
+ return InvalidOid;
+
if (RelfilenodeMapHash == NULL)
InitializeRelfilenodeMap();
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: pg_filenode_relation(0,0) elog
@ 2021-06-12 03:51 Tom Lane <tgl@sss.pgh.pa.us>
parent: Justin Pryzby <pryzby@telsasoft.com>
0 siblings, 1 reply; 4+ messages in thread
From: Tom Lane @ 2021-06-12 03:51 UTC (permalink / raw)
To: Justin Pryzby <pryzby@telsasoft.com>; +Cc: pgsql-hackers@lists.postgresql.org
Justin Pryzby <pryzby@telsasoft.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.
Likely it should check the reltablespace, too.
regards, tom lane
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: pg_filenode_relation(0,0) elog
@ 2021-06-12 15:12 Justin Pryzby <pryzby@telsasoft.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 4+ messages in thread
From: Justin Pryzby @ 2021-06-12 15:12 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-hackers@lists.postgresql.org
On Fri, Jun 11, 2021 at 11:51:35PM -0400, Tom Lane wrote:
> Justin Pryzby <pryzby@telsasoft.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.
inline patch 1: src/backend/utils/adt/dbsize.c (+3/-0 lines) download inline-1.patch
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))
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: pg_filenode_relation(0,0) elog
@ 2021-06-12 17:30 Tom Lane <tgl@sss.pgh.pa.us>
parent: Justin Pryzby <pryzby@telsasoft.com>
0 siblings, 0 replies; 4+ messages in thread
From: Tom Lane @ 2021-06-12 17:30 UTC (permalink / raw)
To: Justin Pryzby <pryzby@telsasoft.com>; +Cc: pgsql-hackers@lists.postgresql.org
Justin Pryzby <pryzby@telsasoft.com> writes:
> On Fri, Jun 11, 2021 at 11:51:35PM -0400, Tom Lane wrote:
>> 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.
Right, my mistake. Pushed.
regards, tom lane
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2021-06-12 17:30 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-06-12 02:33 pg_filenode_relation(0,0) elog Justin Pryzby <pryzby@telsasoft.com>
2021-06-12 03:51 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-06-12 15:12 ` Justin Pryzby <pryzby@telsasoft.com>
2021-06-12 17:30 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox