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 1nLEM6-0006Fh-UW for pgsql-general@arkaria.postgresql.org; Sat, 19 Feb 2022 01:16:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nLEM4-0005Uu-AO for pgsql-general@arkaria.postgresql.org; Sat, 19 Feb 2022 01:16:08 +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 1nLEM3-0005Uk-Ss for pgsql-general@lists.postgresql.org; Sat, 19 Feb 2022 01:16:07 +0000 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nLELz-0003nk-5l for pgsql-general@lists.postgresql.org; Sat, 19 Feb 2022 01:16:07 +0000 Received: by mail-pj1-x102c.google.com with SMTP id qe15so9995501pjb.3 for ; Fri, 18 Feb 2022 17:16:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yugabyte.com; s=google; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=Zczc+3Zd1cdUatlsbBHWknODWv8bXeM/l0r2cGDEiz8=; b=Wbtjh5E9qX9xv69quAoMeDWv+C3U/sl07T10HylpLMbWN9mDBHz9WM46GKJ3ibqmaz 4lOhepF/EanfjLjCtzTIfxcXp6CxecPgD2MEV7myPXzHfXCaEwZAI0W2JmwK84E99QTn /Wq245dYvM+1pN7T9TALSvuDIzWcUox4kM2v4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=Zczc+3Zd1cdUatlsbBHWknODWv8bXeM/l0r2cGDEiz8=; b=nzly8f2hX0BPF2v4blesWUEQgM9aMXGJMifMqz6yZSPBDRwzUN49VpJ9uRyDOUOTRl xoB0h8QW4KEnzHhT2mykNNLbIBiWtYvSFA0vUSKIdHH9WdXPIz364YmiUjC6MV8vYVE+ LLN4T/g5e0aY2scHCGEKkUDarVK4em/ww1TXj8IXo11hrXO5On9hq1t0iw3WfhKwf/L7 he6BdfuvTEAhM3Wi0Q/c3xTJSPPFof/yuXwxFrFdbbH9JG919FQsYev2kTkNWhRXoJ5o jURaHqCVvcMTl0yTKQjo+VWrLzbmN3Ng5udZ7iSQZsXTyZUDnrH9Q2Uir8scA8dbnzWW 7J9Q== X-Gm-Message-State: AOAM530ArYEI6ifP5QUf3yfNXGYV7MRc1yXdKTw04t7ZtU23hU7zjGBx IJmOx/ZDKtux+V6nPRIlkeHRjBh83HG5Ig== X-Google-Smtp-Source: ABdhPJzthmPsqhqPAQviGyzzyMEAqvU7o3itQAcLIcy7VKXQTvtzVbW/RuhYpOwyeQJpt5pO1F7MBw== X-Received: by 2002:a17:90a:e2c5:b0:1b8:ee4e:6b44 with SMTP id fr5-20020a17090ae2c500b001b8ee4e6b44mr14944356pjb.61.1645233360696; Fri, 18 Feb 2022 17:16:00 -0800 (PST) Received: from smtpclient.apple ([2601:646:101:7fda:f503:86f6:13d6:9c2c]) by smtp.gmail.com with ESMTPSA id q13sm4409287pfj.44.2022.02.18.17.15.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Feb 2022 17:16:00 -0800 (PST) From: Bryn Llewellyn Message-Id: <269BD3F1-B652-40E7-BC12-84BAF8955F6F@yugabyte.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_CCA3E956-14F9-4BA9-A01E-4EE543D2D7C7" Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Subject: Re: alter function/procedure depends on extension Date: Fri, 18 Feb 2022 17:15:58 -0800 In-Reply-To: Cc: Adrian Klaver , Alvaro Herrera , pgsql-general list To: "David G. Johnston" , Tom Lane PostgreSQL References: <7C2D01B4-AD32-48DB-B5FA-6FFBC312ECB2@yugabyte.com> <4c6b69e2-52c6-359d-3ed9-04842f631ffe@aklaver.com> <3781667.1645147045@sss.pgh.pa.us> <3889546.1645156447@sss.pgh.pa.us> X-Mailer: Apple Mail (2.3654.120.0.1.13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_CCA3E956-14F9-4BA9-A01E-4EE543D2D7C7 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > david.g.johnston@gmail.com wrote: >=20 > It's not a member though; there's a different syntax for that (ALTER = EXTENSION name ADD member_object). The differences are a bit subtle, = but for example making the function an extension member would change how = pg_dump treats it. I read, and re-read, the six replies from Tom and David that came in = yesterday (17-Feb) after my most recent turn in this thread. Here=E2=80=99= s what I=E2=80=99ve concluded: (1) Tom has ruled that there are no implementation bugs in this space. = This means that all the functionality that the tests that I have done = (and presumably could do) reflect the intended behavior. (2) The reasons for deciding on at least some of this behavior are lost = in the mists of time. But anyway, no implementation changes will be = made. (3) I, for one, found it very hard to build an overall, predictive, = mental model from the documentation. But, then, you=E2=80=99ve seen = (somewhat to my embarrassment) that I often have such difficulties. = I=E2=80=99m grateful therefore, especially in these work-from-home days, = for the answers that my questions to this list have received. (4) The clue to the whole thing is the semantics of the LoV for = "pg_depend. deptype" (see below) =E2=80=94 but you all kept this a = secret from me! =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 = =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 = =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 = =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 = =E2=80=94 =E2=80=94=20 Here=E2=80=99s some detailed observations and responses to what Tom and = David wrote: > David: =C2=AB An extension neither depends on nor is dependent upon = its members. =C2=BB This must be a typo: "depends on" and "is dependent upon" mean the same. = I=E2=80=99m guessing that this was meant: =C2=AB An extension neither = depends on nor is *depended* upon by its members. =C2=BB If so, then = it=E2=80=99s wrong. Yes: an extension doesn=E2=80=99t depend on its = members. This query (which runs without error) shows that an extension = depends upon only the schema nominated by "create extension=E2=80=A6 = with schema=E2=80=A6". select nspname from pg_namespace where oid =3D ( select refobjid from pg_catalog.pg_depend where objid =3D ( select oid from pg_catalog.pg_extension where extname::text =3D $1)); But no: the objects do depend upon the extension that creates them, as = this query shows: prepare dependents_on_extension(text) as select p.proname::text as dependent_name, 'subprogram'::text as dependent_type, e.extname::text as parent_name, 'extension'::text as parent_type, d.deptype::text as dependecy_type from pg_catalog.pg_proc p inner join pg_catalog.pg_depend d on p.oid =3D d.objid inner join pg_catalog.pg_extension e on d.refobjid =3D e.oid where e.extname::text =3D $1; I tried it for the "cube" extension and it listed out the same function = names that "\df the_schema.*" lists (where "the_schema" is the provided = argument for the "with schema" clause of "create extension". Moreover, it showed that the "dependency_type" is 'e' for the objects = that creating the extension brings. And the section "52.18. pg_depend" = says this about that value: =C2=AB DEPENDENCY_EXTENSION (e) =E2=80=94 The dependent object is a member of = the extension that is the referenced object (see pg_extension). The = dependent object can be dropped only via DROP EXTENSION on the = referenced object. Functionally this dependency type acts the same as an = INTERNAL dependency, but it's kept separate for clarity and to simplify = pg_dump. =C2=BB and it says this about "internal": =C2=AB DEPENDENCY_INTERNAL (i) =E2=80=94 The dependent object was created as = part of creation of the referenced object, and is really just a part of = its internal implementation. A direct DROP of the dependent object will = be disallowed outright (we'll tell the user to issue a DROP against the = referenced object, instead). A DROP of the referenced object will result = in automatically dropping the dependent object whether CASCADE is = specified or not=E2=80=A6 =C2=BB Seems to me that the account of the "create extension" DDL would benefit = from words to this effect and an x-ref to the account of "pg_depend" In my tests, I installed the "cube" extension in schema "cube". Then I = did this: alter function cube.cube_cmp(cube.cube, cube.cube)depends on extension = cube; And then I repeated the query that I showed above. Now the results = included these two rows: dependent_name | dependent_type | parent_name | parent_type | = dependecy_type=20 = --------------------+----------------+-------------+-------------+--------= -------- cube_cmp | subprogram | cube | extension | e cube_cmp | subprogram | cube | extension | x Here's what the doc says about the new result: =C2=AB DEPENDENCY_AUTO_EXTENSION (x) =E2=80=94 The dependent object is not a = member of the extension that is the referenced object (and so it should = not be ignored by pg_dump), but it cannot function without the extension = and should be auto-dropped if the extension is. The dependent object may = be dropped on its own as well. Functionally this dependency type acts = the same as an AUTO dependency, but it's kept separate for clarity and = to simplify pg_dump. =C2=BB This is the clue to everything that's been confusing me. But nobody = mentioned "pg_depend. deptype"! After reading and re-reading the accounts for all values of "pg_depend. = deptype" I saw, eventually, that this means that "drop extension" will = always silently remove all of its dependents of type 'x' whatever you = might say about "restrict" (or "cascade"). B.t.w., a query like I show above but for the "parent_type" = (user-defined) type shows that a function with an argument whose data = type is such a user-defined) type depends on that type with deptype =3D = 'n'. =C2=AB DEPENDENCY_NORMAL (n) A normal relationship between separately-created objects. The dependent = object can be dropped without affecting the referenced object. The = referenced object can only be dropped by specifying CASCADE, in which = case the dependent object is dropped, too. Example: a table column has a = normal dependency on its data type. =C2=BB A slow learner like me would always appreciate a commentary, with = self-contained runnable examples along the lines of what I've sketched = here, to accompany every maximally terse definitional account. But I = appreciate that the PG Doc doesn't aim to do this. --Apple-Mail=_CCA3E956-14F9-4BA9-A01E-4EE543D2D7C7 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
david.g.johnston@gmail.com wrote:

It's not a member though; there's a different syntax for = that (ALTER EXTENSION name ADD member_object). =  The differences are a bit subtle, but for example making = the function an extension member would change how pg_dump treats = it.

I read, and = re-read, the six replies from Tom and David that came in yesterday = (17-Feb) after my most recent turn in this thread. Here=E2=80=99s = what I=E2=80=99ve concluded:

(1) Tom has = ruled that there are no implementation bugs in this space. This means = that all the functionality that the tests that I have done (and = presumably could do) reflect the intended behavior.

(2) The reasons for deciding on at least some of this = behavior are lost in the mists of time. But anyway, no implementation = changes will be made.

(3) I, for one, = found it very hard to build an overall, predictive, mental model from = the documentation. But, then, you=E2=80=99ve seen (somewhat to my = embarrassment) that I often have such difficulties. I=E2=80=99m grateful = therefore, especially in these work-from-home days, for the answers that = my questions to this list have received.

(4) The clue to the whole thing is the = semantics of the LoV for "pg_depend. deptype" (see below) =E2=80=94 but = you all kept this a secret from me!
=E2=80=94 =E2=80=94 = =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 = =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 = =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 = =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 =E2=80=94 = ;

Here=E2=80=99s some detailed observations = and responses to what Tom and David wrote:

David: =C2=AB An extension neither depends on nor is = dependent upon its members. =C2=BB

This must be a typo: "depends on" and "is dependent upon" = mean the same. I=E2=80=99m guessing that this was meant: =C2=AB An = extension neither depends on nor is *depended* upon by its members. = =C2=BB If so, then it=E2=80=99s wrong. Yes: an extension doesn=E2=80=99t = depend on its members. This query (which runs without error) shows = that an extension depends upon only the schema nominated by = "create extension=E2=80=A6 with schema=E2=80=A6".

select nspname from
pg_namespace
where oid =3D (
  select refobjid
  from pg_catalog.pg_depend
  where objid =3D (
  =   select oid
    from = pg_catalog.pg_extension
    where = extname::text =3D $1));

But= no: the objects do depend upon the extension that creates them, as this = query shows:

prepare = dependents_on_extension(text) as
select
  p.proname::text    as = dependent_name,
  'subprogram'::text as = dependent_type,
  e.extname::text  =   as parent_name,
  'extension'::text  as parent_type,
  d.deptype::text    as = dependecy_type
from
  pg_catalog.pg_proc p
  inner join
  pg_catalog.pg_depend d
  on= p.oid =3D d.objid
  inner join
  pg_catalog.pg_extension e
  on d.refobjid =3D e.oid
where e.extname::text =3D $1;

I = tried it for the "cube" extension and it listed out the same function = names that "\df the_schema.*" lists (where "the_schema" is the provided = argument for the "with schema" clause of "create extension".

Moreover, it showed that = the "dependency_type" is 'e' for the objects that creating the extension = brings. And the section "52.18. pg_depend" says this about that = value:

=C2=AB
DEPENDENCY_EXTENSION (e) =E2=80=94 = The dependent object is a member of the extension that is the referenced = object (see pg_extension). The dependent object can be dropped only = via DROP EXTENSION on the referenced object. Functionally = this dependency type acts the same as an INTERNAL dependency, but = it's kept separate for clarity and to simplify pg_dump.
=C2=BB

and = it says this about "internal":

=C2=AB
DEPENDENCY_INTERNAL (i) =E2=80=94 The dependent object was = created as part of creation of the referenced object, and is = really just a part of its internal implementation. A direct DROP of = the dependent object will be disallowed outright (we'll tell the user = to issue a DROP against the referenced object, instead). A DROP of = the referenced object will result in automatically dropping = the dependent object whether CASCADE is specified or = not=E2=80=A6
=C2=BB

Seems to me that the = account of the "create extension" DDL would benefit from words to this = effect and an x-ref to the account of "pg_depend"
In my tests, I installed the "cube" = extension in schema "cube". Then I did this:

alter function cube.cube_cmp(cube.cube, = cube.cube)depends on extension cube;

And then I repeated the query that I = showed above. Now the results included these two rows:

   dependent_name   | = dependent_type | parent_name | parent_type | dependecy_type 
--------------------+----------------+-------------+-----------= --+----------------
 cube_cmp     =       | subprogram     | = cube        | extension   | e
 cube_cmp           | = subprogram     | cube      =   | extension   | x

Here's = what the doc says about the new result:

=C2=AB
DEPENDENCY_AUTO_EXTENSION (x) =E2=80=94 The dependent object = is not a member of the extension that is the referenced object (and = so it should not be ignored by pg_dump), but it cannot function without = the extension and should be auto-dropped if the extension is. The = dependent object may be dropped on its own as well. Functionally this = dependency type acts the same as an AUTO dependency, but it's kept = separate for clarity and to simplify pg_dump.
=C2=BB

This is the clue to everything that's = been confusing me. But nobody mentioned "pg_depend. deptype"!

After reading and = re-reading the accounts for all values of "pg_depend. deptype" I saw, = eventually, that this means that "drop extension" will always silently = remove all of its dependents of type 'x' whatever you might say about = "restrict" (or "cascade").

B.t.w., a query like I show above but for the "parent_type" = (user-defined) type shows that a function with an argument whose data = type is such a user-defined) type depends on that type with deptype = =3D 'n'.

=C2=AB
DEPENDENCY_NORMAL (n)
A normal = relationship between separately-created objects. The dependent object = can be dropped without affecting the referenced object. The = referenced object can only be dropped by specifying CASCADE, in = which case the dependent object is dropped, too. Example: a table = column has a normal dependency on its data type.
=C2=BB

A slow learner like me would always = appreciate a commentary, with self-contained runnable examples along the = lines of what I've sketched here, to accompany every maximally terse = definitional account. But I appreciate that the PG Doc doesn't aim to do = this.

= --Apple-Mail=_CCA3E956-14F9-4BA9-A01E-4EE543D2D7C7--