v60-0012-Fixed-the-stale-xid64-problem-at-the-heapam_tupl.patch

text/x-patch

Filename: v60-0012-Fixed-the-stale-xid64-problem-at-the-heapam_tupl.patch
Type: text/x-patch
Part: 11
Message: Re: Add 64-bit XIDs into PostgreSQL 15

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch v60-0012
Subject: Fixed the "stale xid64" problem at the heapam_tuple_satisfies_snapshot function.
File+
src/backend/access/heap/heapam_handler.c 8 0
From d2dd3d9e34404f5bc10ca42f1b896d66e09b67fc Mon Sep 17 00:00:00 2001
From: Evgeny Voropaev <evorop@gmail.com>
Date: Sun, 8 Dec 2024 23:47:31 +0800
Subject: [PATCH v60 12/15] Fixed the "stale xid64" problem at the
 heapam_tuple_satisfies_snapshot function.

This issue mostly appeared in practice as the "missing chunk" error during operations on TOASTS of the pg_statistic table.

Author: Ivan Kushnarenko <ivan.kush@tantorlabs.com>
Author: Evgeny Voropaev <evgeny.voropaev@tantorlabs.com> <evorop@gmail.com>
---
 src/backend/access/heap/heapam_handler.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index 48684b5f143..d1a34691d68 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -218,6 +218,7 @@ heapam_tuple_satisfies_snapshot(Relation rel, TupleTableSlot *slot,
 {
 	BufferHeapTupleTableSlot *bslot = (BufferHeapTupleTableSlot *) slot;
 	bool		res;
+	Page		page;
 
 	Assert(TTS_IS_BUFFERTUPLE(slot));
 	Assert(BufferIsValid(bslot->buffer));
@@ -227,6 +228,13 @@ heapam_tuple_satisfies_snapshot(Relation rel, TupleTableSlot *slot,
 	 * Caller should be holding pin, but not lock.
 	 */
 	LockBuffer(bslot->buffer, BUFFER_LOCK_SHARE);
+	/*
+	 * Need to reread min/max xids as they can be overwritten before
+	 */
+	page = BufferGetPage(bslot->buffer);
+	HeapTupleCopyXidsFromPage(bslot->buffer, bslot->base.tuple, page,
+							IsToastRelation(rel));
+
 	res = HeapTupleSatisfiesVisibility(bslot->base.tuple, snapshot,
 									   bslot->buffer);
 	LockBuffer(bslot->buffer, BUFFER_LOCK_UNLOCK);
-- 
2.48.1