pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Set HEAP_XMAX_INVALID for tuples updated by aborted subtransacti
11+ messages / 2 participants
[nested] [flat]

* pgsql: Set HEAP_XMAX_INVALID for tuples updated by aborted subtransacti
@ 2026-10-26 00:55  Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 11+ messages in thread

From: Michael Paquier @ 2026-10-26 00:55 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Set HEAP_XMAX_INVALID for tuples updated by aborted subtransaction

HeapTupleSatisfiesVacuumHorizon() did not set HEAP_XMAX_INVALID on a
tuple inserted, then updated by a subtransaction that rolled back.
rewriteheap.c relies on this hint to tell if such tuples should be
treated as updated and would drop them, causing rewrites to lose some
tuples.

HeapTupleSatisfiesVacuumHorizon() is updated to set the hint
HEAP_XMAX_INVALID, so as heap AM is able to redirect such a tuple to its
correct route, and does not lose it.

This issue impacted both CLUSTER (down to v14) and REPACK [USING] (down
to v19).

Reported-by: Alperen Keles <alpkeles99@gmail.com>
Author: Shihao Zhong <zhong950419@gmail.com>
Author: Michael Paquier <michael@paquier.xyz>
Reported-by: Zhijie Hou <houzhijie22@gmail.com>
Reported-by: Takeshi Ideriha <iderihatakeshi@gmail.com>
Reported-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Discussion: https://postgr.es/m/19760-8f9a0eba17bc8c92@postgresql.org
Backpatch-through: 14

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/e7f4463e869cc006b7d3210c264d92b1016dcad2

Modified Files
--------------
src/backend/access/heap/heapam_visibility.c |  2 ++
src/test/regress/expected/cluster.out       | 28 ++++++++++++++++++++++++++++
src/test/regress/sql/cluster.sql            | 19 +++++++++++++++++++
3 files changed, 49 insertions(+)



^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* pgsql: Set HEAP_XMAX_INVALID for tuples updated by aborted subtransacti
@ 2026-10-26 00:55  Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 11+ messages in thread

From: Michael Paquier @ 2026-10-26 00:55 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Set HEAP_XMAX_INVALID for tuples updated by aborted subtransaction

HeapTupleSatisfiesVacuumHorizon() did not set HEAP_XMAX_INVALID on a
tuple inserted, then updated by a subtransaction that rolled back.
rewriteheap.c relies on this hint to tell if such tuples should be
treated as updated and would drop them, causing rewrites to lose some
tuples.

HeapTupleSatisfiesVacuumHorizon() is updated to set the hint
HEAP_XMAX_INVALID, so as heap AM is able to redirect such a tuple to its
correct route, and does not lose it.

This issue impacted both CLUSTER (down to v14) and REPACK [USING] (down
to v19).

Reported-by: Alperen Keles <alpkeles99@gmail.com>
Author: Shihao Zhong <zhong950419@gmail.com>
Author: Michael Paquier <michael@paquier.xyz>
Reported-by: Zhijie Hou <houzhijie22@gmail.com>
Reported-by: Takeshi Ideriha <iderihatakeshi@gmail.com>
Reported-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Discussion: https://postgr.es/m/19760-8f9a0eba17bc8c92@postgresql.org
Backpatch-through: 14

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/928c2eeed5291ddd68d5872ee03eac1cd4f7f387

Modified Files
--------------
src/backend/access/heap/heapam_visibility.c |  2 ++
src/test/regress/expected/cluster.out       | 28 ++++++++++++++++++++++++++++
src/test/regress/sql/cluster.sql            | 19 +++++++++++++++++++
3 files changed, 49 insertions(+)



^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* pgsql: Set HEAP_XMAX_INVALID for tuples updated by aborted subtransacti
@ 2026-10-26 00:55  Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 11+ messages in thread

From: Michael Paquier @ 2026-10-26 00:55 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Set HEAP_XMAX_INVALID for tuples updated by aborted subtransaction

HeapTupleSatisfiesVacuumHorizon() did not set HEAP_XMAX_INVALID on a
tuple inserted, then updated by a subtransaction that rolled back.
rewriteheap.c relies on this hint to tell if such tuples should be
treated as updated and would drop them, causing rewrites to lose some
tuples.

HeapTupleSatisfiesVacuumHorizon() is updated to set the hint
HEAP_XMAX_INVALID, so as heap AM is able to redirect such a tuple to its
correct route, and does not lose it.

This issue impacted both CLUSTER (down to v14) and REPACK [USING] (down
to v19).

Reported-by: Alperen Keles <alpkeles99@gmail.com>
Author: Shihao Zhong <zhong950419@gmail.com>
Author: Michael Paquier <michael@paquier.xyz>
Reported-by: Zhijie Hou <houzhijie22@gmail.com>
Reported-by: Takeshi Ideriha <iderihatakeshi@gmail.com>
Reported-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Discussion: https://postgr.es/m/19760-8f9a0eba17bc8c92@postgresql.org
Backpatch-through: 14

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/5df84b355ab78cfc3e8c10d37a80d627a53ed365

Modified Files
--------------
src/backend/access/heap/heapam_visibility.c |  2 ++
src/test/regress/expected/cluster.out       | 28 ++++++++++++++++++++++++++++
src/test/regress/sql/cluster.sql            | 19 +++++++++++++++++++
3 files changed, 49 insertions(+)



^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* pgsql: Set HEAP_XMAX_INVALID for tuples updated by aborted subtransacti
@ 2026-10-26 00:55  Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 11+ messages in thread

From: Michael Paquier @ 2026-10-26 00:55 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Set HEAP_XMAX_INVALID for tuples updated by aborted subtransaction

HeapTupleSatisfiesVacuumHorizon() did not set HEAP_XMAX_INVALID on a
tuple inserted, then updated by a subtransaction that rolled back.
rewriteheap.c relies on this hint to tell if such tuples should be
treated as updated and would drop them, causing rewrites to lose some
tuples.

HeapTupleSatisfiesVacuumHorizon() is updated to set the hint
HEAP_XMAX_INVALID, so as heap AM is able to redirect such a tuple to its
correct route, and does not lose it.

This issue impacted both CLUSTER (down to v14) and REPACK [USING] (down
to v19).

Reported-by: Alperen Keles <alpkeles99@gmail.com>
Author: Shihao Zhong <zhong950419@gmail.com>
Author: Michael Paquier <michael@paquier.xyz>
Reported-by: Zhijie Hou <houzhijie22@gmail.com>
Reported-by: Takeshi Ideriha <iderihatakeshi@gmail.com>
Reported-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Discussion: https://postgr.es/m/19760-8f9a0eba17bc8c92@postgresql.org
Backpatch-through: 14

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/08f0cec8fb55093bd225b77bb45983c6001ad8de

Modified Files
--------------
src/backend/access/heap/heapam_visibility.c |  2 ++
src/test/regress/expected/cluster.out       | 28 ++++++++++++++++++++++++++++
src/test/regress/sql/cluster.sql            | 19 +++++++++++++++++++
3 files changed, 49 insertions(+)



^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* pgsql: Set HEAP_XMAX_INVALID for tuples updated by aborted subtransacti
@ 2026-10-26 00:55  Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 11+ messages in thread

From: Michael Paquier @ 2026-10-26 00:55 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Set HEAP_XMAX_INVALID for tuples updated by aborted subtransaction

HeapTupleSatisfiesVacuumHorizon() did not set HEAP_XMAX_INVALID on a
tuple inserted, then updated by a subtransaction that rolled back.
rewriteheap.c relies on this hint to tell if such tuples should be
treated as updated and would drop them, causing rewrites to lose some
tuples.

HeapTupleSatisfiesVacuumHorizon() is updated to set the hint
HEAP_XMAX_INVALID, so as heap AM is able to redirect such a tuple to its
correct route, and does not lose it.

This issue impacted both CLUSTER (down to v14) and REPACK [USING] (down
to v19).

Reported-by: Alperen Keles <alpkeles99@gmail.com>
Author: Shihao Zhong <zhong950419@gmail.com>
Author: Michael Paquier <michael@paquier.xyz>
Reported-by: Zhijie Hou <houzhijie22@gmail.com>
Reported-by: Takeshi Ideriha <iderihatakeshi@gmail.com>
Reported-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Discussion: https://postgr.es/m/19760-8f9a0eba17bc8c92@postgresql.org
Backpatch-through: 14

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/07d1b44181df03b6b16e372a1be4511fa94effdf

Modified Files
--------------
src/backend/access/heap/heapam_visibility.c |  2 ++
src/test/regress/expected/cluster.out       | 28 ++++++++++++++++++++++++++++
src/test/regress/sql/cluster.sql            | 19 +++++++++++++++++++
3 files changed, 49 insertions(+)



^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* pgsql: Set HEAP_XMAX_INVALID for tuples updated by aborted subtransacti
@ 2026-10-26 00:55  Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 11+ messages in thread

From: Michael Paquier @ 2026-10-26 00:55 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Set HEAP_XMAX_INVALID for tuples updated by aborted subtransaction

HeapTupleSatisfiesVacuumHorizon() did not set HEAP_XMAX_INVALID on a
tuple inserted, then updated by a subtransaction that rolled back.
rewriteheap.c relies on this hint to tell if such tuples should be
treated as updated and would drop them, causing rewrites to lose some
tuples.

HeapTupleSatisfiesVacuumHorizon() is updated to set the hint
HEAP_XMAX_INVALID, so as heap AM is able to redirect such a tuple to its
correct route, and does not lose it.

This issue impacted both CLUSTER (down to v14) and REPACK [USING] (down
to v19).

Reported-by: Alperen Keles <alpkeles99@gmail.com>
Author: Shihao Zhong <zhong950419@gmail.com>
Author: Michael Paquier <michael@paquier.xyz>
Reported-by: Zhijie Hou <houzhijie22@gmail.com>
Reported-by: Takeshi Ideriha <iderihatakeshi@gmail.com>
Reported-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Discussion: https://postgr.es/m/19760-8f9a0eba17bc8c92@postgresql.org
Backpatch-through: 14

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/0b565674945c2b08d131f2d821400ed11181ac37

Modified Files
--------------
src/backend/access/heap/heapam_visibility.c |  2 ++
src/test/regress/expected/cluster.out       | 28 ++++++++++++++++++++++++++++
src/test/regress/sql/cluster.sql            | 19 +++++++++++++++++++
3 files changed, 49 insertions(+)



^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* pgsql: Set HEAP_XMAX_INVALID for tuples updated by aborted subtransacti
@ 2026-10-26 00:55  Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 11+ messages in thread

From: Michael Paquier @ 2026-10-26 00:55 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Set HEAP_XMAX_INVALID for tuples updated by aborted subtransaction

HeapTupleSatisfiesVacuumHorizon() did not set HEAP_XMAX_INVALID on a
tuple inserted, then updated by a subtransaction that rolled back.
rewriteheap.c relies on this hint to tell if such tuples should be
treated as updated and would drop them, causing rewrites to lose some
tuples.

HeapTupleSatisfiesVacuumHorizon() is updated to set the hint
HEAP_XMAX_INVALID, so as heap AM is able to redirect such a tuple to its
correct route, and does not lose it.

This issue impacted both CLUSTER (down to v14) and REPACK [USING] (down
to v19).

Reported-by: Alperen Keles <alpkeles99@gmail.com>
Author: Shihao Zhong <zhong950419@gmail.com>
Author: Michael Paquier <michael@paquier.xyz>
Reported-by: Zhijie Hou <houzhijie22@gmail.com>
Reported-by: Takeshi Ideriha <iderihatakeshi@gmail.com>
Reported-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Discussion: https://postgr.es/m/19760-8f9a0eba17bc8c92@postgresql.org
Backpatch-through: 14

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/278d2a672e65d22d5d191c674cda863623df59d7

Modified Files
--------------
src/backend/access/heap/heapam_visibility.c |  2 ++
src/test/regress/expected/cluster.out       | 28 ++++++++++++++++++++++++++++
src/test/regress/sql/cluster.sql            | 19 +++++++++++++++++++
3 files changed, 49 insertions(+)



^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: pgsql: Set HEAP_XMAX_INVALID for tuples updated by aborted subtransacti
@ 2026-10-28 19:32  Robert Haas <robertmhaas@gmail.com>
  parent: Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 11+ messages in thread

From: Robert Haas @ 2026-10-28 19:32 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; +Cc: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>

On Sun, Oct 25, 2026 at 8:56 PM Michael Paquier <michael@paquier.xyz> wrote:
> Set HEAP_XMAX_INVALID for tuples updated by aborted subtransaction
>
> HeapTupleSatisfiesVacuumHorizon() did not set HEAP_XMAX_INVALID on a
> tuple inserted, then updated by a subtransaction that rolled back.
> rewriteheap.c relies on this hint to tell if such tuples should be
> treated as updated and would drop them, causing rewrites to lose some
> tuples.
>
> HeapTupleSatisfiesVacuumHorizon() is updated to set the hint
> HEAP_XMAX_INVALID, so as heap AM is able to redirect such a tuple to its
> correct route, and does not lose it.

Uggh. I think that this is the right fix given that
rewrite_heap_tuple() is documented to rely on hint bits being set for
correctness, but it seems to me to be pretty questionable that we rely
on hint bits being set for correctness. It's not going to be obvious
to someone modifying HeapTupleSatisfiesVacuum() or
HeapTupleSatisfiesVacuumHorizon() that rewrite_heap_tuple() critically
depends on that, and even if we added a comment about that, somebody
reading that comment might justifiably complain about our decision to
create such a dependency.

-- 
Robert Haas
Databricks






^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: pgsql: Set HEAP_XMAX_INVALID for tuples updated by aborted subtransacti
@ 2026-10-29 08:11  Michael Paquier <michael@paquier.xyz>
  parent: Robert Haas <robertmhaas@gmail.com>
  0 siblings, 1 reply; 11+ messages in thread

From: Michael Paquier @ 2026-10-29 08:11 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>

On Wed, Oct 28, 2026 at 03:32:44PM -0400, Robert Haas wrote:
> Uggh. I think that this is the right fix given that
> rewrite_heap_tuple() is documented to rely on hint bits being set for
> correctness, but it seems to me to be pretty questionable that we rely
> on hint bits being set for correctness. It's not going to be obvious
> to someone modifying HeapTupleSatisfiesVacuum() or
> HeapTupleSatisfiesVacuumHorizon() that rewrite_heap_tuple() critically
> depends on that, and even if we added a comment about that, somebody
> reading that comment might justifiably complain about our decision to
> create such a dependency.

As far as I know this is implied since 7b78474da356.  So it's been
around for some time...  It's really hard to miss, as the other thread
has proved.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: pgsql: Set HEAP_XMAX_INVALID for tuples updated by aborted subtransacti
@ 2026-10-31 00:34  Michael Paquier <michael@paquier.xyz>
  parent: Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 11+ messages in thread

From: Michael Paquier @ 2026-10-31 00:34 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>

On Thu, Oct 29, 2026 at 05:11:26PM +0900, Michael Paquier wrote:
> As far as I know this is implied since 7b78474da356.  So it's been
> around for some time...  It's really hard to miss, as the other thread
> has proved.

I meant the opposite here, as of "It's really *easy* to miss, as the
other thread has proved".  Sorry for the confusion.  :)
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: pgsql: Set HEAP_XMAX_INVALID for tuples updated by aborted subtransacti
@ 2026-10-31 10:42  Robert Haas <robertmhaas@gmail.com>
  parent: Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 11+ messages in thread

From: Robert Haas @ 2026-10-31 10:42 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; +Cc: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>

On Fri, Oct 30, 2026 at 8:34 PM Michael Paquier <michael@paquier.xyz> wrote:
> I meant the opposite here, as of "It's really *easy* to miss, as the
> other thread has proved".  Sorry for the confusion.  :)

That makes more sense. Not that I'm volunteering you, or myself, but
maybe somebody should put some effort into redesigning this so that
there isn't so much action-at-a-distance.

-- 
Robert Haas
Databricks






^ permalink  raw  reply  [nested|flat] 11+ messages in thread


end of thread, other threads:[~2026-10-31 10:42 UTC | newest]

Thread overview: 11+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-10-26 00:55 pgsql: Set HEAP_XMAX_INVALID for tuples updated by aborted subtransacti Michael Paquier <michael@paquier.xyz>
2026-10-28 19:32 ` Robert Haas <robertmhaas@gmail.com>
2026-10-29 08:11   ` Michael Paquier <michael@paquier.xyz>
2026-10-31 00:34     ` Michael Paquier <michael@paquier.xyz>
2026-10-31 10:42       ` Robert Haas <robertmhaas@gmail.com>
2026-10-26 00:55 pgsql: Set HEAP_XMAX_INVALID for tuples updated by aborted subtransacti Michael Paquier <michael@paquier.xyz>
2026-10-26 00:55 pgsql: Set HEAP_XMAX_INVALID for tuples updated by aborted subtransacti Michael Paquier <michael@paquier.xyz>
2026-10-26 00:55 pgsql: Set HEAP_XMAX_INVALID for tuples updated by aborted subtransacti Michael Paquier <michael@paquier.xyz>
2026-10-26 00:55 pgsql: Set HEAP_XMAX_INVALID for tuples updated by aborted subtransacti Michael Paquier <michael@paquier.xyz>
2026-10-26 00:55 pgsql: Set HEAP_XMAX_INVALID for tuples updated by aborted subtransacti Michael Paquier <michael@paquier.xyz>
2026-10-26 00:55 pgsql: Set HEAP_XMAX_INVALID for tuples updated by aborted subtransacti Michael Paquier <michael@paquier.xyz>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox