pgsql: Set HEAP_XMAX_INVALID for tuples updated by aborted subtransacti

Started by Michael Paquier28 days ago1 messagescommitters
Jump to latest
#1Michael Paquier
michael@paquier.xyz

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: /messages/by-id/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(+)