From a493dabdce0faea127c049b2a4cc58be0e934e04 Mon Sep 17 00:00:00 2001
From: yyuansong <yyuansong@126.com>
Date: Sun, 1 Dec 2024 21:38:35 +0800
Subject: [PATCH] Fix the error in the B-tree binary search for the post list.

The _bt_binsrch_insert function always returns low, but during the post list search, there may be cases where the values of low and mid are not equal. Additionally, modify the code to terminate the search early once a matching post list value is found.

Discussion: https://www.postgresql.org/message-id/flat/bdc9e08.a2c5.1934f3f42d0.Coremail.yyuansong%40126.com
Signed-off-by: yyuansong <yyuansong@126.com>
---
 src/backend/access/nbtree/nbtsearch.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/backend/access/nbtree/nbtsearch.c b/src/backend/access/nbtree/nbtsearch.c
index 2551df8a67..ae9c25e6c2 100644
--- a/src/backend/access/nbtree/nbtsearch.c
+++ b/src/backend/access/nbtree/nbtsearch.c
@@ -567,6 +567,8 @@ _bt_binsrch_insert(Relation rel, BTInsertState insertstate)
 										 RelationGetRelationName(rel))));
 
 			insertstate->postingoff = _bt_binsrch_posting(key, page, mid);
+			low = mid;
+			break;
 		}
 	}
 
-- 
2.46.0.windows.1

