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 1vqU3R-00BfkH-0C for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Feb 2026 10:36:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vqU3P-0080vS-2q for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Feb 2026 10:36:12 +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 1vqU3P-0080vK-1k for pgsql-hackers@lists.postgresql.org; Thu, 12 Feb 2026 10:36:12 +0000 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vqU3O-00000000IbL-0jdf for pgsql-hackers@postgresql.org; Thu, 12 Feb 2026 10:36:12 +0000 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-436317c80f7so1144294f8f.1 for ; Thu, 12 Feb 2026 02:36:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1770892569; x=1771497369; darn=postgresql.org; h=message-id:date:mime-version:comments:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=wcjtVfifV5eJ1lZvhn13MoohkUpKr+zDRDVBw6w/4BA=; b=MqSDIzjwf9wGXHwSlqQwRGEmTMkbkDZB3JXKohm4YyDpjbYXwZpgnWoWjZpl9G38XR Cq870cyc0q/8J9ds8NtdqD1LbGq8PxdRphFZirAznkxM7nbjhh4hHbfjM41WISla7WiI U1wyhTxnJmAAfIV/LaFJ69t+j2YJY+dEQKhqdVzDvWpdxb3IXw5arQXcwLJqRN7rimnD rdCnz+Q0hqkTnvmepUfPryC8UQfSzoQeT/yqFlU/F7EdaKXXTGwml4T0r51ltLyIiqIR L22qDJHmritAJuTsFbuTc6sxkTN5Es5Kk2vff4wU/b923k4Vw6q+lFf4VJTZyYvbbH3G vL5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770892569; x=1771497369; h=message-id:date:mime-version:comments:references:in-reply-to :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=wcjtVfifV5eJ1lZvhn13MoohkUpKr+zDRDVBw6w/4BA=; b=QLOM3t3TRDpaDgqddfI5rOxnEJK1R05p8NzQTo8feqkzDHJqeLsFcpklL3CKDzAGQC G3oDHmua+4/o59fMHmuF1evKcoGFVCet1Qr+PsEItWY6YolWVzgErjPJerKgWMEzuiHt 9vrB+9qm5GvmkNFPbXtsoN9MYEz5oTm4tgAXl8janFFwrGuohzSb4YjW5tAwhnjhwEdW 40ne1mnEzM8DXZuiYClw0Ju0HuxI/1fro9vfCL+FjQmN9s6l574CpmqUTG171sZdx3jK Nkvkzfjz31+3RUxjvtXtLBC8zFn6A5ZL4KX3EUMAhBBLDDW+TXlue6IypnEcsKiMwzB+ XJnw== X-Forwarded-Encrypted: i=1; AJvYcCW4xSfGkbOpfzIaWJPdnbD1r65OYucPdF+f9kCEp8cTMed92uOJl0DCjs+TTr1yotXBJFfaYpBZ9GHWHX74@postgresql.org X-Gm-Message-State: AOJu0YyuZ7arcynyVTnrHu93RhI+cCNcU6SQlg9J/ri66DTed24YsPF3 LEXyvD7Cud1GZOVSFAkYythnfzcAt7xVPy1TPJpXj7mZwOWfUXcr5JpididWZsRvRu8= X-Gm-Gg: AZuq6aKUavmU39vFCmAfW0ZpNs7SaDZW/KKSkLkk2fNA9UpUa7xXwRy6MydLj9TZw8i 0KbdQBXWB/cKB21kvSZEST/YnxR89pgiWhKCLBPyBNzQX8wr9xHBtCxyi0owhEAzGweK2l6h8eF seV2TzQvxJsbg51RvDCLp4hWBkukLRh+5kDTJcN4A9NYB4aU12Zf8eM/GTeEI3UOeF0Q3kynXVv haaoiAbbcHmvq+sZ6e38r25NTrJy/V6vfLjEyrnnyYxwUt2eruEVGI9/f2QEypL/rjQ+uAY7ot4 oRdFQduEFeR23IVRWryxRjw6gBwN2pjoeAxEeJRf0wgZ/e3JYv54uoj9t8HER2Z+X3nr8Uf9Wmm pDr5LD4kwgjkgfvjCqCPjWJt2y5fj5M7LejQYbsFiOrpSTGX7+PBmvdpMQvfQlIcDvu7AtYfUW5 cqwebIsndABp9l0UFIcvEvttoKgcNDbGC/j4G6 X-Received: by 2002:a05:6000:420d:b0:437:6c0c:346c with SMTP id ffacd0b85a97d-4378e73b090mr3570674f8f.28.1770892569188; Thu, 12 Feb 2026 02:36:09 -0800 (PST) Received: from localhost (109-81-168-142.rct.o2.cz. [109.81.168.142]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43783e38e26sm10692598f8f.26.2026.02.12.02.36.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Feb 2026 02:36:08 -0800 (PST) From: Antonin Houska To: Andres Freund cc: Kirill Reshke , Heikki Linnakangas , Melanie Plageman , Matthias van de Meent , pgsql-hackers@postgresql.org, Thomas Munro , Noah Misch , Robert Haas , Michael Paquier Subject: Re: Buffer locking is special (hints, checksums, AIO writes) In-reply-to: References: <1108f18d-cf7c-4f17-b29c-a119fe42f7e5@iki.fi> <5dwlfu2jyzkyf3nrlzxxblxctb6xio5es73ptgsahjnmfu5miu@772rc764hfhi> <4csodkvvfbfloxxjlkgsnl2lgfv2mtzdl7phqzd4jxjadxm4o5@usw7feyb5bzf> <61812.1770637345@localhost> <19720.1770709587@localhost> Comments: In-reply-to Andres Freund message dated "Tue, 10 Feb 2026 11:49:36 -0500." X-Mailer: MH-E 8.6+git; nmh 1.8; GNU Emacs 28.3 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Date: Thu, 12 Feb 2026 11:36:08 +0100 Message-ID: <196082.1770892568@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --=-=-= Content-Type: text/plain Andres Freund wrote: > For something committable, I think we should probably split IsMVCCSnapshot > into IsMVCCSnapshot(), just accepting SNAPSHOT_MVCC, and IsMVCCLikeSnapshot() > accepting both SNAPSHOT_MVCC and SNAPSHOT_HISTORIC_MVCC. And then go through > all the existing callers of IsMVCCSnapshot() - only about half should stay > as-is, I think. The attached patch tries to do that. -- Antonin Houska Web: https://www.cybertec-postgresql.com --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Refine-checking-of-snapshot-type.patch From dcdbaf3095e632a1f7f65f3abc43eccff0249d4c Mon Sep 17 00:00:00 2001 From: Antonin Houska Date: Thu, 12 Feb 2026 11:14:00 +0100 Subject: [PATCH] Refine checking of snapshot type. It appears to be confusing if IsMVCCSnapshot() evaluates to true for both "regular" and "historic" MVCC snapshot. This patch restricts the meaning of the macro to the "regular" MVCC snapshot, and introduces a new macro IsMVCCLikeSnapshot() to recognize both types. IsMVCCLikeSnapshot() is only used in functions that can (supposedly) be called during logical decoding. --- src/backend/access/heap/heapam_handler.c | 2 +- src/backend/access/index/indexam.c | 2 +- src/backend/access/nbtree/nbtree.c | 2 +- src/include/utils/snapmgr.h | 6 ++++-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c index cbef73e5d4b..332c788bab2 100644 --- a/src/backend/access/heap/heapam_handler.c +++ b/src/backend/access/heap/heapam_handler.c @@ -159,7 +159,7 @@ heapam_index_fetch_tuple(struct IndexFetchTableData *scan, * Only in a non-MVCC snapshot can more than one member of the HOT * chain be visible. */ - *call_again = !IsMVCCSnapshot(snapshot); + *call_again = !IsMVCCLikeSnapshot(snapshot); slot->tts_tableOid = RelationGetRelid(scan->rel); ExecStoreBufferHeapTuple(&bslot->base.tupdata, slot, hscan->xs_cbuf); diff --git a/src/backend/access/index/indexam.c b/src/backend/access/index/indexam.c index 4ed0508c605..80623350d6f 100644 --- a/src/backend/access/index/indexam.c +++ b/src/backend/access/index/indexam.c @@ -445,7 +445,7 @@ index_markpos(IndexScanDesc scan) void index_restrpos(IndexScanDesc scan) { - Assert(IsMVCCSnapshot(scan->xs_snapshot)); + Assert(IsMVCCLikeSnapshot(scan->xs_snapshot)); SCAN_CHECKS; CHECK_SCAN_PROCEDURE(amrestrpos); diff --git a/src/backend/access/nbtree/nbtree.c b/src/backend/access/nbtree/nbtree.c index 3dec1ee657d..07ba5997fbc 100644 --- a/src/backend/access/nbtree/nbtree.c +++ b/src/backend/access/nbtree/nbtree.c @@ -422,7 +422,7 @@ btrescan(IndexScanDesc scan, ScanKey scankey, int nscankeys, * Note: so->dropPin should never change across rescans. */ so->dropPin = (!scan->xs_want_itup && - IsMVCCSnapshot(scan->xs_snapshot) && + IsMVCCLikeSnapshot(scan->xs_snapshot) && RelationNeedsWAL(scan->indexRelation) && scan->heapRelation != NULL); diff --git a/src/include/utils/snapmgr.h b/src/include/utils/snapmgr.h index b8c01a291a1..dd5aaae6953 100644 --- a/src/include/utils/snapmgr.h +++ b/src/include/utils/snapmgr.h @@ -53,12 +53,14 @@ extern PGDLLIMPORT SnapshotData SnapshotToastData; /* This macro encodes the knowledge of which snapshots are MVCC-safe */ #define IsMVCCSnapshot(snapshot) \ - ((snapshot)->snapshot_type == SNAPSHOT_MVCC || \ - (snapshot)->snapshot_type == SNAPSHOT_HISTORIC_MVCC) + ((snapshot)->snapshot_type == SNAPSHOT_MVCC) #define IsHistoricMVCCSnapshot(snapshot) \ ((snapshot)->snapshot_type == SNAPSHOT_HISTORIC_MVCC) +#define IsMVCCLikeSnapshot(snapshot) \ + (IsMVCCSnapshot(snapshot) || IsHistoricMVCCSnapshot(snapshot)) + extern Snapshot GetTransactionSnapshot(void); extern Snapshot GetLatestSnapshot(void); extern void SnapshotSetCommandId(CommandId curcid); -- 2.47.3 --=-=-=--