Commit 139858e6 authored by Vadim B. Mikheev's avatar Vadim B. Mikheev

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.
parent 5cf55737
...@@ -7,7 +7,7 @@ ...@@ -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,31 +287,22 @@ _bt_insertonpg(Relation rel, ...@@ -287,31 +287,22 @@ _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;
bool keys_equal = false;
for ( ; ; ) rbuf = _bt_getbuf(rel, lpageop->btpo_next, BT_WRITE);
{ rpage = BufferGetPage(rbuf);
bool keys_equal = false; rpageop = (BTPageOpaque) PageGetSpecialPointer(rpage);
if ( !P_RIGHTMOST (rpageop) ) /* non-rightmost page */
rbuf = _bt_getbuf(rel, lpageop->btpo_next, BT_WRITE); { /*
rpage = BufferGetPage(rbuf);
rpageop = (BTPageOpaque) PageGetSpecialPointer(rpage);
if ( P_RIGHTMOST (rpageop) )
{
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),
BTEqualStrategyNumber) ) BTEqualStrategyNumber) )
...@@ -321,12 +312,12 @@ _bt_insertonpg(Relation rel, ...@@ -321,12 +312,12 @@ _bt_insertonpg(Relation rel,
keys_equal = true; keys_equal = true;
} }
else if ( _bt_skeycmp (rel, keysz, scankey, rpage, else if ( _bt_skeycmp (rel, keysz, scankey, rpage,
PageGetItemId(rpage, P_HIKEY), PageGetItemId(rpage, P_HIKEY),
BTGreaterStrategyNumber) ) BTGreaterStrategyNumber) )
elog (FATAL, "btree: hikey is out of order"); elog (FATAL, "btree: hikey is out of order");
/* /*
* If hikey > scankey and BTP_CHAIN is ON * If hikey > scankey and BTP_CHAIN is ON
* then it's first page of the chain of higher keys: * then it's first page of the chain of higher keys:
* our left sibling hikey was lying! We can't add new * our left sibling hikey was lying! We can't add new
* item here, but we can turn BTP_CHAIN off on our * item here, but we can turn BTP_CHAIN off on our
* left page and overwrite its hikey. * left page and overwrite its hikey.
...@@ -336,26 +327,19 @@ _bt_insertonpg(Relation rel, ...@@ -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) use_left = false;
* we have to use this page . }
*/ else /* rightmost page */
if ( PageGetFreeSpace (rpage) > itemsz || !keys_equal ) {
{ Assert ( !( rpageop->btpo_flags & BTP_CHAIN ) );
/* if there is room here then we use this page. */
if ( PageGetFreeSpace (rpage) > itemsz )
use_left = false; use_left = false;
break;
}
/* try to move righter */
_bt_relbuf(rel, buf, BT_WRITE);
buf = rbuf;
page = rpage;
lpageop = rpageop;
} }
if ( !use_left ) /* insert on the right page */ if ( !use_left ) /* insert on the right page */
{ {
...@@ -364,7 +348,6 @@ _bt_insertonpg(Relation rel, ...@@ -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 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment