agora inbox for [email protected]  
help / color / mirror / Atom feed
From: Kyotaro Horiguchi <[email protected]>
Subject: [PATCH 2/2] crude fix
Date: Thu, 6 Feb 2020 19:09:09 +0900

---
 src/backend/access/nbtree/nbtsearch.c | 43 +++++++++++++++++----------
 1 file changed, 27 insertions(+), 16 deletions(-)

diff --git a/src/backend/access/nbtree/nbtsearch.c b/src/backend/access/nbtree/nbtsearch.c
index 5cd97d8bb5..1f18b38ca5 100644
--- a/src/backend/access/nbtree/nbtsearch.c
+++ b/src/backend/access/nbtree/nbtsearch.c
@@ -1619,6 +1619,9 @@ _bt_skip(IndexScanDesc scan, ScanDirection dir,
 
 			nextOffset = startOffset = ItemPointerGetOffsetNumber(&scan->xs_itup->t_tid);
 
+			if (nextOffset != startOffset)
+				LockBuffer(so->currPos.buf, BUFFER_LOCK_UNLOCK);
+
 			while (nextOffset == startOffset)
 			{
 				IndexTuple itup;
@@ -1653,7 +1656,7 @@ _bt_skip(IndexScanDesc scan, ScanDirection dir,
 				offnum = OffsetNumberPrev(offnum);
 
 				/* Check if _bt_readpage returns already found item */
-				if (!_bt_readpage(scan, indexdir, offnum))
+				if (!_bt_readpage(scan, dir, offnum))
 				{
 					/*
 					 * There's no actually-matching data on this page.  Try to
@@ -1668,6 +1671,8 @@ _bt_skip(IndexScanDesc scan, ScanDirection dir,
 						return false;
 					}
 				}
+				else
+					LockBuffer(so->currPos.buf, BUFFER_LOCK_UNLOCK);
 
 				currItem = &so->currPos.items[so->currPos.lastItem];
 				itup = (IndexTuple) (so->currTuples + currItem->tupleOffset);
@@ -1721,24 +1726,30 @@ _bt_skip(IndexScanDesc scan, ScanDirection dir,
 	}
 
 	/* Now read the data */
-	if (!_bt_readpage(scan, indexdir, offnum))
+	if (!(ScanDirectionIsForward(dir) &&
+		  ScanDirectionIsBackward(indexdir)) ||
+		scanstart)
 	{
-		/*
-		 * There's no actually-matching data on this page.  Try to advance to
-		 * the next page.  Return false if there's no matching data at all.
-		 */
-		LockBuffer(so->currPos.buf, BUFFER_LOCK_UNLOCK);
-		if (!_bt_steppage(scan, dir))
+		if (!_bt_readpage(scan, dir, offnum))
 		{
-			pfree(so->skipScanKey);
-			so->skipScanKey = NULL;
-			return false;
+			/*
+			 * There's no actually-matching data on this page.  Try to advance
+			 * to the next page.  Return false if there's no matching data at
+			 * all.
+			 */
+			LockBuffer(so->currPos.buf, BUFFER_LOCK_UNLOCK);
+			if (!_bt_steppage(scan, dir))
+			{
+				pfree(so->skipScanKey);
+				so->skipScanKey = NULL;
+				return false;
+			}
+		}
+		else
+		{
+			/* Drop the lock, and maybe the pin, on the current page */
+			LockBuffer(so->currPos.buf, BUFFER_LOCK_UNLOCK);
 		}
-	}
-	else
-	{
-		/* Drop the lock, and maybe the pin, on the current page */
-		LockBuffer(so->currPos.buf, BUFFER_LOCK_UNLOCK);
 	}
 
 	/* And set IndexTuple */
-- 
2.18.2


----Next_Part(Fri_Feb_14_17_23_13_2020_052)----





view thread (2+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: [PATCH 2/2] crude fix
  In-Reply-To: <no-message-id-188433@localhost>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox