mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-01-12 18:34:36 +08:00
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:
parent
5cf55737a4
commit
139858e699
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* 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
|
||||
* 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 ) &&
|
||||
( lpageop->btpo_flags & BTP_LEAF ) )
|
||||
{
|
||||
bool use_left = true;
|
||||
|
||||
for ( ; ; )
|
||||
{
|
||||
bool keys_equal = false;
|
||||
|
||||
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 ( !P_RIGHTMOST (rpageop) ) /* non-rightmost page */
|
||||
{ /*
|
||||
* If we have the same hikey here then it's
|
||||
* yet another page in chain and we may move
|
||||
* even righter.
|
||||
* yet another page in chain.
|
||||
*/
|
||||
if ( _bt_skeycmp (rel, keysz, scankey, rpage,
|
||||
PageGetItemId(rpage, P_HIKEY),
|
||||
@ -336,26 +327,19 @@ _bt_insertonpg(Relation rel,
|
||||
BTItem tmp;
|
||||
|
||||
lpageop->btpo_flags &= ~BTP_CHAIN;
|
||||
tmp = (BTItem) PageGetItem(rpage,
|
||||
PageGetItemId(rpage, P_HIKEY));
|
||||
tmp = (BTItem) PageGetItem(rpage, PageGetItemId(rpage, P_HIKEY));
|
||||
hiRightItem = _bt_formitem(&(tmp->bti_itup));
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* if there is room here or hikey > scankey (so it's our
|
||||
* last page in the chain and we can't move righter)
|
||||
* we have to use this page .
|
||||
*/
|
||||
if ( PageGetFreeSpace (rpage) > itemsz || !keys_equal )
|
||||
{
|
||||
/* if there is room here then we use this page. */
|
||||
else if ( PageGetFreeSpace (rpage) > itemsz )
|
||||
use_left = false;
|
||||
break;
|
||||
}
|
||||
/* try to move righter */
|
||||
_bt_relbuf(rel, buf, BT_WRITE);
|
||||
buf = rbuf;
|
||||
page = rpage;
|
||||
lpageop = rpageop;
|
||||
else /* rightmost page */
|
||||
{
|
||||
Assert ( !( rpageop->btpo_flags & BTP_CHAIN ) );
|
||||
/* if there is room here then we use this page. */
|
||||
if ( PageGetFreeSpace (rpage) > itemsz )
|
||||
use_left = false;
|
||||
}
|
||||
if ( !use_left ) /* insert on the right page */
|
||||
{
|
||||
@ -364,7 +348,6 @@ _bt_insertonpg(Relation rel,
|
||||
scankey, btitem, afteritem) );
|
||||
}
|
||||
_bt_relbuf(rel, rbuf, BT_WRITE);
|
||||
bknum = BufferGetBlockNumber(buf);
|
||||
}
|
||||
|
||||
/* split the buffer into left and right halves */
|
||||
|
Loading…
Reference in New Issue
Block a user