Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit67b0b2d

Browse files
Reconsider nbtree page deletion assertion.
Commit624686a added an assertion that verified that _bt_searchsuccessfully relocated the leaf page undergoing deletion. Page deletioncannot deal with the case where the descent stack is to the right of thepage, so this seemed critical (deletion can only handle the case wherethe descent stack is to the left of the leaf/target page). However, theassertion went a bit too far.Since only a buffer pin is held on the leaf page throughout the call to_bt_search, nothing guarantees that it can't have split during thissmall window. And if does actually split, _bt_search may end up"relocating" a page to the right of the original target leaf page. Thisscenario seems extremely unlikely, but it must still be considered.Remove the assertion, and document how we cope in this scenario.
1 parentc301c2e commit67b0b2d

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

‎src/backend/access/nbtree/nbtpage.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,15 +1599,22 @@ _bt_pagedel(Relation rel, Buffer leafbuf, TransactionId *oldestBtpoXact)
15991599
itup_key->pivotsearch= true;
16001600
stack=_bt_search(rel,itup_key,&sleafbuf,BT_READ,NULL);
16011601
/* won't need a second lock or pin on leafbuf */
1602-
Assert(leafblkno==BufferGetBlockNumber(sleafbuf)||
1603-
!itup_key->heapkeyspace);
16041602
_bt_relbuf(rel,sleafbuf);
16051603

16061604
/*
16071605
* Re-lock the leaf page, and start over to use our stack
16081606
* within _bt_mark_page_halfdead. We must do it that way
16091607
* because it's possible that leafbuf can no longer be
16101608
* deleted. We need to recheck.
1609+
*
1610+
* Note: We can't simply hold on to the sleafbuf lock instead,
1611+
* because it's barely possible that sleafbuf is not the same
1612+
* page as leafbuf. This happens when leafbuf split after our
1613+
* original lock was dropped, but before _bt_search finished
1614+
* its descent. We rely on the assumption that we'll find
1615+
* leafbuf isn't safe to delete anymore in this scenario.
1616+
* (Page deletion can cope with the stack being to the left of
1617+
* leafbuf, but not to the right of leafbuf.)
16111618
*/
16121619
LockBuffer(leafbuf,BT_WRITE);
16131620
continue;
@@ -1735,9 +1742,8 @@ _bt_mark_page_halfdead(Relation rel, Buffer leafbuf, BTStack stack)
17351742
* Before attempting to lock the parent page, check that the right sibling
17361743
* is not in half-dead state. A half-dead right sibling would have no
17371744
* downlink in the parent, which would be highly confusing later when we
1738-
* delete the downlink that follows the leafbuf page's downlink. It would
1739-
* fail the "right sibling of target page is also the next child in parent
1740-
* page" cross-check below.
1745+
* delete the downlink. It would fail the "right sibling of target page
1746+
* is also the next child in parent page" cross-check below.
17411747
*/
17421748
if (_bt_rightsib_halfdeadflag(rel,leafrightsib))
17431749
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp