Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nG5Zo-0001ca-3h for pgsql-hackers@arkaria.postgresql.org; Fri, 04 Feb 2022 20:53:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nG5ZG-0003c6-E6 for pgsql-hackers@arkaria.postgresql.org; Fri, 04 Feb 2022 20:52:30 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nG5ZG-0003bw-1i for pgsql-hackers@lists.postgresql.org; Fri, 04 Feb 2022 20:52:30 +0000 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nG5Z8-0000KK-BR for pgsql-hackers@lists.postgresql.org; Fri, 04 Feb 2022 20:52:29 +0000 Received: by mail-pj1-x1036.google.com with SMTP id z14-20020a17090ab10e00b001b6175d4040so14222911pjq.0 for ; Fri, 04 Feb 2022 12:52:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=gXPiZ229uKEQ57puyqURxGKzcX+BySsg08oPo9LBkFI=; b=ksISLsMW8qfE/LCX8pN3trnSq9gdtGUKacMteQ+6lwujxA9c0K4G9c72fyRz5JLO6p +Tk1n4Cho/PprE3XDhxYitFLh70a/o6DuNdXB0wj9aQhCkdkosPI6bySRRApPvJkVk2h lFl2/gWMFU5OK8RLzHnToiyRlRiDCqm03d9HZpn99wPLL9MSZWotMZXDDY1qrbWHn1Cl BTGEIhOv/O5B4m6TV6cPIoHwBTRJ9btNJZncOus1YAG6ZAKWmYijA1VbHTO9bR4XW93f BPp63TpopDVtLC0xmOOBZOktPqg6GZQu/oov0Y7UJjszpkHGzPyAP+MjSuwxcynu6kcy k7Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=gXPiZ229uKEQ57puyqURxGKzcX+BySsg08oPo9LBkFI=; b=ZIsEAcFkx/3xh9hFhJzo+iuj+rxp5ZCqXhsawL6yRCplGjEFY3mpqQ3EdQtMo+ds7j P6MqylyGcvjvyXw7V48mkWoUIY2CJQ2D8LQWvdwRk96lZQBWk/J9DZVv5PK8NqxMW8AU xAjIVMOXExr3U+MPpKh8gQlZV47w40yE5EXbbxoC+0Su9SNaqgiHFbM25cR1VhpkuvYe SiYdw/o7qgiqSMa8H6CIb9XXYbEOuq467+PXDCjmZf/uRaEsGNDIApak3PFAy9gq5LXo VxJPs+Za8ppquuU0paH628Eo9lfNqvDDNT7LLq+WpVO2FMRl5RFajTg44sAe0njzt199 dSUQ== X-Gm-Message-State: AOAM532h4ziUe/10F2QJOd0R2m62fEp9yoRlq4niFAgRxGgbG52Wdljl 7Pkk16O4IN8QjIdgvdkU8n+SRN81XkaYPMoFiI4= X-Google-Smtp-Source: ABdhPJzbYNSHh5Gv8V0mVS7iTMcOxLn6HLxKrjd4ENpmyrxSH1I1CR2bfN16SXjbou7EQ7N419eMbR7YwVy+p0pUPJU= X-Received: by 2002:a17:902:d2ca:: with SMTP id n10mr4193283plc.28.1644007939942; Fri, 04 Feb 2022 12:52:19 -0800 (PST) MIME-Version: 1.0 References: <202202040142.luk526wfnjjl@alvherre.pgsql> In-Reply-To: <202202040142.luk526wfnjjl@alvherre.pgsql> From: Swaha Miller Date: Fri, 4 Feb 2022 12:52:08 -0800 Message-ID: Subject: Re: support for CREATE MODULE To: Alvaro Herrera Cc: PostgreSQL Hackers Content-Type: multipart/alternative; boundary="00000000000044ae6b05d7376d8a" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000044ae6b05d7376d8a Content-Type: text/plain; charset="UTF-8" On Thu, Feb 3, 2022 at 5:42 PM Alvaro Herrera wrote: > On 2022-Feb-03, Pavel Stehule wrote: > > > The biggest problem is coexistence of Postgres's SEARCH_PATH object > > identification, and local and public scopes used in MODULEs or in > Oracle's > > packages. > > > > I can imagine MODULES as third level of database unit object grouping > with > > following functionality > > > > 1. It should support all database objects like schemas > > I proposed a way for modules to coexist with schemas that got no reply, > https://postgr.es/m/202106021908.ddmebx7qfdld@alvherre.pgsql > Yes, I arrived a little after that thread, and used that as my starting point. The POC patch Jim Mlodgenski had on that thread was similar to your proposed way - modules were rows in pg_namespace, with the addition of a new column in pg_namespace for the nspkind (module or schema.) Jim had asked about two options -- the above approach and an alternative one of having a pg_module system catalog and got some input https://www.postgresql.org/message-id/2897116.1622642280%40sss.pgh.pa.us Picking up from there, I am exploring the alternative approach. And what qualified names would look like and how they get interpreted unambiguously, when schemas and modules co-exist. (Also, being new to PostgreSQL, it has been a great learning exercise for me on some of the internals of PostgreSQL.) With modules being their own type of object stored in a pg_module system catalog, deconstructing a qualified path could always give precedence to schema over module. So when there is function f() in schema s and another function f() in module s in schema public, then s.f() would invoke the former. What are some other directions we might want to take this patch? I still think that that idea is valuable; it would let us create > "private" routines, for example, which are good for encapsulation. > But the way it interacts with schemas means we don't end up with a total > mess in the namespace resolution rules. I argued that modules would > only have functions, and maybe a few other useful object types, but not > *all* object types, because we don't need all object types to become > private. For example, I don't think I would like to have data types or > casts to be private, so they can only be in a schema and they cannot be > in a module. > > Of course, that idea of modules would also ease porting large DB-based > applications from other database systems. > Indeed. Looking at commercial databases Oracle and Microsoft SQLServer, they both have implemented module-like structures. Swaha Miller --00000000000044ae6b05d7376d8a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Thu, Feb 3, 2022 at 5:42 PM Alvaro Her= rera <alvherre@alvh.no-ip.org= > wrote:
On 2022-Feb-03, Pavel Stehule wrote:

> The biggest problem is coexistence of Postgres's SEARCH_PATH=C2=A0= object
> identification, and local and public scopes used in MODULEs or in Orac= le's
> packages.
>
> I can imagine MODULES as third level of database unit object grouping = with
> following functionality
>
> 1. It should support all database objects like schemas

I proposed a way for modules to coexist with schemas that got no reply,
https://postgr.es/m/202106021908.ddmebx7= qfdld@alvherre.pgsql

Yes, I arrived= a=C2=A0little after that thread, and used that as my starting point.
=

The POC patch Jim Mlodgenski had on that thread was sim= ilar to your proposed=C2=A0
way - modules were rows in pg_namespa= ce, with the addition of a new column in pg_namespace for the nspkind (modu= le or schema.)

Jim had asked about two options=C2= =A0 -- the above approach and an alternative one=C2=A0
of having = a pg_module system catalog and got some input

Picking up from there, I am explori= ng the alternative approach. And what qualified=C2=A0
names would= look like and how they get interpreted unambiguously, when=C2=A0
schemas and modules co-exist. (Also, being new to PostgreSQL, it has been = a=C2=A0
great learning exercise for me on some of the internals o= f PostgreSQL.)

With modules being their own type o= f object stored in a pg_module system=C2=A0
catalog, deconstructi= ng a qualified path could always give precedence to=C2=A0
schema = over module. So when there is function f() in schema s and another=C2=A0
function f() in module s in schema public, then s.f() would invoke = the former.

What are some other directions we migh= t=C2=A0want to=C2=A0take this patch?=C2=A0

I still think that that idea is valuable; it would let us create
"private" routines, for example, which are good for encapsulation= .
But the way it interacts with schemas means we don't end up with a tota= l
mess in the namespace resolution rules.=C2=A0 I argued that modules would only have functions, and maybe a few other useful object types, but not
*all* object types, because we don't need all object types to become private.=C2=A0 For example, I don't think I would like to have data typ= es or
casts to be private, so they can only be in a schema and they cannot be
in a module.

Of course, that idea of modules would also ease porting large DB-based
applications from other database systems.

Indeed. Looking at commercial databases Oracle and Microsoft SQLServer,= =C2=A0
they both have implemented module-like structures.

= Swaha Miller
--00000000000044ae6b05d7376d8a--