pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Prevent ALTER TYPE/DOMAIN/OPERATOR from changing extension membe
Date: Tue, 17 Aug 2021 18:29:36 +0000
Message-ID: <E1mG3qC-0001mu-Rj@gemulon.postgresql.org> (raw)

Prevent ALTER TYPE/DOMAIN/OPERATOR from changing extension membership.

If recordDependencyOnCurrentExtension is invoked on a pre-existing,
free-standing object during an extension update script, that object
will become owned by the extension.  In our current code this is
possible in three cases:

* Replacing a "shell" type or operator.
* CREATE OR REPLACE overwriting an existing object.
* ALTER TYPE SET, ALTER DOMAIN SET, and ALTER OPERATOR SET.

The first of these cases is intentional behavior, as noted by the
existing comments for GenerateTypeDependencies.  It seems like
appropriate behavior for CREATE OR REPLACE too; at least, the obvious
alternatives are not better.  However, the fact that it happens during
ALTER is an artifact of trying to share code (GenerateTypeDependencies
and makeOperatorDependencies) between the CREATE and ALTER cases.
Since an extension script would be unlikely to ALTER an object that
didn't already belong to the extension, this behavior is not very
troubling for the direct target object ... but ALTER TYPE SET will
recurse to dependent domains, and it is very uncool for those to
become owned by the extension if they were not already.

Let's fix this by redefining the ALTER cases to never change extension
membership, full stop.  We could minimize the behavioral change by
only changing the behavior when ALTER TYPE SET is recursing to a
domain, but that would complicate the code and it does not seem like
a better definition.

Per bug #17144 from Alex Kozhemyakin.  Back-patch to v13 where ALTER
TYPE SET was added.  (The other cases are older, but since they only
affect the directly-named object, there's not enough of a problem to
justify changing the behavior further back.)

Discussion: https://postgr.es/m/17144-e67d7a8f049de9af@postgresql.org

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/7b01246e1de94a436c64f1d396674b2dc44dab70

Modified Files
--------------
src/backend/catalog/pg_depend.c     |  7 +++++++
src/backend/catalog/pg_operator.c   | 15 +++++++++++----
src/backend/catalog/pg_type.c       | 24 ++++++++++++++++--------
src/backend/commands/operatorcmds.c |  2 +-
src/backend/commands/typecmds.c     |  2 ++
src/include/catalog/pg_operator.h   |  4 +++-
src/include/catalog/pg_type.h       |  1 +
7 files changed, 41 insertions(+), 14 deletions(-)



view thread (3+ messages)  latest in thread

Message-ID: <E1mG3qC-0001mu-Rj@gemulon.postgresql.org>
Permalink:  ../E1mG3qC-0001mu-Rj@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1mG3qC-0001mu-Rj@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Prevent ALTER TYPE/DOMAIN/OPERATOR from changing extension membe
  In-Reply-To: <E1mG3qC-0001mu-Rj@gemulon.postgresql.org>
  References: <E1mG3qC-0001mu-Rj@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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