pg_get_first_normal_oid()?

From: "Joel Jacobson" <joel(at)compiler(dot)org>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: pg_get_first_normal_oid()?
Date: 2021-02-10 07:43:09
Message-ID: 76599f1f-50cb-46c7-b14f-8f56bb860d31@www.fastmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

I need to filter out any system catalog objects from SQL,
and I've learned it's not possible to simply filter based on namespace name,
since there are objects such as pg_am that don't have any namespace belonging,
except indirectly via their handler, but since you can define a new access method
using an existing handler from the system catalog, there is no way to distinguish
your user created access handler from the system catalog access handlers
only based on namespace name based filtering.

After some digging I found this

#define FirstNormalObjectId 16384

in src/include/access/transam.h, which pg_dump.c and 14 other files are using at 27 different places in the sources.

Seems to be a popular and important fellow.

I see this value doesn't change often, it was added back in 2005-04-13 in commit 2193a856a229026673cbc56310cd0bddf7b5ea25.

Is it safe to just hard-code in application code needing to know this cut-off value?

Or will we have a Bill Gates "640K ought to be enough for anybody" moment in the foreseeable future,
where this limit needs to be increased?

If there is a risk we will, then maybe we should add a function such as $SUBJECT to expose this value to SQL users who needs it?

I see there has been a related discussion in the thread "Identifying user-created objects"

https://www.postgresql.org/message-id/flat/CA%2Bfd4k7Zr%2ByQLYWF3O_KjAJyYYUZFBZ_dFchfBvq5bMj9GgKQw%40mail.gmail.com

However, this thread focused on security and wants to know if a specific oid is user defined or not.

I think pg_get_first_normal_oid() would be more useful than pg_is_user_object(oid),
since with pg_get_first_normal_oid() you could do filtering based on oid indexes.

Compare e.g.:

SELECT * FROM pg_class WHERE oid >= pg_get_first_normal_oid()

with..

SELECT * FROM pg_class WHERE pg_is_user_object(oid) IS TRUE

The first query could use the index on pg_class.oid,
whereas I'm not mistaken, the second query would need a seq_scan to evaluate pg_is_user_object() for each oid.

/Joel

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2021-02-10 07:58:18 Re: 64-bit XIDs in deleted nbtree pages
Previous Message Amit Langote 2021-02-10 07:30:26 Re: Parallel INSERT (INTO ... SELECT ...)