From: | jian he <jian(dot)universality(at)gmail(dot)com> |
---|---|
To: | David Rowley <dgrowleyml(at)gmail(dot)com> |
Cc: | 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: | 2025-09-29 07:42:39 |
Message-ID: | CACJufxG-tHh1ZtqAP7XTcvuJbKgsJupXBnA6BJGoVKP8pKCq_A@mail.gmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Mon, Sep 29, 2025 at 5:36 AM David Rowley <dgrowleyml(at)gmail(dot)com> wrote:
>
> I do wonder what the exact reason was that AT_PASS_ALTER_TYPE and
> AT_PASS_SET_EXPRESSION are separate passes. I'd have expected that's
> maybe so that it's possible to alter the type of a column used within
> a generated column, but looking at the following error message makes
> me think I might not be correct in that thinking:
>
> create table test1 (a int, b int generated always as (a + 1) stored);
> alter table test1 alter column a set data type bigint;
> ERROR: cannot alter type of a column used by a generated column
> DETAIL: Column "a" is used by generated column "b".
>
> There's probably some good explanation for the separate pass, but I'm
> not sure of it for now. I'm including in the author and committer of
> the patch which added this code to see if we can figure this out.
>
I found the explanation link:
https://www.postgresql.org/message-id/CAAJ_b96TYsRrqm%2BveXCBb6CJuHJh0opmAvnhw8iMvhCMFKO-Tg%40mail.gmail.com
AT_PASS_SET_EXPRESSION should come after AT_PASS_ADD_COL,
otherwise cases like below would fail.
create table t1 (a int, b int generated always as (a + 1) stored);
alter table t1 add column c int, alter column b set expression as (a + c);
>AT_PASS_ALTER_TYPE and AT_PASS_ADD_COL cannot be together, the ALTER TYPE
> cannot see that column.
I guess this is the reason why we have two seperate PASS.
please also check the attached patch.
The idea is that if both generation expression and type are being changed,
only call ATPostAlterTypeCleanup while the current pass is
AT_PASS_SET_EXPRESSION.
Attachment | Content-Type | Size |
---|---|---|
v3-0001-avoid-call-ATPostAlterTypeCleanup-twice.patch | text/x-patch | 6.2 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | wenhui qiu | 2025-09-29 07:54:39 | Re: Fix locking issue with fixed-size stats template in injection_points |
Previous Message | Chao Li | 2025-09-29 07:29:25 | Re: Fix locking issue with fixed-size stats template in injection_points |