If we have to split leaf page in the chain of duplicates

then we try to look at our right sibling first, but not farther,
as it was in yesterday fix.
This commit is contained in:
Vadim B. Mikheev 1997-05-31 06:35:56 +00:00
parent 5cf55737a4
commit 139858e699

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.13 1997/05/30 18:35:31 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.14 1997/05/31 06:35:56 vadim Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -287,30 +287,21 @@ _bt_insertonpg(Relation rel,
/* /*
* If we have to split leaf page in the chain of duplicates * If we have to split leaf page in the chain of duplicates
* then we try to move righter to avoid splitting. * then we try to look at our right sibling first.
*/ */
if ( ( lpageop->btpo_flags & BTP_CHAIN ) && if ( ( lpageop->btpo_flags & BTP_CHAIN ) &&
( lpageop->btpo_flags & BTP_LEAF ) ) ( lpageop->btpo_flags & BTP_LEAF ) )
{ {
bool use_left = true; bool use_left = true;
for ( ; ; )
{
bool keys_equal = false; bool keys_equal = false;
rbuf = _bt_getbuf(rel, lpageop->btpo_next, BT_WRITE); rbuf = _bt_getbuf(rel, lpageop->btpo_next, BT_WRITE);
rpage = BufferGetPage(rbuf); rpage = BufferGetPage(rbuf);
rpageop = (BTPageOpaque) PageGetSpecialPointer(rpage); rpageop = (BTPageOpaque) PageGetSpecialPointer(rpage);
if ( P_RIGHTMOST (rpageop) ) if ( !P_RIGHTMOST (rpageop) ) /* non-rightmost page */
{ { /*
Assert ( !( rpageop->btpo_flags & BTP_CHAIN ) );
use_left = false;
break;
}
/*
* If we have the same hikey here then it's * If we have the same hikey here then it's
* yet another page in chain and we may move * yet another page in chain.
* even righter.
*/ */
if ( _bt_skeycmp (rel, keysz, scankey, rpage, if ( _bt_skeycmp (rel, keysz, scankey, rpage,
PageGetItemId(rpage, P_HIKEY), PageGetItemId(rpage, P_HIKEY),
@ -336,26 +327,19 @@ _bt_insertonpg(Relation rel,
BTItem tmp; BTItem tmp;
lpageop->btpo_flags &= ~BTP_CHAIN; lpageop->btpo_flags &= ~BTP_CHAIN;
tmp = (BTItem) PageGetItem(rpage, tmp = (BTItem) PageGetItem(rpage, PageGetItemId(rpage, P_HIKEY));
PageGetItemId(rpage, P_HIKEY));
hiRightItem = _bt_formitem(&(tmp->bti_itup)); hiRightItem = _bt_formitem(&(tmp->bti_itup));
break;
} }
/* /* if there is room here then we use this page. */
* if there is room here or hikey > scankey (so it's our else if ( PageGetFreeSpace (rpage) > itemsz )
* last page in the chain and we can't move righter)
* we have to use this page .
*/
if ( PageGetFreeSpace (rpage) > itemsz || !keys_equal )
{
use_left = false; use_left = false;
break;
} }
/* try to move righter */ else /* rightmost page */
_bt_relbuf(rel, buf, BT_WRITE); {
buf = rbuf; Assert ( !( rpageop->btpo_flags & BTP_CHAIN ) );
page = rpage; /* if there is room here then we use this page. */
lpageop = rpageop; if ( PageGetFreeSpace (rpage) > itemsz )
use_left = false;
} }
if ( !use_left ) /* insert on the right page */ if ( !use_left ) /* insert on the right page */
{ {
@ -364,7 +348,6 @@ _bt_insertonpg(Relation rel,
scankey, btitem, afteritem) ); scankey, btitem, afteritem) );
} }
_bt_relbuf(rel, rbuf, BT_WRITE); _bt_relbuf(rel, rbuf, BT_WRITE);
bknum = BufferGetBlockNumber(buf);
} }
/* split the buffer into left and right halves */ /* split the buffer into left and right halves */