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 1vkdzK-000XDR-1O for pgsql-hackers@arkaria.postgresql.org; Tue, 27 Jan 2026 07:59:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vkdzH-00Chom-1L for pgsql-hackers@arkaria.postgresql.org; Tue, 27 Jan 2026 07:59:47 +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.96) (envelope-from ) id 1vkdzH-00Chob-0N for pgsql-hackers@lists.postgresql.org; Tue, 27 Jan 2026 07:59:47 +0000 Received: from mail-dy1-x132d.google.com ([2607:f8b0:4864:20::132d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vkdz9-00000000fnM-2ZrS for pgsql-hackers@lists.postgresql.org; Tue, 27 Jan 2026 07:59:41 +0000 Received: by mail-dy1-x132d.google.com with SMTP id 5a478bee46e88-2b72e49776eso8968673eec.1 for ; Mon, 26 Jan 2026 23:59:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769500776; x=1770105576; darn=lists.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=TzZh9AZYZ+pR3Eab49i8yE2Emy0MdQOFAR/kcrbl6JE=; b=DBS7Knxa+LZmYkl8x8Z6cZkHazMwBCuG7Xok/9R6fywvFWr+ZogUtBwy2eWB0qDFvm ylFuYsRLkC0RIBKyuReGrNBvsMG1D2SnlWJ9M8EqttrYW2BLLE4iwf3jzh0dqPtzfng1 B5bUmN6xxOFtEPVuwYKdQmuv8lFOSRYWhY8CB7jdikwBr/1/NVPGTBkqFOrEsUK7knM8 y1uhr6rbo+sf1uI0wR1vI/lIsWM7Vk1eeNar+NR+TrVPpnsrq7yl5SiWyrj3lbHwopZo vQW4lxd5JQxsitietFp6mdCamZe6gNq30+gpsFCA+3cXjhnZCCXXexTiP/kWUCyqlp0l OXtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769500776; x=1770105576; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=TzZh9AZYZ+pR3Eab49i8yE2Emy0MdQOFAR/kcrbl6JE=; b=N5iQWzdCVUfd01cQTJsF6c7Ek0O+6uDPKKU2ciGBNwrbIgHbOuCmuAlkXFeWwFy+01 D1EcxlMI5TMixLkx138N3YhCZZgfwDjWXUgDKwmlPiALJncEODCx8QSIM3dHOEtY/GZz ZmBFWLv6lfldU/GSyIlAhTH/PBHYwRZyT+0uLALNF/l/dThkXDLAKGXYzv3e0so8Ppyp wNnkPSdf/0HH3922HLv3crJogDpsRVj6crylKUZ9O3NUL45jQOc2qYCJR2F/icScapgS Lo2b2bdZiKYfzhog+Ey7tjH7DInfxAyAyB17iUNOp3EfQARaZ6nUKrd9d+WpSu8sxpQU Eflw== X-Gm-Message-State: AOJu0YwP2CJUaLeNkzZfj4NrYu4W83pA5y8xktNQwA4AsYuT2KlxOW9K 6TEw5TTM8lL4a+dZBCIlDc39BvA4G3LuSac+oZBV9RNb3czxMuYGCGJw X-Gm-Gg: AZuq6aL6/zqYlezStCfkWOOX2kYH4s4mNq8nr1GUs3msLaoec7glpRme6YV1nr7MXTx sNrQAfhE3FYd3mE7g1hKnOXF4rTFcaTCqSGFgPzU1cmsk0I03m9z0IHf/gz8HaPXmzTCKYmcb/1 JegCTZGqG16U3AVoqLdiiYZI4DGaqRZB5V3X1Js4NBOl2Bim1bKXC57GcARa55/Xn/JAdGUQhFi B1NdI0nlyaUlG4MsOIjXpqTojfuul04DH1CQrfMSJvjvRd3yMAvBPFLCPHrKAhfAtXgWzBvcYpu A5DCzqy4jx2+MQrSa6lWxjx8m9PvBgNBVGz3IYGjoWxcXFuEoD0zQq1+6VL5+JBD5yAa4oi8qCq EwXgHweh/C3/jANpCfEunEITom7qMLZ9nsNdVAozfqwv4j11/50HU8hp2bowSHnw8Kl+v8L2OVn Xx31z4KhXfENevG+RaGN13 X-Received: by 2002:a05:7300:cc12:b0:2ab:ecd0:5221 with SMTP id 5a478bee46e88-2b78da4b7e1mr624184eec.42.1769500776461; Mon, 26 Jan 2026 23:59:36 -0800 (PST) Received: from smtpclient.apple ([142.171.105.12]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2b73a9e1c17sm17301260eec.20.2026.01.26.23.59.34 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Jan 2026 23:59:35 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.300.41.1.7\)) Subject: Re: tablecmds: fix bug where index rebuild loses replica identity on partitions From: Chao Li In-Reply-To: Date: Tue, 27 Jan 2026 15:59:01 +0800 Cc: Postgres hackers Content-Transfer-Encoding: quoted-printable Message-Id: <0B38B9DC-A53C-437C-B9BD-807F30A032BA@gmail.com> References: To: Michael Paquier X-Mailer: Apple Mail (2.3864.300.41.1.7) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Jan 27, 2026, at 15:39, Michael Paquier = wrote: >=20 > On Tue, Jan 27, 2026 at 01:13:32PM +0800, Chao Li wrote: >> I found this bug while working on a related patch [1]. >>=20 >> When ALTER TABLE ... ALTER COLUMN TYPE causes an index rebuild, and >> that index is used as REPLICA IDENTITY on a partitioned table, the >> replica identity marking on partitions can be silently lost after the >> rebuild. >=20 > I am slightly confused by the tests included in the proposed patch. > On HEAD, if I undo the proposed changes of tablecmds.c, the tests > pass. If I run the tests of the patch with the changes of > tablecmds.c, the tests also pass. =20 Oops, that isn=E2=80=99t supposed to be so. I=E2=80=99ll check the test. > These tests don't check what you > want them to. >=20 > - if (tab->replicaIdentityIndex) > + if (tab->replicaIdentityIndexOids !=3D NIL) > elog(ERROR, "relation %u has multiple indexes marked as = replica identity", tab->relid); >=20 > This looks wrong to me. This new list tracks the OIDs of indexes > where you'd want to make sure that relreplident is updated, and it > could be possible, based on your proposal, that multiple indexes are > stored in this list. The error message is at least not in line > anymore. Actually, do we really need this extra list at all? The > list of indexes to rebuild are tracked already in changedIndexOids, > and the partitioned indexes seem to be in it, no? No, changedIndexOids only tracks the root index OID. DefineIndex() will = automatically rebuild indexes on all partitions, and won=E2=80=99t = return the rebuilt index OIDs to =E2=80=9Calter table=E2=80=9D. So, before index rebuild, this patch records potential affected indexes = in replicaIdentityIndexOids, and after index rebuild, restore replica = identity on them. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/