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 1wqljf-002Og9-18 for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Aug 2026 06:01:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wqlje-004IMF-0v for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Aug 2026 06:01:14 +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 1wqljd-004IM7-30 for pgsql-hackers@lists.postgresql.org; Mon, 03 Aug 2026 06:01:14 +0000 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wqljc-00000001eeU-0Tsh for pgsql-hackers@postgresql.org; Mon, 03 Aug 2026 06:01:13 +0000 Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-38dcbade417so2771594a91.1 for ; Sun, 02 Aug 2026 23:01:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785736871; x=1786341671; darn=postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:content-type:from:to:cc :subject:date:message-id:reply-to:content-type; bh=DFzZDVxMtqQfWXbVuc2r6UHtr8F16L9TyiOOg64qQNA=; b=GmpoFNoG8xizmLKX7EQr3S/GwpN5EgR3xKpxHMPFwQmyOc/2A4WrMd1BtsOrcbsNpg Hq7bDeuhew+7m7TeQKE5crV1W7Jg5VO6DMgzigwcDVz83jRdg9T6gJCt5ogQOdwmQPNZ pE2jXPV4UNqZ6ZFVJ/dDe3Ct/LnjCNo7DpuboBrMkrsDOosL4m5w106De73Y2Nm8VBR8 kOju6ovnKo8KANevGO1kq67i/3hAruCNgDSSY6LpVnFfMNpmEZfMss/742Fqd56n7+8x /Ke4B0ntdVA2eLk+3L8Si1HoscwZKUSulz1sc/Glakwy1cVJratrDlnAc4xNGknIepPO AeRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785736871; x=1786341671; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:content-type:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=DFzZDVxMtqQfWXbVuc2r6UHtr8F16L9TyiOOg64qQNA=; b=ZBVzO9awHQxo6Q4aVEs/04dxYGjwEmwzWsVs0ed2y8AjCbIuJEEUrNr9g3pJdPVofy grdUbDLxDQdLvD7cQXINr9443MKSoJFi5SFyPPiUMCrkVTY5Rv+Z7eFaFPZHkyVZrlw4 GIjnhNw08txCIFnN0I4mvv2UdYKPH+oFmbZeIb2mnBzupP/J4sY0tIuJQ8qxv0In3tYt UGGOcqRBacsqmriR4lBWmc3s8xwnndn73QwSHBGsL62gJZK2/ZnT3yPM6xttvvgv60bM Y4DekrCXFgeGrn5n0llp4bNUPuVI+oJim9Ua8oo3lvDD45RxCrWOE5BgBqMT3gEC+P2y hjAA== X-Forwarded-Encrypted: i=1; AHgh+Rp8TOpnPslxGt7SL5InK89p5yuTbn8jbFwIEqryY3tasTm+DOuSP3T+0DYO8cAGhQcFZqLl7TqOYEDbJrzO@postgresql.org X-Gm-Message-State: AOJu0YzGp5giBY42bzRYnBvJjscGXrm+8BbRSEVU3ti1d60rzgn5H2lb tTV2UNrwE6wKJcDWFBCAN/WuGnbmklXqpZQhrUplq3fTXNmdmEcp5pox X-Gm-Gg: AR+sD11LfkxwKk3Epl7RYwqSqAahLYdJGuxrt0xAS2B1j6mYl8HpOK4dr+00W/vqoZE Oe89qljwBAQ+EI4NYM+MTKKqC2MLHs8N/VDY2El74ZOpW5erflo64AdkMSeKtp4x3KaVbCYpLu/ Kae3nZm25rs8Ki1yqOdbSxn1ZL9YQ7FfX84TTLT01CPA9ZcACRL+iLWqhMVa8ko4MqF/dmWtR54 SUeyyCDE7LqaIV0lt43q4ZD4ol+gKzFzgPO194he5Q6g35mu6ZCadzKstMjoG3z6gmFLzeg5GQC qiP/1jy07EOJwQnt6tmSaSSrkPT3WS5lipQpTZbB5OyWTdfdX+IqpXa40JIwodXhnRzBSe1RcFK vnMn8exIb2qWS+rY8+MwKnzPQqi3f/R+mcn0SjfrXNzM03c7i6YxqXT+Q1PcbZvmKQ9Bn8jpNjV pym/9dFZB6VRvPkBzFHYlCR+/qdGrpfRGfrjPMgwxAAGyrY8lM93FTTt510gTJhVUOxnnqwA== X-Received: by 2002:a17:90b:4c42:b0:37f:9cdf:f0ac with SMTP id 98e67ed59e1d1-38fbc4cf1b2mr8742150a91.27.1785736871165; Sun, 02 Aug 2026 23:01:11 -0700 (PDT) Received: from smtpclient.apple ([185.135.79.125]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2d04b15d26esm32256645ad.76.2026.08.02.23.01.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 02 Aug 2026 23:01:10 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.600.51.1.1\)) Subject: Re: bug, ALTER TABLE call ATPostAlterTypeCleanup twice for the same relation From: Chao Li In-Reply-To: Date: Mon, 3 Aug 2026 14:00:33 +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.3864.600.51.1.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Aug 2, 2026, at 19:52, jian he wrote: >=20 > Hi. >=20 > 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. >=20 > 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. >=20 > 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". >=20 > 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. > -------------------------------- >=20 >=20 >=20 > -- > 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 =E2=80=A6 but left those lists = untouched. ``` I think =E2=80=9Cleft=E2=80=9D should be =E2=80=9Cleaves=E2=80=9D to = keep the tense consistent with =E2=80=9Cdrops=E2=80=9D. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/