From 9e3903fd2497c967aa001010b20167363963017a Mon Sep 17 00:00:00 2001
From: Pavel Borisov <pashkin.elfe@gmail.com>
Date: Mon, 13 May 2024 15:19:16 +0400
Subject: [PATCH] amcheck: Get lowkey only for internal pages of btree index

state->lowkey is used only for checking child pages in btree index inside
bt_child_check()/bt_child_highkey_check() All calls of these functions
possible only from internal pages level. So there is no reason of getting
page lowkey for leaf pages just to invalidate it next without actual usage.
---
 contrib/amcheck/verify_nbtree.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/contrib/amcheck/verify_nbtree.c b/contrib/amcheck/verify_nbtree.c
index 70f65b645a..8e18a19deb 100644
--- a/contrib/amcheck/verify_nbtree.c
+++ b/contrib/amcheck/verify_nbtree.c
@@ -938,13 +938,13 @@ nextpage:
 		 * falls to the boundary of pages on the target level.  See
 		 * bt_child_highkey_check() for details.  So, typically we won't end
 		 * up doing anything with low key, but it's simpler for general case
-		 * high key verification to always have it available.
+		 * high key verification to have it available for all non-leaf pages.
 		 *
 		 * The correctness of managing low key in the case of concurrent
 		 * splits wasn't investigated yet.  Thankfully we only need low key
 		 * for readonly verification and concurrent splits won't happen.
 		 */
-		if (state->readonly && !P_RIGHTMOST(opaque))
+		if (state->readonly && !P_RIGHTMOST(opaque) && !P_ISLEAF(opaque))
 		{
 			IndexTuple	itup;
 			ItemId		itemid;
-- 
2.34.1

