From 99a71e9543ba2cae0bf91403f78c57671a6aebf8 Mon Sep 17 00:00:00 2001
From: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date: Sat, 23 Sep 2023 20:50:38 +0300
Subject: [PATCH 3/5] Also clear 'downlinkoffnum' when the parent block is
 changed.

While looking at bug #18129, I noticed this spot where we update the
parent block in the stack, but we don't clear the
'downlinkoffnum'. This case wasn't hit by the test case, but it could
lead to similar bugs.
---
 src/backend/access/gist/gist.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/backend/access/gist/gist.c b/src/backend/access/gist/gist.c
index d4469eb7cc4..b3749bbb432 100644
--- a/src/backend/access/gist/gist.c
+++ b/src/backend/access/gist/gist.c
@@ -1068,6 +1068,7 @@ gistFindCorrectParent(Relation r, GISTInsertStack *child)
 			}
 
 			parent->blkno = GistPageGetOpaque(parent->page)->rightlink;
+			parent->downlinkoffnum = InvalidOffsetNumber;
 			UnlockReleaseBuffer(parent->buffer);
 			if (parent->blkno == InvalidBlockNumber)
 			{
-- 
2.39.2

