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.98.2) (envelope-from ) id 1xJiSi-00000000Nmo-0kUH for pgsql-bugs@arkaria.postgresql.org; Thu, 22 Oct 2026 02:23:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xJiRh-00000007xxz-3CHl for pgsql-bugs@arkaria.postgresql.org; Thu, 22 Oct 2026 02:22:21 +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.98.2) (envelope-from ) id 1xJiRg-00000007xxr-3jHC for pgsql-bugs@lists.postgresql.org; Thu, 22 Oct 2026 02:22:21 +0000 Received: from fout-a6-smtp.messagingengine.com ([103.168.172.149]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xJiRc-00000000KKr-45df for pgsql-bugs@lists.postgresql.org; Thu, 22 Oct 2026 02:22:20 +0000 Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfout.phl.internal (Postfix) with ESMTP id 7813CEC0224 for ; Wed, 21 Oct 2026 22:22:14 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Wed, 21 Oct 2026 22:22:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1792635734; x=1792722134; bh=j1onRqNjYZ b/+rySE/LkluH/AwEb72kCPXLRGvVmkV0=; b=EP2xshu6CB693Ec7xq7Uw6S75S DI/MoJ5x9vBh/z326eyOCB03lFkK4fG+hzSmXt6aB/fcSNjANH8haVeGeOoN0LKm kdvgtwHslYIXTMF7MnJGh8h5rTH0zaPmUJfGbKXYPVD9xbHdNXjJ9Rvn0uZKV6Ln a2IPy9GM4MA8ywJdokaNIE0KBQuQAlv2zwTPIshL0C8JM2W2ip/3zhkPwgl1N48y P/Ehwwx6wBffdOcVv276QnU0Dcu6MKwjMGB9ayHxLmvPdLrsyGc8OKIhcD6BMiu2 Sejv0QohFoqKz1fIr5FBmI1f1gZik6lxgKHl6RfbKZcKjhyZ0BfiPC2aisBA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1792635734; x=1792722134; bh=j1onRqNjYZb/+rySE/LkluH/AwEb72kCPXL RGvVmkV0=; b=SWW3EDBfg1kyWW+69TnqI1IXPjADPsmcJDR+5mXsdhjQDWNIjfX Ho21Pdg+lZCJtr5TZ2ifR/WZp/8/qjRAu6XT3vmEUs58JBzs3D/gzm8nRQ72wM7a Xj4q4kYcv83ufCfFiCE2zxEZpuoSk7gnCdEvlb6JBmzCT/XX3lL4AtdWqawBx/uc Nge6PkeNxi7E0v+IvhM0t4ZbJSkEk6e5qi0QsZflltPLPfhA1sGLEToSdHIfMqe9 o0tPVXQAafW0I/8AdSRMsPSm+67rZPvAFQOsC0fqepcHcNhknEvvJ41aAVoC4eXQ 9/fOUzMbs/nV/GKNsrNxi54Tb5KU5103vfw== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-07; repo=github.com/dkim2wg/interop; date=2026-10-18; sw=lmtpprox; action=sign d=paquier.xyz a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1792635734; d=paquier.xyz; mf=PG1pY2hhZWxAcGFxdWllci54eXo+; rt=PHBnc3FsLWJ1Z3NAbGlzdHMucG9zdGdyZXNxbC5vcmc+; s=fm2:rsa-sha256:e44u2kGcVZAST0BgJVAUjPINSQvyMF5OexvwKL1ZVV0d++1 97WYJXAIjNliX+g5L9IQ0pWegJaUFJiJBGwmJKHv9/fdlZ4snZs0arKZYJoo8xum N79pW5kF1yAZnEsts+giGNkKoqGfyahUPxIgmFVyNHBmV3yJ9HD2Ev0N8/IsxfrD 8M0RIbLtO2RrU7rKS+qv8T2uGl2aN/dK7j/TUoqIEA0mHHfQbJsydrqxj30dFtOG iUbUw4PefyvnuPXNKaHvwA3lPWnKII+QVlC0VEu/ewMgsH7qXWjVj6xhsh3jYa1D BzXkEw5QFoSLTNFGlD9yD9lwlAe/UcvOzedM4Gg==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-07; repo=github.com/dkim2wg/interop; date=2026-10-18; sw=lmtpprox; action=mi-m=1; hc=12; hn=cc,content-disposition,content-type,date,feedback-id,from, in-reply-to,message-id,mime-version,references,subject,to; Message-Instance: m=1; h=sha256:KUTxfbIeaUw+5YKyx/SqUpaRnpTA7S4nF5C0YjsvWGA=:Tt+vaJdhy5kHSxK9QKALZVH3AVS3oNSNgFsl73RlWGQ=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTGjNyjhFxv/FJft6F+8dldYScUtcWCV81CV9j1kXz3drb8mSdWj8VamkeG3k9tNiL ppzYPO43Gl7pbWKzfaZ9cLFyjheFZSs/fnUIpxwWa/aNsriB92o99Rv3KHcWv7nPHc55tk aSa3VqtOYkahH0i60AjUunx9JbBQ8ljKHgIi88fmBrKzbC5EFljNO0aKBEm8eGiqcIpRcr x4r+5UO7HbrecjESMkkoFm4dojx912ct/Q8enzXAe1A9yiLDqvYvWppXkWICJz0vnSqx3I Rr3m04WmLcL6dymo8hRU6MBQU2JZOfwNQjsPjiisWD9VnRtD0n9D1Nauc9Hdr2nL6r6Fai Ynqc8gofC5DP9wvmXw2X3fY0vs85dZ7CcGfttwY3zwAPuBMTRXrHDNut5+OM8fkqea6QwV gvPyPGqIKftx2Vqqfz3CObjhg1wBYuWsAbdivFIQMd3k2cMKmMNaEad06teRPQwiOIt972 IrWpxBoqtY3o1kCeJJnpBaAn4G+StsrTv2yG0HRpNpNeNo6wb8FPcc4Gwx8byBqih+u9SV zTFY75aAT6AOxlcN0AK7tGD8ckCDqS90xT5tuMfLNLDM+05RxDGEvk345z0uRpDYj7EDap FKwDL5PseE3gqKQwTO4v3pxSA1X1k8KgQFbCQIRk4H6WCwW4Ox2df9gLlyog X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 21 Oct 2026 22:22:12 -0400 (EDT) Date: Thu, 22 Oct 2026 11:22:08 +0900 From: Michael Paquier To: Zhijie Hou Cc: shihao zhong , Takeshi Ideriha , Ayush Tiwari , alpkeles99@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #19760: CLUSTER loses a row the transaction inserted and then updated in a rolled-back subtransaction Message-ID: References: <5fff280b-96c4-497f-bbfc-0af95b9844b3@gmail.com> <949ad7b3-2b0e-40dc-b6ac-e84da432149b@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="nnPg7+TGHmmyZ4C0" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --nnPg7+TGHmmyZ4C0 Content-Type: multipart/mixed; boundary="HJYbPr8SZxC65jHm" Content-Disposition: inline --HJYbPr8SZxC65jHm Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Oct 21, 2026 at 06:01:28PM +0800, Zhijie Hou wrote: > + if (!(tuple->t_infomask & HEAP_XMAX_INVALID) && > + !HEAP_XMAX_IS_LOCKED_ONLY(tuple->t_infomask) && > + !HeapTupleHeaderIsOnlyLocked(tuple)) > + { > + TransactionId xmax =3D HeapTupleHeaderGetUpdateXid(tuple); > + > + if (!TransactionIdIsInProgress(xmax) && > + !TransactionIdDidCommit(xmax)) > + SetHintBits(tuple, buffer, HEAP_XMAX_INVALID, > + InvalidTransactionId); >=20 > If a tuple's Xmax is a MultiXact and the updating subtransaction is still= in > progress when HeapTupleHeaderIsOnlyLocked() is called, it returns false. > However, if that updating subtransaction aborts before the second > TransactionIdIsInProgress() check, the second check returns false and sets > HEAP_XMAX_INVALID on the tuple even though the MultiXact still has active > members, which I think violates the MultiXact hint-bit standard. Perhaps also check for HEAP_XMAX_IS_MULTI to skip the multixacts and make sure that active members are not lost, then? I am not completely sure if this would be always right, though, these code paths are the hard-level definition of tricky. What I am really wondering is why do we actually need to fix *two* problems at once? The first SetHintBits() looks like a no-brainer to me, and links to the second permutation in the test "s1_plain s1_count" where we do a CLUSTER after an UPDATE rollbacked to a previous savepoint. I don't think that there is a need for an isolation test on this one, either, wouldn't a plain SQL sequence be sufficient? That's not to mention that the first one can be hit with DDLs that do some update on catalogs, as well. Say, an ANALYZE with a CLUSTER (this SQL sequence is a courtesy of Claude, I've just pointed to it the possibility and the agent has confirmed the sequence): BEGIN; -- force the index-scan path SET LOCAL random_page_cost =3D 0.0001; SET LOCAL seq_page_cost =3D 1000; CREATE TABLE s (a int); INSERT INTO s VALUES (1); ANALYZE s; SAVEPOINT sp; INSERT INTO s SELECT g FROM generate_series(2, 1000) g; -- updates pg_statistic row ANALYZE s; ROLLBACK TO sp; RELEASE sp; CLUSTER VERBOSE pg_statistic USING pg_statistic_relid_att_inh_index; COMMIT; -- one row expected, none on HEAD. SELECT count(*) FROM pg_statistic WHERE starelid =3D 's'::regclass; The VACUUM FULL on pg_class is less exciting, points to the second SetHintBits(). And as far as I can see, this one is actually the source of a measurable regression. To prove my point, see the SQL scripts attached. Use them like that: 1) Run setup.sql, for some relations. 2) Run holders.sql through a bunch of sessions (64 here, could be more). This is important to stress TransactionIdIsInProgress(): for i in $(seq 64); do psql -X -f holders.sql > /dev/null 2>&1 & done 3) In a new session, run either subxact_updates.sql, delete.sql or insert_only.sql. 3) Run vacuum.sql, measure its runtime. Then with 500k rows, here are some VACUUM average runtimes in ms from one of my laptops: HEAD Shihao's v2 subxact_updates 1408 2123 delete 686 1369 insert_only 689 693 The subxact_updates is an edge case, fine, still it regresses badly. The DELETE case is a much more common case. It regresses even more badly, and that does not look acceptable to me. That should be optimizable, of course, I don't really know yet how to do that. I know however that regressions like these ones are never good. So the first step to me would be a "Divide and Conquer" strategy, where we should look at each problem independently instead of trying to do too much at once. -- Michael --HJYbPr8SZxC65jHm Content-Type: application/sql Content-Disposition: attachment; filename=setup.sql Content-Transfer-Encoding: quoted-printable -- Tables used by the other scripts. Run once.=0ADROP TABLE IF EXISTS t;= =0ADROP TABLE IF EXISTS h;=0ACREATE TABLE t (id int, v int);=0ACREATE TABLE= h (x int);=0A --HJYbPr8SZxC65jHm Content-Type: application/sql Content-Disposition: attachment; filename=delete.sql Content-Transfer-Encoding: quoted-printable -- xmax is the xid of the inserter itself.=0A-- Leave the transaction open!= !=0A\if :{?n}=0A\else=0A \set n 500000=0A\endif=0ABEGIN;=0AINSERT INTO t S= ELECT g, 0 FROM generate_series(1, :n) g;=0ADELETE FROM t;=0A --HJYbPr8SZxC65jHm Content-Type: application/sql Content-Disposition: attachment; filename=insert_only.sql Content-Transfer-Encoding: quoted-printable -- no xmax. Leaves the transaction open.=0A\if :{?n}=0A\else=0A \set n 50= 0000=0A\endif=0ABEGIN;=0AINSERT INTO t SELECT g, 0 FROM generate_series(1, = :n) g;=0A --HJYbPr8SZxC65jHm Content-Type: application/sql Content-Disposition: attachment; filename=subxact_updates.sql Content-Transfer-Encoding: quoted-printable -- Every old tuple version has as xmax a distinct subxid, released=0A-- but= still running. Leave the transaction open!=0A\if :{?n}=0A\else=0A \set n= 500000=0A\endif=0ABEGIN;=0AINSERT INTO t SELECT g, 0 FROM generate_series(= 1, :n) g;=0ADO $$=0ADECLARE=0A r record;=0ABEGIN=0A FOR r IN SELECT ctid = AS c FROM t LOOP=0A BEGIN=0A UPDATE t SET v =3D 1 WHERE ctid =3D r.= c;=0A EXCEPTION WHEN others THEN NULL;=0A END;=0A END LOOP;=0AEND $$= ;=0A --HJYbPr8SZxC65jHm Content-Type: application/sql Content-Disposition: attachment; filename=vacuum.sql Content-Transfer-Encoding: quoted-printable -- txid_current() is required here..=0ASELECT txid_current();=0A\timing on= =0AVACUUM t;=0AVACUUM t;=0AVACUUM t;=0AVACUUM t;=0AVACUUM t;=0AVACUUM t;=0A= VACUUM t;=0AVACUUM t;=0AVACUUM t;=0A\timing off=0A --HJYbPr8SZxC65jHm Content-Type: application/sql Content-Disposition: attachment; filename=holders.sql Content-Transfer-Encoding: quoted-printable -- One holder session: an open transaction with 60 released subtransactions= ,=0A-- each with its own xid.=0A-- Start many of them first, in the backgro= und. They sleep and wait..=0ABEGIN;=0ADO $$=0ABEGIN=0A FOR i IN 1..60 LOO= P=0A BEGIN=0A INSERT INTO h VALUES (i);=0A EXCEPTION WHEN others= THEN NULL;=0A END;=0A END LOOP;=0AEND $$;=0ASELECT pg_sleep(7200);=0A --HJYbPr8SZxC65jHm-- --nnPg7+TGHmmyZ4C0 Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmrZc1AACgkQnvQgOdby QH3ytQ/9FfP2F0v6lOfiEDQkfdhOcgU28lCcmN9D0F63SXjj8cSI/nqvdi6YoB7G BcH2NGj7pjwMKelx+WrSnsIeM85HbxXBCyI/B1OejeyduTujIA7f0niWtCOri8Db p/R1nM2GUcIbkCIt4lmDC4ZftKuUKeDqEaxy7M0lc+SSgcV/Vso5nInzDAKjPuiq zypGTjLd5SOliLIWFm2KUJDxoXoy67F4DX6FgTkfPglXVxMX7LDTFpsLk9Sx+IeD So6Xjq42c9ofJSmIqoPi7YF+IvbYt1SLgTa4ifNRbQKGYWwSTEo7CfGpD//sFdYj /AlxRoysg6n+1aib1miEpMLrloo/nDuOQBZtiqQ2/asXVCck0SgYizYYPefzQ6UM DQ1m1OQ+samCzpNB6imw+oGwOH6HhYL51SxEnXZADT5+i9usTN0hnS3QLRU0BK7v y6SqHPvhFQNnLW5/THqFHm4n+CLZqfFmARTuvlb3mbYeNMzoxBWfXJfIe5c+Bb0a oy1Aax4UaSB0wGqIjAM2DgJ9GESyNJQKglGQtRNn09pZuAtoQjQ5zjn29KWd+bVC kNGdzejXZZZ3rjyp9vltfmuMhmG7lA1rQfphDTIfHbDGpvvP6zT2z+FQiK2LQC6A 7l4KGz5q5CqZQTYpa30itHnE55pw2CWjqiF+2E1xE8t8jhZ/4Ec= =+oDg -----END PGP SIGNATURE----- --nnPg7+TGHmmyZ4C0--