From: Tom Lane <tgl@sss.pgh.pa.us>
To: Robert Haas <robertmhaas@gmail.com>
Cc: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: Rearranging ALTER TABLE to avoid multi-operations bugs
Date: Tue, 29 Oct 2019 14:18:05 -0400
Message-ID: <30897.1572373085@sss.pgh.pa.us> (raw)
In-Reply-To: <41500.1559166722@sss.pgh.pa.us>
References: <10365.1558909428@sss.pgh.pa.us>
<CA+Tgmoa3FzZvWriJmqquvAbf8GxrC9YM9umBb18j5M69iuq9bg@mail.gmail.com>
<41500.1559166722@sss.pgh.pa.us>
[ starting to think about this issue again ]
I wrote:
> Robert Haas <robertmhaas@gmail.com> writes:
>> I mean, in an ideal world, I think we'd never call back out to
>> ProcessUtility() from within AlterTable(). That seems like a pretty
>> clear layering violation. I assume the reason we've never tried to do
>> better is a lack of round tuits and/or sufficient motivation.
> ...
> Also, recursive ProcessUtility cases exist independently of this issue,
> in particular in CreateSchemaCommand. My worry about my patch upthread
> is not really that it introduces another one, but that it doesn't do
> anything towards providing a uniform framework/notation for all these
> cases.
Actually ... looking closer at this, the cases I'm concerned about
*already* do recursive ProcessUtility calls. Look at utility.c around
line 1137. The case of interest here is when transformAlterTableStmt
returns any subcommands that are not AlterTableStmts. As the code
stands, ProcessUtility merrily recurses to itself to handle them.
What I was proposing to do was have the recursion happen from inside
AlterTable(); maybe that's less clean, but surely not by much.
The thing I think you are actually worried about is the interaction
with event triggers, which is already a pretty horrid mess in this
code today. I don't really follow the comment here about
"ordering of queued commands". It looks like that comment dates to
Alvaro's commit b488c580a ... can either of you elucidate that?
Anyway, with the benefit of more time to let this thing percolate
in my hindbrain, I am thinking that the fundamental error we've made
is to do transformAlterTableStmt in advance of execution *at all*.
The idea I now have is to scrap that, and instead apply the
parse_utilcmd.c transformations individually to each AlterTable
subcommand when it reaches execution in "phase 2" of AlterTable().
In that way, the bugs associated with interference between different
AlterTable subcommands touching the same column are removed because
the column's catalog state is up-to-date when we do the parse
transformations. We can probably also get rid of the problems with
IF NOT EXISTS, because that check would be made in advance of applying
parse transformations for a particular subcommand, and thus its
side-effects would not happen when IF NOT EXISTS fires. I've not
worked this out in any detail, and there might still be a few ALTER
bugs this framework doesn't fix --- but I think my original idea
of "flags" controlling AlterTable execution probably isn't needed
if we go this way.
Now, if we move things around like that, it will have some effects
on what event triggers see --- certainly the order of operations
at least. But do we feel a need to retain the same sort of
"encapsulation" that is currently happening due to the aforesaid
logic in utility.c? I don't fully understand what that's for.
regards, tom lane
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-hackers@postgresql.org
Cc: tgl@sss.pgh.pa.us, robertmhaas@gmail.com, alvherre@2ndquadrant.com
Subject: Re: Rearranging ALTER TABLE to avoid multi-operations bugs
In-Reply-To: <30897.1572373085@sss.pgh.pa.us>
References: <10365.1558909428@sss.pgh.pa.us> <CA+Tgmoa3FzZvWriJmqquvAbf8GxrC9YM9umBb18j5M69iuq9bg@mail.gmail.com> <41500.1559166722@sss.pgh.pa.us> <30897.1572373085@sss.pgh.pa.us>
* 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