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

Commit 4e064c0

Browse files
committed
_bt_updateitem is returned in code, but works only if sizes of keys
are equal.
1 parent c3e10a4 commit 4e064c0

File tree

1 file changed

+76
-50
lines changed

1 file changed

+76
-50
lines changed

src/backend/access/nbtree/nbtinsert.c

+76-50
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.7 1996/11/13 20:47:11 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.8 1996/12/06 09:45:30 vadim Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -31,10 +31,7 @@ static OffsetNumber _bt_findsplitloc(Relation rel, Page page, OffsetNumber start
3131
static void _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf);
3232
static OffsetNumber _bt_pgaddtup(Relation rel, Buffer buf, int keysz, ScanKey itup_scankey, Size itemsize, BTItem btitem, BTItem afteritem);
3333
static bool _bt_goesonpg(Relation rel, Buffer buf, Size keysz, ScanKey scankey, BTItem afteritem);
34-
35-
#if 0
3634
static void _bt_updateitem(Relation rel, Size keysz, Buffer buf, Oid bti_oid, BTItem newItem);
37-
#endif
3835

3936
/*
4037
* _bt_doinsert() -- Handle insertion of a single btitem in the tree.
@@ -265,6 +262,8 @@ _bt_insertonpg(Relation rel,
265262

266263
if (_bt_itemcmp(rel, keysz, stack->bts_btitem, new_item,
267264
BTGreaterStrategyNumber)) {
265+
ppageop = (BTPageOpaque) PageGetSpecialPointer(page);
266+
Assert (P_LEFTMOST(ppageop));
268267
lowLeftItem =
269268
(BTItem) PageGetItem(page,
270269
PageGetItemId(page, P_FIRSTKEY));
@@ -278,56 +277,80 @@ _bt_insertonpg(Relation rel,
278277
/* because it's bigger than what was there before). */
279278
/* --djm 8/21/96 */
280279

281-
/* _bt_updateitem(rel, keysz, pbuf, stack->bts_btitem->bti_oid,
282-
lowLeftItem); */
283-
284-
/* get the parent page */
285-
ppage = BufferGetPage(pbuf);
286-
ppageop = (BTPageOpaque) PageGetSpecialPointer(ppage);
280+
/*
281+
* but it works for items with the same size and so why don't
282+
* use it for them ? - vadim 12/05/96
283+
*/
284+
if ( DOUBLEALIGN (IndexTupleDSize (lowLeftItem->bti_itup)) ==
285+
DOUBLEALIGN (IndexTupleDSize (stack->bts_btitem->bti_itup)) )
286+
{
287+
_bt_updateitem(rel, keysz, pbuf,
288+
stack->bts_btitem->bti_oid, lowLeftItem);
289+
_bt_relbuf(rel, buf, BT_WRITE);
290+
_bt_relbuf(rel, rbuf, BT_WRITE);
291+
}
292+
else
293+
{
294+
/* get the parent page */
295+
ppage = BufferGetPage(pbuf);
296+
ppageop = (BTPageOpaque) PageGetSpecialPointer(ppage);
287297

288-
/* figure out which key is leftmost (if the parent page */
289-
/* is rightmost, too, it must be the root) */
290-
if(P_RIGHTMOST(ppageop)) {
291-
leftmost_offset = P_HIKEY;
292-
} else {
293-
leftmost_offset = P_FIRSTKEY;
294-
}
295-
PageIndexTupleDelete(ppage, leftmost_offset);
298+
/*
299+
* figure out which key is leftmost (if the parent page
300+
* is rightmost, too, it must be the root)
301+
*/
302+
if(P_RIGHTMOST(ppageop)) {
303+
leftmost_offset = P_HIKEY;
304+
} else {
305+
leftmost_offset = P_FIRSTKEY;
306+
}
307+
PageIndexTupleDelete(ppage, leftmost_offset);
296308

297-
/* don't write anything out yet--we still have the write */
298-
/* lock, and now we call another _bt_insertonpg to */
299-
/* insert the correct leftmost key */
309+
/*
310+
* don't write anything out yet--we still have the write
311+
* lock, and now we call another _bt_insertonpg to
312+
* insert the correct leftmost key
313+
*/
300314

301-
/* make a new leftmost item, using the tuple data from */
302-
/* lowLeftItem. point it to the left child. */
303-
/* update it on the stack at the same time. */
304-
bknum = BufferGetBlockNumber(buf);
305-
pfree(stack->bts_btitem);
306-
stack->bts_btitem = _bt_formitem(&(lowLeftItem->bti_itup));
307-
ItemPointerSet(&(stack->bts_btitem->bti_itup.t_tid),
315+
/*
316+
* make a new leftmost item, using the tuple data from
317+
* lowLeftItem. point it to the left child.
318+
* update it on the stack at the same time.
319+
*/
320+
bknum = BufferGetBlockNumber(buf);
321+
pfree(stack->bts_btitem);
322+
stack->bts_btitem = _bt_formitem(&(lowLeftItem->bti_itup));
323+
ItemPointerSet(&(stack->bts_btitem->bti_itup.t_tid),
308324
bknum, P_HIKEY);
309325

310-
/* unlock the children before doing this */
311-
_bt_relbuf(rel, buf, BT_WRITE);
312-
_bt_relbuf(rel, rbuf, BT_WRITE);
326+
/* unlock the children before doing this */
327+
_bt_relbuf(rel, buf, BT_WRITE);
328+
_bt_relbuf(rel, rbuf, BT_WRITE);
313329

314-
/* a regular _bt_binsrch should find the right place to */
315-
/* put the new entry, since it should be lower than any */
316-
/* other key on the page, therefore set afteritem to NULL */
317-
newskey = _bt_mkscankey(rel, &(stack->bts_btitem->bti_itup));
318-
newres = _bt_insertonpg(rel, pbuf, stack->bts_parent,
330+
/*
331+
* a regular _bt_binsrch should find the right place to
332+
* put the new entry, since it should be lower than any
333+
* other key on the page, therefore set afteritem to NULL
334+
*/
335+
newskey = _bt_mkscankey(rel, &(stack->bts_btitem->bti_itup));
336+
newres = _bt_insertonpg(rel, pbuf, stack->bts_parent,
319337
keysz, newskey, stack->bts_btitem,
320338
NULL);
321339

322-
pfree(newres);
323-
pfree(newskey);
340+
pfree(newres);
341+
pfree(newskey);
324342

325-
/* we have now lost our lock on the parent buffer, and */
326-
/* need to get it back. */
327-
pbuf = _bt_getstackbuf(rel, stack, BT_WRITE);
328-
} else {
329-
_bt_relbuf(rel, buf, BT_WRITE);
330-
_bt_relbuf(rel, rbuf, BT_WRITE);
343+
/*
344+
* we have now lost our lock on the parent buffer, and
345+
* need to get it back.
346+
*/
347+
pbuf = _bt_getstackbuf(rel, stack, BT_WRITE);
348+
}
349+
}
350+
else
351+
{
352+
_bt_relbuf(rel, buf, BT_WRITE);
353+
_bt_relbuf(rel, rbuf, BT_WRITE);
331354
}
332355

333356
newskey = _bt_mkscankey(rel, &(new_item->bti_itup));
@@ -872,8 +895,6 @@ _bt_itemcmp(Relation rel,
872895
return (true);
873896
}
874897

875-
#if 0
876-
/* gone since updating in place doesn't work in general --djm 11/13/96 */
877898
/*
878899
* _bt_updateitem() -- updates the key of the item identified by the
879900
* oid with the key of newItem (done in place if
@@ -912,18 +933,23 @@ _bt_updateitem(Relation rel,
912933
elog(FATAL, "_bt_getstackbuf was lying!!");
913934
}
914935

936+
/*
937+
* It's defined by caller (_bt_insertonpg)
938+
*/
939+
/*
915940
if(IndexTupleDSize(newItem->bti_itup) >
916941
IndexTupleDSize(item->bti_itup)) {
917942
elog(NOTICE, "trying to overwrite a smaller value with a bigger one in _bt_updateitem");
918943
elog(WARN, "this is not good.");
919944
}
945+
*/
920946

921947
oldIndexTuple = &(item->bti_itup);
922948
newIndexTuple = &(newItem->bti_itup);
923949

924950
/* keep the original item pointer */
925-
ItemPointerCopy(&(oldIndexTuple->t_tid), &itemPtrData);
926-
CopyIndexTuple(newIndexTuple, &oldIndexTuple);
927-
ItemPointerCopy(&itemPtrData, &(oldIndexTuple->t_tid));
951+
ItemPointerCopy(&(oldIndexTuple->t_tid), &itemPtrData);
952+
CopyIndexTuple(newIndexTuple, &oldIndexTuple);
953+
ItemPointerCopy(&itemPtrData, &(oldIndexTuple->t_tid));
954+
928955
}
929-
#endif

0 commit comments

Comments
 (0)