From e184253695e8187c8faed70df04fa2447dfa7793 Mon Sep 17 00:00:00 2001
From: Jakub Wartak <jakub.wartak@enterprisedb.com>
Date: Mon, 16 Nov 2026 12:04:13 +0100
Subject: [PATCH v16112026 7/7] verify_heapam: make beyond-EOF TID check heapAM
 only

---
 contrib/amcheck/verify_nbtree.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/contrib/amcheck/verify_nbtree.c b/contrib/amcheck/verify_nbtree.c
index 91c24f121df..da9b926afad 100644
--- a/contrib/amcheck/verify_nbtree.c
+++ b/contrib/amcheck/verify_nbtree.c
@@ -441,12 +441,13 @@ bt_check_every_level(Relation rel, Relation heaprel, bool heapkeyspace,
 
 	/*
 	 * Remember the current size of the heap for beyond-EOF TID checks.  When
-	 * the main fork is missing entirely, skip those checks (by making any
-	 * comparison against heapnblocks false): the user may have deliberately
-	 * excluded the corrupt table from table-level verification, which is what
-	 * reports a missing main fork.
+	 * the main fork is not heapAM or the main fork is missing entirely, skip
+	 * those checks (by making any comparison against heapnblocks false): the
+	 * user may have deliberately excluded the corrupt table from table-level
+	 * verification, which is what reports a missing main fork.
 	 */
-	if (smgrexists(RelationGetSmgr(state->heaprel), MAIN_FORKNUM))
+	if (state->heaprel->rd_rel->relam == HEAP_TABLE_AM_OID &&
+		smgrexists(RelationGetSmgr(state->heaprel), MAIN_FORKNUM))
 		state->heapnblocks = RelationGetNumberOfBlocks(state->heaprel);
 	else
 		state->heapnblocks = InvalidBlockNumber;
-- 
2.43.0

