From: Chao Li <li.evan.chao@gmail.com>
To: jian he <jian.universality@gmail.com>
Cc: David Rowley <dgrowleyml@gmail.com>
Cc: amul sul <sulamul@gmail.com>
Cc: Peter Eisentraut <peter@eisentraut.org>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Subject: Re: bug, ALTER TABLE call ATPostAlterTypeCleanup twice for the same relation
Date: Mon, 3 Aug 2026 14:00:33 +0800
Message-ID: <D5AB9959-35FA-4DF0-B29F-FC9B34506B00@gmail.com> (raw)
In-Reply-To: <CACJufxFD-LGP1Ccj58d4WgGAoq-+N1fwQkA=b5u5PQf_65Vo9A@mail.gmail.com>
References: <CACJufxHZsgn3zM5g-x7YmtFGzNDnRwR07S+GYfiUs+tZ45MDDw@mail.gmail.com>
<CAApHDvp7NidshSiw0kqQMgtRupYw7=A5aCM0ubhxC7D0MzvTVg@mail.gmail.com>
<CACJufxG-tHh1ZtqAP7XTcvuJbKgsJupXBnA6BJGoVKP8pKCq_A@mail.gmail.com>
<CAEoWx2nEXYMm+UhXaPdBfG2yqMoRMHiujGMrye9mnP6_jP26cQ@mail.gmail.com>
<CACJufxE10Cfe6-JzPGArL01k0B_n8dacz+fvmUSp9Rcn2Wo+1g@mail.gmail.com>
<CACJufxH1gCqCXHr7CNZBOUqffrHAC9kPg5wcDKZe4MersbUEYg@mail.gmail.com>
<ACAE1349-334E-43C3-AAE6-FC249E3C237D@gmail.com>
<CACJufxFD-LGP1Ccj58d4WgGAoq-+N1fwQkA=b5u5PQf_65Vo9A@mail.gmail.com>
> On Aug 2, 2026, at 19:52, jian he <jian.universality@gmail.com> wrote:
>
> Hi.
>
> ATPostAlterTypeCleanup->performMultipleDeletions drops the
> objects referenced by changedConstraintOids, changedIndexOids, and similar
> fields of the AlteredTableInfo, it makes sense to set those pointers
> to NULL afterward.
> The attached patch implements this approach.
>
> Another reason why I prefer this approach:
> Imagine some other random ALTER TABLE command that also needs to
> rebuild whole-row dependent objects for the table,
> then ATPostAlterTypeCleanup would also need to be called for that
> AlterTablePass.
> Ideally, we should be able to call ATPostAlterTypeCleanup for any kind
> of AlterTablePass.
>
> The commit message is below:
> ---------------------------------
> ATPostAlterTypeCleanup() is called twice when a single ALTER TABLE contains both
> ALTER COLUMN SET DATA TYPE and ALTER COLUMN SET EXPRESSION.
> The first call drops the objects listed in tab->changedConstraintOids,
> tab->changedIndexOids and tab->changedStatisticsOids via
> performMultipleDeletions(), but left those lists untouched. The second call
> would drop the same OIDs again, failing with errors like
> "cache lookup failed".
>
> Fix by resetting the changed-object lists (and the replica identity and CLUSTER
> index markings, which would otherwise queue duplicate subcommands) at the end of
> ATPostAlterTypeCleanup(), so the second invocation only processes objects
> registered by the SET EXPRESSION pass.
> --------------------------------
>
>
>
> --
> jian
> https://www.enterprisedb.com/
> <v6-0001-Fix-ALTER-TABLE-when-ALTER-TYPE-and-SET-EXPRESSION-are-used-toget.patch>
Since my last round of review of this patch, I have done a lot of work on ALTER TABLE and thus gained a better understanding of the ALTER TABLE infra. I now agree that your approach (as in v6) is correct. The ALTER TYPE pass remembers and drops its dependencies, and SET EXPRESSION remembers and drops any additional ones.
A small comment on the commit message:
```
The first call drops the objects … but left those lists untouched.
```
I think “left” should be “leaves” to keep the tense consistent with “drops”.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
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: li.evan.chao@gmail.com, jian.universality@gmail.com, dgrowleyml@gmail.com, sulamul@gmail.com, peter@eisentraut.org
Subject: Re: bug, ALTER TABLE call ATPostAlterTypeCleanup twice for the same relation
In-Reply-To: <D5AB9959-35FA-4DF0-B29F-FC9B34506B00@gmail.com>
References: <CACJufxHZsgn3zM5g-x7YmtFGzNDnRwR07S+GYfiUs+tZ45MDDw@mail.gmail.com> <CAApHDvp7NidshSiw0kqQMgtRupYw7=A5aCM0ubhxC7D0MzvTVg@mail.gmail.com> <CACJufxG-tHh1ZtqAP7XTcvuJbKgsJupXBnA6BJGoVKP8pKCq_A@mail.gmail.com> <CAEoWx2nEXYMm+UhXaPdBfG2yqMoRMHiujGMrye9mnP6_jP26cQ@mail.gmail.com> <CACJufxE10Cfe6-JzPGArL01k0B_n8dacz+fvmUSp9Rcn2Wo+1g@mail.gmail.com> <CACJufxH1gCqCXHr7CNZBOUqffrHAC9kPg5wcDKZe4MersbUEYg@mail.gmail.com> <ACAE1349-334E-43C3-AAE6-FC249E3C237D@gmail.com> <CACJufxFD-LGP1Ccj58d4WgGAoq-+N1fwQkA=b5u5PQf_65Vo9A@mail.gmail.com> <D5AB9959-35FA-4DF0-B29F-FC9B34506B00@gmail.com>
* 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