Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tMyny-007i7F-4r for pgsql-general@arkaria.postgresql.org; Mon, 16 Dec 2024 00:17:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tMymv-000pb4-Vd for pgsql-general@arkaria.postgresql.org; Mon, 16 Dec 2024 00:16:43 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tMymv-000pat-Gn for pgsql-general@lists.postgresql.org; Mon, 16 Dec 2024 00:16:42 +0000 Received: from mail-oo1-xc35.google.com ([2607:f8b0:4864:20::c35]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tMymp-0033Hx-BJ for pgsql-general@postgresql.org; Mon, 16 Dec 2024 00:16:41 +0000 Received: by mail-oo1-xc35.google.com with SMTP id 006d021491bc7-5f340d6db09so508242eaf.1 for ; Sun, 15 Dec 2024 16:16:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734308193; x=1734912993; darn=postgresql.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=V22AhP0hNvngFOJGy31VsK4ZKA1BnF8HFxHn7HUYMb8=; b=MxQVnOZ+jDWWUvfoE3/nqr1i/I8Brg5k/36o++OCY1YLBazFiWeIVadeEBNMO6yE0i Ca4JxBrrQCLwAtdLpqLvavtfxWtYV6C8UXb872w3t0hj9Exvx7lCUYUo43oKAdv+DBIv ERm+j7SAiyktwwBh1bIII1JtHKEv1FvDfkNlgmS8vwntdY4hO0lByyWAm2yPFzT+k/Fe z+zaeQms89XVGYsoFiI3neflEuR+uM7RVQ1XjuhbuWJDICs3LHMxXo0c7xd8eD9PTmN2 rTOsAsX4KCTGMayXbs1+z7/oRs4x0CPvojxdb9/UmGvgBVuk9INJk/XPCzVdJI31dQUf Zy6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734308193; x=1734912993; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=V22AhP0hNvngFOJGy31VsK4ZKA1BnF8HFxHn7HUYMb8=; b=JwkFkNh2TQQhZTnr+L+aMBqPwSG48cXnSEbqz6W2UPWfEDp3x6ulhxypktNuUwWrCz L4S3k4iSBhBYjDwML2EU2lP3wa7y9tGZlS+6poVl7R/SIcXmGSQ4XBcRUnyU4JEfT2+V Se2Vf/ztnOxWk98+K7TRcoiE5mAB5DuuKkT6X8phTyilGWhL/1uuuQLpyBI2x/ir6c9e 6a6MjB/szuaaPtbu5YGY5XIUN9PinRgtGx2Vc1lgwYE2H3c05G+K/atiP284IncrGz1e BDRgtF1eWr6OXkWlva5P2xuT7W7LlWPXj15xBrSiixzpRH5WbP74iJnsNSfSbKCeyR/7 e1nQ== X-Gm-Message-State: AOJu0Yyj2PfbM9Tw/xnw4JJoP/3IFF3jVN7jWRjFrbzx2yzl75C8QzMF Qi9pqQxfe0c2fp6sUPImSm8Lo6+QmWMRcOeaMad60qv48xzd0VcxBgPPSI65B7s46tM7GkICaXw LEx6yt9hO0Np19k1dziGJCHt+lYSwjqQj X-Gm-Gg: ASbGncsdxizH5lip4YqX1oxne0VMUdhhkFMv3WE3P2czRhVS0dJvzPwgGBF0mpWgB9J idYZVTwWYIkdi2USrVHrmObzi73+KhuvLhDxCTOw= X-Google-Smtp-Source: AGHT+IHn1YsAkszdz1PAjeKfY/hYmnO19VtK+od2UPe4EuytztPGHoaSEDbdHsihkXFD6b4TymTUBXiwaLEkSLguO4U= X-Received: by 2002:a05:6870:5492:b0:29e:5c37:a1c0 with SMTP id 586e51a60fabf-2a3ac6be7f9mr5809850fac.21.1734308192758; Sun, 15 Dec 2024 16:16:32 -0800 (PST) MIME-Version: 1.0 References: <1627466.1734283766@sss.pgh.pa.us> <1753818.1734290423@sss.pgh.pa.us> In-Reply-To: <1753818.1734290423@sss.pgh.pa.us> From: Ron Johnson Date: Sun, 15 Dec 2024 19:16:21 -0500 Message-ID: Subject: Re: Request for new column in pg_namespace To: pgsql-general Content-Type: multipart/alternative; boundary="000000000000c2b37606295817cf" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000c2b37606295817cf Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, Dec 15, 2024 at 2:20=E2=80=AFPM Tom Lane wrote: > Isaac Morland writes: > > On Sun, 15 Dec 2024 at 12:29, Tom Lane 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 =3D nsp.oid" appears in my (and so much other code around t= he 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... --=20 Death to , and butter sauce. Don't boil me, I'm still alive. lobster! --000000000000c2b37606295817cf Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Sun, Dec 15, 2024 at 2:20=E2=80=AFPM T= om Lane <tgl@sss.pgh.pa.us> = wrote:
Isaac Morland <isaac.morland@gmail.com> wri= tes:
> On Sun, 15 Dec 2024 at 12:29, Tom Lane <tgl@sss.pgh.pa.us> 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.=C2=A0 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<= /font>.relnamespace=C2=A0 valu= e, since that's what's stored in pg_class.

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

Might it b= e slightly slower?=C2=A0 Sure... but=C2=A0pg_class and pg_namespace aren= 9;t giant tables, and the queries won't run thousands of times per day.= =C2=A0 Thus, in this case, a little less efficiency for much cleaner code i= s an acceptable trade-off TO ME.

Heck, given how o= ften "pg_class cl INNER JOIN pg_namespace nsp ON cl.relnamespace =3D n= sp.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=C2=A0i= s_system_schema column.

That would really= =C2=A0simplify my code...

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