Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vB769-00AyIF-Q3 for pgsql-hackers@arkaria.postgresql.org; Tue, 21 Oct 2025 07:48:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1vB768-007bXT-Lg for pgsql-hackers@arkaria.postgresql.org; Tue, 21 Oct 2025 07:47:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vB768-007bXL-BG for pgsql-hackers@lists.postgresql.org; Tue, 21 Oct 2025 07:47:59 +0000 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vB764-003OMN-2o for pgsql-hackers@postgresql.org; Tue, 21 Oct 2025 07:47:59 +0000 Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-33bb090aa78so4554681a91.3 for ; Tue, 21 Oct 2025 00:47:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761032874; x=1761637674; darn=postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=4WTtZ53Zcb0B4BNa63hND1XWolpP6pc40tdtYYW9Pf8=; b=nFBWUlzhz3Fiq1g/F0D4pocAde6fNWd3hs9gVZKrlnYYu3Qb+M5YYjuqQgvAo2/HFU g2YFoncjZAyf5+P4YHknlUkf8PmbL066ZpkD4DVAaCtgJz3vMkRp8uSc5qx8AGLms+ZB eCqGk1f6l0XCP6j2/50koMZU69kFH9BIt+RL+T+2DeUmquu1Da38JmIU5vk5OTdFQwke W4G4U4a9xnQA9Ad+imneFEZ5MoLd+WtocACPdyHFPvdxgUlkg+QmBNEgioplgozeD2Bc 6mD96FfteIAUkcavo5ITOPx+Y3lrYDb3PCq8QMBt2uFv1Na4GXEkdRMFxsUpPi+gLiY+ Pc2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761032874; x=1761637674; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4WTtZ53Zcb0B4BNa63hND1XWolpP6pc40tdtYYW9Pf8=; b=TAmqenRNFRMk2QDwnS6UGr3dcqweRgoRchf+u4OPPA81PkAJOc6eBKoUD42qBfQV7M 0Zv9Ks/w2UygtD27EcYeDi/2au1f57Vbg8SgevcFn0iVwHqyS/tYIdNe6osTIA5kKgWb k2BuERb/pQ9URo7+l1va6fXeP195QgIaA+shldwENR6t9MiExjt6T8buBbNS3ccrdTJB A0jv8SPwJgZQLSEQsVaYxWdaHDP+HNOmdxctOvFn5qLCBahar93qmHgQS3MtDV47XDJB lOCE5kIKEyh8DO6AEFEvqTB8mKyCbhuDLX314et+tNU7GgIu8Tyv4s+Y/P4YvMkNWODH HaKA== X-Forwarded-Encrypted: i=1; AJvYcCWKp8A+zm1r4j/a7Hz7Cbd46hnz7c2H1+bvmyckieffnonhc0Fr2ME3Cl/XdoCQyI3WvrvF6FOS4nv7WR0q@postgresql.org X-Gm-Message-State: AOJu0Yw6BVhGXn8mbWswGQfovtWFUXWpynYfdNgDC9cCktDArKJvzp9/ 3qXNMiaIbemP1pp2hduCT1O4g+C2dWGFMpBXclvVgVaeq39vYOhxVQO5 X-Gm-Gg: ASbGnctr1zvsEV8HZRaPLwrVvV2oMm1o6ho7FKuYcq9lYJ0PvN0p8nYMq8moks4IB2a Aze6NQ5c8CATCkbwN+SfN0578/xU2RxGdG+/QyLMo00H6bDVOBeHdtkS5JBOamOF/zttU3U+I6C 8KFxdt9HktQO0WyEVyhkyL+1vW0LrFvHQRJ8vyJ9fxujQEtdGeDb6irjL/CYYWfjZQ0F5uLB3Hu pO4g8rOEFmhL9pN0W30XhT7i76LOkYCK5obY2jKPm4gz95IVBOFevB7AKTQ9ZXBPvPR4I0HjARd Y1aXY1bAsDpZQepB0RJvs/wu03VNxF6ctzWex5Li0EI9Q9LhrFPpsbV0QaWUh+mZG5Eao1VFBFI ar257qvZCJcCc597aTdGzn+mziRzYKWbwIkiUqrmSuX0jpEPtwRRzZuujxjCD/B8YLKi+fIHQeI l8fT6W9V1rFFY= X-Google-Smtp-Source: AGHT+IFVUWmUnJpy/pKjTTpN9ism6UIXjmshE3q8wteyTPQQBaMn+TG/GzkT9n2XU3ATtrZ/cKivBg== X-Received: by 2002:a17:90b:3811:b0:313:1c7b:fc62 with SMTP id 98e67ed59e1d1-33bcf8fa6cemr19761158a91.22.1761032874438; Tue, 21 Oct 2025 00:47:54 -0700 (PDT) Received: from smtpclient.apple ([170.178.170.211]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-33d5de8091fsm10306461a91.19.2025.10.21.00.47.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Oct 2025 00:47:53 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: bug, ALTER TABLE call ATPostAlterTypeCleanup twice for the same relation From: Chao Li In-Reply-To: Date: Tue, 21 Oct 2025 15:47:18 +0800 Cc: David Rowley , amul sul , Peter Eisentraut , PostgreSQL-development Content-Transfer-Encoding: quoted-printable Message-Id: References: To: jian he X-Mailer: Apple Mail (2.3826.700.81) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Oct 13, 2025, at 16:08, jian he = wrote: >=20 > On Wed, Oct 1, 2025 at 11:04=E2=80=AFAM jian he = wrote: >>=20 >> we can simply change from >>=20 >> if (pass =3D=3D AT_PASS_ALTER_TYPE || pass =3D=3D = AT_PASS_SET_EXPRESSION) >> ATPostAlterTypeCleanup(wqueue, tab, lockmode); >>=20 >> to >> if (pass =3D=3D AT_PASS_SET_EXPRESSION) >> ATPostAlterTypeCleanup(wqueue, tab, lockmode); >> else if (pass =3D=3D AT_PASS_ALTER_TYPE && >> tab->subcmds[AT_PASS_SET_EXPRESSION] =3D=3D NIL) >> ATPostAlterTypeCleanup(wqueue, tab, lockmode); >=20 > That will not work if AT_PASS_ALTER_TYPE triggers the creation of a = new > AT_PASS_SET_EXPRESSION entry. > For example, consider: > CREATE TABLE gtest25 (a int, b int GENERATED ALWAYS AS (a * 2) = STORED); >=20 > If we alter the type of column "a", the column b=E2=80=99s generation > expression would need > to be rebuilt (which is currently not supported). In that case, the = current > logic would not be able to handle it. >=20 > I think the correct fix is within ATPostAlterTypeCleanup. > at the end of ATPostAlterTypeCleanup, we already delete these changed > objects via > ``performMultipleDeletions(objects, DROP_RESTRICT, = PERFORM_DELETION_INTERNAL);`` >=20 > we can just list_free these (the below) objects too: > tab->changedConstraintOids > tab->changedConstraintDefs > tab->changedIndexOids > tab->changedIndexDefs > tab->changedStatisticsOids > tab->changedStatisticsDefs >=20 > since this information would become stale if those objects have > already been dropped. > Now I fully understand what your concern is, so that I understand your = solution also. So, I take back my previous reply and re-reply. Your concern comes from an assumed solution to support altering a = column=E2=80=99s type when it has a dependent generated column. Your = assumed solution is like: 1. SQL: ALTER TABLE gtest25 ALTER COLUMN a TYPE bigint; # generated = column depends on a 2. Before alter column a=E2=80=99s type, b=E2=80=99s expression is = remembered 3. After alter column a=E2=80=99s type, ATPostAlterTypeClean() is called = as there is no SET EXPRESSION. ATPostAlterTypeClean() will add a SET = EXPRESSION subcmd to rebuild b 4. In SET_EXPRESSION PASS, b is recreated 5. ATPostAlterTypeClean() is called again, if we don=E2=80=99t cleanup = those tab->changedXXX lists, then remembered objects will be rebuilt = again, which may lead to errors. What=E2=80=99s why your solution of = cleaning up table->changedXXX works. In my opinion, in step 2, we don=E2=80=99t have follow the same = mechanism to remember generated expressions as constraints. We can = directly check if b has SET EXPRESSION cmd, if yes, we don=E2=80=99t = need to do anything; otherwise, we get the b=E2=80=99s expression and = inject a SET EXPRESSION subcmd for b. In this case, your worried problem = will not exist. With this approach, ATPostAlterTypeClean() will always = be called only once, so that execution path is simpler. But anyway, we haven=E2=80=99t decided to support that yet. So for the = current bug, your solution of: >> if (pass =3D=3D AT_PASS_SET_EXPRESSION) >> ATPostAlterTypeCleanup(wqueue, tab, lockmode); >> else if (pass =3D=3D AT_PASS_ALTER_TYPE && >> tab->subcmds[AT_PASS_SET_EXPRESSION] =3D=3D NIL) >> ATPostAlterTypeCleanup(wqueue, tab, lockmode); should work. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/