Re: bug, ALTER TABLE call ATPostAlterTypeCleanup twice for the same relation

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Cc: David Rowley <dgrowleyml(at)gmail(dot)com>, amul sul <sulamul(at)gmail(dot)com>, Peter Eisentraut <peter(at)eisentraut(dot)org>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: bug, ALTER TABLE call ATPostAlterTypeCleanup twice for the same relation
Date: 2026-08-02 11:52:40
Message-ID: CACJufxFD-LGP1Ccj58d4WgGAoq-+N1fwQkA=b5u5PQf_65Vo9A@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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/

Attachment Content-Type Size
v6-0001-Fix-ALTER-TABLE-when-ALTER-TYPE-and-SET-EXPRESSION-are-used-toget.patch text/x-patch 8.3 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Previous Message Tatsuya Kawata 2026-08-02 11:08:16 Re: a large LIMIT makes some sorts slower