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.96) (envelope-from ) id 1x5rf3-000K2B-2H for pgsql-hackers@arkaria.postgresql.org; Sun, 13 Sep 2026 21:22:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x5re2-00AUr3-2L for pgsql-hackers@arkaria.postgresql.org; Sun, 13 Sep 2026 21:21:50 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x5re2-00AUqu-12 for pgsql-hackers@lists.postgresql.org; Sun, 13 Sep 2026 21:21:50 +0000 Received: from mail-oi1-x235.google.com ([2607:f8b0:4864:20::235]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1x5rdz-00000000ESJ-2RTE for pgsql-hackers@postgresql.org; Sun, 13 Sep 2026 21:21:48 +0000 Received: by mail-oi1-x235.google.com with SMTP id 5614622812f47-495c49f8eccso2975954b6e.3 for ; Sun, 13 Sep 2026 14:21:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789334506; x=1789939306; darn=postgresql.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=WOXmgOeEQzEhMs3cCNmBtkoAb5DPHP7COaTlda26OeU=; b=PZNmkxvQomFVcbY5KRQwQO8LwAH5CUlASVB/gxt+STCKO4vptngWqoKltsSOJs1Xv9 i22iTTxWZaNCsXqwFY8MimH1CWNTWvnFUF6gibrBbITR4vg4KPOOwkmGZUOFXbNzAXUr Y0TiwxDAjCVGf39dniAzvX1dm6gakeGX/t6zwZYFMag1nphggBD15iNJt2Jx8CRZlQGJ AKfO3WlTGPhzIaE++ugvdb+7OYNCuY8fudlgTRjZrPrf4mBkKms5zcF5BPAPDmlqVwC4 NN/wuJxhgZMZgIq7aYPwdvkViWvOv7Rizf2YUbi7mU6pEdkidGfz9vzCXCCXOrb4M9e5 5oOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789334506; x=1789939306; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=WOXmgOeEQzEhMs3cCNmBtkoAb5DPHP7COaTlda26OeU=; b=KnKFppk+R/17R3iZaNjlmkJrLQwcHMCwmFziC0/WXoBJBz1HR6p1nbPji56xk7LMnK xpS8e0ISueHVo0UUQFoj0wPtWVaZ32w+MXB0cncWBrANo0tXVKZK1KgSE/kp/LnLYlu4 xWKfmfuZm9gSJozWzmi9007fYwxJLKX0pyvNpg85xOHB8yhcJiIus2ZXui0uvS/AuHEC msXXdL0VJe66CRq9dd0nwD44R+vLTR90vuyobleQFwp9boC6y04PcbgU21mhHrC50nXD dBRlbntgRGWQ5xtnGhlbsxXMJqSM0iK7EU54NzjsMweSAaSGayW2bS4rzOB0WYju0F5p 882g== X-Forwarded-Encrypted: i=1; AKwUvByK71IDMZAv7WlS9TegcyD038r6ZEAe98v0OF56rm8qJ508i8M3uAbh42afXURzMeh1Ault6tEz/CMGMG5/@postgresql.org X-Gm-Message-State: AFuF++lR7b3WgQaUKJa8S61f8nnDRy+fi7RkW0dLsZgV19XbtYwP6Cmq 5Bb3mgzBVcDciN2cmFV50D1+wDPYUHF3UlVRC62diNyCXnHjzpjLUenW X-Gm-Gg: AYBFou0V5FO3YsaZZFf9M9F4JYXTI1n7532GUFwKN9u+9H4kbNvuLbcX0gM+eWOjjk1 LKdOszHQSSuHsP3zLTdJAUhdW20l90yzPiwWUquZdz+o8ZT9EmWJVdKzfnFgWuZg0O7gwT72pMX 3/IgHgW8oDxzJbeFIWY3BOHk6IK7hENTCIClhal+mzvKqqU2dUHcqCzN9E8MRDc19EQ4d9fSZuG nOVbjmb0P15rSH656mWcj/Sx575bSRXp3OJI6VjyUfvhsBuJHVsGd/w4ZrcT1ZUn9Uk1Cv66atg aboJGCzcAn/19TKAPtldTG0sqHTUw6EOYCq+4h7PvWGYniZIwvS2ND86xFnZJG8qCLd6xtxAaBA KEdokY3pCTwGx/QNCvdVhiTwG9dsPqQ/pcvN2KLbr5PvirUe+QFzssIyKwH47IQSuUmlhUKWtlC ihVt12y7juIBM1GSy6n1ieAvtNTdU8iGnO1OqbtO93PNEpLba6GySf3t8p3RNtTf6jjl+DBpqsI s1hX+WVgEwp5w1xjj2dVUVuiSKLKrPyyu+Xe825AhI9NQ5yO6Tk4EQY1y7NiSzomzNIS2PwoYPE 7xMGaHcT X-Received: by 2002:a05:6820:813:b0:6ba:3635:800b with SMTP id 006d021491bc7-6c0bd19ad9amr8545056eaf.68.1789334506260; Sun, 13 Sep 2026 14:21:46 -0700 (PDT) Received: from ?IPV6:2603:8082:2b40:1f:ad6f:2150:1283:4f79? ([2603:8082:2b40:1f:ad6f:2150:1283:4f79]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-6c0927adc48sm9717647eaf.0.2026.09.13.14.21.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 13 Sep 2026 14:21:44 -0700 (PDT) Message-ID: <9e6e5257-3ea4-4834-a1cc-b8bf2fb76d5f@gmail.com> Date: Sun, 13 Sep 2026 16:21:11 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: bug, ALTER TABLE call ATPostAlterTypeCleanup twice for the same relation To: Chao Li , jian he Cc: David Rowley , amul sul , Peter Eisentraut , PostgreSQL-development References: Content-Language: en-US From: Bryan Green In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 8/3/2026 1:00 AM, Chao Li wrote: > > >> On Aug 2, 2026, at 19:52, jian he 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/ >> > > 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/ The fix for the double ATPostAlterTypeCleanup() call is right in what it does, but rebased onto current master the list reset is incomplete, and it appears the gap reintroduces CVE-2026-6469. Since v6 was written, 6713a6e04cb added a third parallel list, tab->changedStatisticsOwners. The patch resets changedStatisticsOids/Defs but not changedStatisticsOwners. So on the second call (the SET EXPRESSION pass) the new statistics objects are paired with the previous leftover owners and the rebuild goes through CreateStatistics() with check_rights disabled, silently installing the wrong owner. Reproducer -- a statistics object silently changes owner, and an unrelated role can then drop the table owner's object: CREATE ROLE r_owner; CREATE ROLE r_other; GRANT CREATE, USAGE ON SCHEMA public TO r_other; CREATE TABLE t (k int, c int, b int GENERATED ALWAYS AS (k*2) STORED); ALTER TABLE t OWNER TO r_owner; CREATE STATISTICS s_c ON k, c FROM t; -- rebuilt in the ALTER TYPE pass ALTER STATISTICS s_c OWNER TO r_other; CREATE STATISTICS s_b ON k, b FROM t; -- rebuilt in the SET EXPRESSION pass ALTER STATISTICS s_b OWNER TO r_owner; SET ROLE r_owner; ALTER TABLE t ALTER COLUMN c TYPE bigint, ALTER COLUMN b SET EXPRESSION AS (k*3); RESET ROLE; SELECT stxname, stxowner::regrole FROM pg_statistic_ext WHERE stxrelid='t'::regclass; -- HEAD: ERROR: cache lookup failed for statistics object ... (s_b still r_owner) -- patched: succeeds, and s_b is now owned by r_other SET ROLE r_other; DROP STATISTICS s_b; -- HEAD/fixed: ERROR: must be owner of statistics object s_b -- patched: succeeds -- r_other drops r_owner's object RESET ROLE; The fix is to reset that list too, in the same block: list_free(tab->changedStatisticsOwners); tab->changedStatisticsOwners = NIL; I applied exactly that on top of v6 and re-ran the reproducer: s_b keeps its owner (r_owner), r_other's DROP is again refused with "must be owner", and the original combined-ALTER case still succeeds. It might be worth extending the owner-preservation test that came with 6713a6e04cb (stats_ext.sql) with a two-statistics-object ALTER TYPE + SET EXPRESSION case, since the existing test exercises only a single ALTER TYPE pass and wouldn't catch this. With that list added, the rest of the approach looks correct to me. -- Bryan Green EDB: https://www.enterprisedb.com