bug, ALTER TABLE call ATPostAlterTypeCleanup twice for the same relation - Mailing list pgsql-hackers

From jian he
Subject bug, ALTER TABLE call ATPostAlterTypeCleanup twice for the same relation
Date
Msg-id CACJufxHZsgn3zM5g-x7YmtFGzNDnRwR07S+GYfiUs+tZ45MDDw@mail.gmail.com
Whole thread Raw
Responses Re: bug, ALTER TABLE call ATPostAlterTypeCleanup twice for the same relation
Re: bug, ALTER TABLE call ATPostAlterTypeCleanup twice for the same relation
List pgsql-hackers
hi.

bug demo:
drop table if exists gtest25;
CREATE TABLE gtest25 (a0 int, a int, b int GENERATED ALWAYS AS (a * 2
+ a0) STORED);
alter table gtest25 add constraint cc check (b > 0);

alter table gtest25  alter column b set data type int8, ALTER COLUMN b
SET EXPRESSION AS (a * 3 + a0);
ERROR:  cache lookup failed for constraint 18432

ALTER COLUMN SET EXPRESSION only in 17, so it's a 17 and up related bug.
The reason is ATRewriteCatalogs->ATPostAlterTypeCleanup is called
twice for the same relation.
the second time you call it, the constraint cc is already dropped,
then the "cache lookup failed" error will happen.


While at it, maybe we can also polish the comment below in ATRewriteCatalogs.
            /*
             * After the ALTER TYPE or SET EXPRESSION pass, do cleanup work
             * (this is not done in ATExecAlterColumnType since it should be
             * done only once if multiple columns of a table are altered).
             */
but I didn't do it...

Attachment

pgsql-hackers by date:

Previous
From: Daniil Davydov
Date:
Subject: Re: Fix bug with accessing to temporary tables of other sessions
Next
From: David Rowley
Date:
Subject: Re: Fixing MSVC's inability to detect elog(ERROR) does not return