Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 236d569

Browse files
committed
Fix btree mark/restore bug.
Commit 2ed5b87 introduced a bug in mark/restore, in an attempt to optimize repeated restores to the same page. This caused an assertion failure during a merge join which fed directly from an index scan, although the impact would not be limited to that case. Revert the bad chunk of code from that commit. While investigating this bug it was discovered that a particular "paranoia" set of the mark position field would not prevent bad behavior; it would just make it harder to diagnose. Change that into an assertion, which will draw attention to any future problem in that area more directly. Backpatch to 9.5, where the bug was introduced. Bug #14169 reported by Shinta Koyanagi. Preliminary analysis by Tom Lane identified which commit caused the bug.
1 parent 43d3fbe commit 236d569

File tree

2 files changed

+1
-20
lines changed

2 files changed

+1
-20
lines changed

src/backend/access/nbtree/nbtree.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -592,25 +592,6 @@ btrestrpos(PG_FUNCTION_ARGS)
592592
*/
593593
so->currPos.itemIndex = so->markItemIndex;
594594
}
595-
else if (so->currPos.currPage == so->markPos.currPage)
596-
{
597-
/*
598-
* so->markItemIndex < 0 but mark and current positions are on the
599-
* same page. This would be an unusual case, where the scan moved to
600-
* a new index page after the mark, restored, and later restored again
601-
* without moving off the marked page. It is not clear that this code
602-
* can currently be reached, but it seems better to make this function
603-
* robust for this case than to Assert() or elog() that it can't
604-
* happen.
605-
*
606-
* We neither want to set so->markItemIndex >= 0 (because that could
607-
* cause a later move to a new page to redo the memcpy() executions)
608-
* nor re-execute the memcpy() functions for a restore within the same
609-
* page. The previous restore to this page already set everything
610-
* except markPos as it should be.
611-
*/
612-
so->currPos.itemIndex = so->markPos.itemIndex;
613-
}
614595
else
615596
{
616597
/*

src/backend/access/nbtree/nbtsearch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
10001000
so->currPos.moreRight = false;
10011001
}
10021002
so->numKilled = 0; /* just paranoia */
1003-
so->markItemIndex = -1; /* ditto */
1003+
Assert(so->markItemIndex == -1);
10041004

10051005
/* position to the precise item on the page */
10061006
offnum = _bt_binsrch(rel, buf, keysCount, scankeys, nextkey);

0 commit comments

Comments
 (0)