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

Commit c73669c

Browse files
committed
Fix WAL-logging of B-tree "unlink halfdead page" operation.
There was some confusion on how to record the case that the operation unlinks the last non-leaf page in the branch being deleted. _bt_unlink_halfdead_page set the "topdead" field in the WAL record to the leaf page, but the redo routine assumed that it would be an invalid block number in that case. This commit fixes _bt_unlink_halfdead_page to do what the redo routine expected. This code is new in 9.4, so backpatch there.
1 parent 0f9692b commit c73669c

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/backend/access/nbtree/nbtpage.c

+6-7
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,6 @@ _bt_unlink_halfdead_page(Relation rel, Buffer leafbuf, bool *rightsib_empty)
15671567
int targetlevel;
15681568
ItemPointer leafhikey;
15691569
BlockNumber nextchild;
1570-
BlockNumber topblkno;
15711570

15721571
page = BufferGetPage(leafbuf);
15731572
opaque = (BTPageOpaque) PageGetSpecialPointer(page);
@@ -1591,11 +1590,10 @@ _bt_unlink_halfdead_page(Relation rel, Buffer leafbuf, bool *rightsib_empty)
15911590
*/
15921591
if (ItemPointerIsValid(leafhikey))
15931592
{
1594-
topblkno = ItemPointerGetBlockNumber(leafhikey);
1595-
target = topblkno;
1593+
target = ItemPointerGetBlockNumber(leafhikey);
15961594

15971595
/* fetch the block number of the topmost parent's left sibling */
1598-
buf = _bt_getbuf(rel, topblkno, BT_READ);
1596+
buf = _bt_getbuf(rel, target, BT_READ);
15991597
page = BufferGetPage(buf);
16001598
opaque = (BTPageOpaque) PageGetSpecialPointer(page);
16011599
leftsib = opaque->btpo_prev;
@@ -1609,7 +1607,6 @@ _bt_unlink_halfdead_page(Relation rel, Buffer leafbuf, bool *rightsib_empty)
16091607
}
16101608
else
16111609
{
1612-
topblkno = InvalidBlockNumber;
16131610
target = leafblkno;
16141611

16151612
buf = leafbuf;
@@ -1694,9 +1691,11 @@ _bt_unlink_halfdead_page(Relation rel, Buffer leafbuf, bool *rightsib_empty)
16941691
elog(ERROR, "half-dead page changed status unexpectedly in block %u of index \"%s\"",
16951692
target, RelationGetRelationName(rel));
16961693

1697-
/* remember the next child down in the branch. */
1694+
/* remember the next non-leaf child down in the branch. */
16981695
itemid = PageGetItemId(page, P_FIRSTDATAKEY(opaque));
16991696
nextchild = ItemPointerGetBlockNumber(&((IndexTuple) PageGetItem(page, itemid))->t_tid);
1697+
if (nextchild == leafblkno)
1698+
nextchild = InvalidBlockNumber;
17001699
}
17011700

17021701
/*
@@ -1782,7 +1781,7 @@ _bt_unlink_halfdead_page(Relation rel, Buffer leafbuf, bool *rightsib_empty)
17821781
*/
17831782
if (target != leafblkno)
17841783
{
1785-
if (nextchild == leafblkno)
1784+
if (nextchild == InvalidBlockNumber)
17861785
ItemPointerSetInvalid(leafhikey);
17871786
else
17881787
ItemPointerSet(leafhikey, nextchild, P_HIKEY);

0 commit comments

Comments
 (0)