public inbox for [email protected]  
help / color / mirror / Atom feed
Re: Request for new column in pg_namespace
4+ messages / 3 participants
[nested] [flat]

* Re: Request for new column in pg_namespace
@ 2024-12-15 17:40 Isaac Morland <[email protected]>
  2024-12-15 19:20 ` Re: Request for new column in pg_namespace Tom Lane <[email protected]>
  0 siblings, 1 reply; 4+ messages in thread

From: Isaac Morland @ 2024-12-15 17:40 UTC (permalink / raw)
  To: Tom Lane <[email protected]>; +Cc: Pavel Stehule <[email protected]>; Ron Johnson <[email protected]>; pgsql-general

On Sun, 15 Dec 2024 at 12:29, Tom Lane <[email protected]> wrote:


> What I'd suggest as an improvement that could be implemented
> immediately is to wrap the checks in a user-defined function
> like "is_system_schema(nspname name)".
>

Would it make sense to make the parameter be of type regnamespace?


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Request for new column in pg_namespace
  2024-12-15 17:40 Re: Request for new column in pg_namespace Isaac Morland <[email protected]>
@ 2024-12-15 19:20 ` Tom Lane <[email protected]>
  2024-12-15 20:05   ` Re: Request for new column in pg_namespace Isaac Morland <[email protected]>
  2024-12-16 00:16   ` Re: Request for new column in pg_namespace Ron Johnson <[email protected]>
  0 siblings, 2 replies; 4+ messages in thread

From: Tom Lane @ 2024-12-15 19:20 UTC (permalink / raw)
  To: Isaac Morland <[email protected]>; +Cc: Pavel Stehule <[email protected]>; Ron Johnson <[email protected]>; pgsql-general

Isaac Morland <[email protected]> writes:
> On Sun, 15 Dec 2024 at 12:29, Tom Lane <[email protected]> wrote:
>> What I'd suggest as an improvement that could be implemented
>> immediately is to wrap the checks in a user-defined function
>> like "is_system_schema(nspname name)".

> Would it make sense to make the parameter be of type regnamespace?

Meh ... you could, but what the function really needs is the name.
Getting from regnamespace (which is an OID) to the name would incur
an extra syscache lookup.  Admittedly, if it removes the need for
the calling query to join to pg_namespace at all, you'd probably
come out about even --- the net effect would be about like a
hashjoin to pg_namespace, I think, since the syscache would act
like the inner hashtable of a hashjoin.

			regards, tom lane






^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Request for new column in pg_namespace
  2024-12-15 17:40 Re: Request for new column in pg_namespace Isaac Morland <[email protected]>
  2024-12-15 19:20 ` Re: Request for new column in pg_namespace Tom Lane <[email protected]>
@ 2024-12-15 20:05   ` Isaac Morland <[email protected]>
  1 sibling, 0 replies; 4+ messages in thread

From: Isaac Morland @ 2024-12-15 20:05 UTC (permalink / raw)
  To: Tom Lane <[email protected]>; +Cc: Pavel Stehule <[email protected]>; Ron Johnson <[email protected]>; pgsql-general

On Sun, 15 Dec 2024 at 14:20, Tom Lane <[email protected]> wrote:

> Isaac Morland <[email protected]> writes:
> > On Sun, 15 Dec 2024 at 12:29, Tom Lane <[email protected]> wrote:
> >> What I'd suggest as an improvement that could be implemented
> >> immediately is to wrap the checks in a user-defined function
> >> like "is_system_schema(nspname name)".
>
> > Would it make sense to make the parameter be of type regnamespace?
>
> Meh ... you could, but what the function really needs is the name.
> Getting from regnamespace (which is an OID) to the name would incur
> an extra syscache lookup.  Admittedly, if it removes the need for
> the calling query to join to pg_namespace at all, you'd probably
> come out about even --- the net effect would be about like a
> hashjoin to pg_namespace, I think, since the syscache would act
> like the inner hashtable of a hashjoin.


Thanks for the critique. It occurs to me that this function is perhaps just
as much about “is this name a system-reserved name?” as “is this schema a
system schema?”. So putting in a name that doesn’t actually exist in the
database should be perfectly valid, which of course only works if it takes
a string. Generally speaking I am a big fan of the reg* data types but in
this specific case I think it’s not a clear win. I might still suggest
providing both versions using function overloading.


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Request for new column in pg_namespace
  2024-12-15 17:40 Re: Request for new column in pg_namespace Isaac Morland <[email protected]>
  2024-12-15 19:20 ` Re: Request for new column in pg_namespace Tom Lane <[email protected]>
@ 2024-12-16 00:16   ` Ron Johnson <[email protected]>
  1 sibling, 0 replies; 4+ messages in thread

From: Ron Johnson @ 2024-12-16 00:16 UTC (permalink / raw)
  To: pgsql-general

On Sun, Dec 15, 2024 at 2:20 PM Tom Lane <[email protected]> wrote:

> Isaac Morland <[email protected]> writes:
> > On Sun, 15 Dec 2024 at 12:29, Tom Lane <[email protected]> wrote:
> >> What I'd suggest as an improvement that could be implemented
> >> immediately is to wrap the checks in a user-defined function
> >> like "is_system_schema(nspname name)".
>
> > Would it make sense to make the parameter be of type regnamespace?
>
> Meh ... you could, but what the function really needs is the name.
> Getting from regnamespace (which is an OID) to the name would incur
> an extra syscache lookup.  Admittedly, if it removes the need for
> the calling query to join to pg_namespace at all, you'd probably
> come out about even --- the net effect would be about like a
> hashjoin to pg_namespace, I think, since the syscache would act
> like the inner hashtable of a hashjoin.
>

It'll simplify the SQL to pass it a pg_class.relnamespace  value, since
that's what's stored in pg_class.

select ...
from pg_class cl INNER JOIN ...
where not is_system_schema(cl.relnamespace)
  and ...;

Might it be slightly slower?  Sure... but pg_class and pg_namespace aren't
giant tables, and the queries won't run thousands of times per day.  Thus,
in this case, a little less efficiency for much cleaner code is an
acceptable trade-off TO ME.

Heck, given how often "pg_class cl INNER JOIN pg_namespace nsp ON
cl.relnamespace = nsp.oid" appears in my (and so much other code around the
Internet), I should probably create a view that joins the two tables, and
adds an is_system_schema column.

That would *really* simplify my code...

-- 
Death to <Redacted>, and butter sauce.
Don't boil me, I'm still alive.
<Redacted> lobster!


^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2024-12-16 00:16 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-12-15 17:40 Re: Request for new column in pg_namespace Isaac Morland <[email protected]>
2024-12-15 19:20 ` Tom Lane <[email protected]>
2024-12-15 20:05   ` Isaac Morland <[email protected]>
2024-12-16 00:16   ` Ron Johnson <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox