7
7
*
8
8
*
9
9
* 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 $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -31,10 +31,7 @@ static OffsetNumber _bt_findsplitloc(Relation rel, Page page, OffsetNumber start
31
31
static void _bt_newroot (Relation rel , Buffer lbuf , Buffer rbuf );
32
32
static OffsetNumber _bt_pgaddtup (Relation rel , Buffer buf , int keysz , ScanKey itup_scankey , Size itemsize , BTItem btitem , BTItem afteritem );
33
33
static bool _bt_goesonpg (Relation rel , Buffer buf , Size keysz , ScanKey scankey , BTItem afteritem );
34
-
35
- #if 0
36
34
static void _bt_updateitem (Relation rel , Size keysz , Buffer buf , Oid bti_oid , BTItem newItem );
37
- #endif
38
35
39
36
/*
40
37
* _bt_doinsert() -- Handle insertion of a single btitem in the tree.
@@ -265,6 +262,8 @@ _bt_insertonpg(Relation rel,
265
262
266
263
if (_bt_itemcmp (rel , keysz , stack -> bts_btitem , new_item ,
267
264
BTGreaterStrategyNumber )) {
265
+ ppageop = (BTPageOpaque ) PageGetSpecialPointer (page );
266
+ Assert (P_LEFTMOST (ppageop ));
268
267
lowLeftItem =
269
268
(BTItem ) PageGetItem (page ,
270
269
PageGetItemId (page , P_FIRSTKEY ));
@@ -278,56 +277,80 @@ _bt_insertonpg(Relation rel,
278
277
/* because it's bigger than what was there before). */
279
278
/* --djm 8/21/96 */
280
279
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 );
287
297
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 );
296
308
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
+ */
300
314
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 ),
308
324
bknum , P_HIKEY );
309
325
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 );
313
329
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 ,
319
337
keysz , newskey , stack -> bts_btitem ,
320
338
NULL );
321
339
322
- pfree (newres );
323
- pfree (newskey );
340
+ pfree (newres );
341
+ pfree (newskey );
324
342
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 );
331
354
}
332
355
333
356
newskey = _bt_mkscankey (rel , & (new_item -> bti_itup ));
@@ -872,8 +895,6 @@ _bt_itemcmp(Relation rel,
872
895
return (true);
873
896
}
874
897
875
- #if 0
876
- /* gone since updating in place doesn't work in general --djm 11/13/96 */
877
898
/*
878
899
* _bt_updateitem() -- updates the key of the item identified by the
879
900
* oid with the key of newItem (done in place if
@@ -912,18 +933,23 @@ _bt_updateitem(Relation rel,
912
933
elog (FATAL , "_bt_getstackbuf was lying!!" );
913
934
}
914
935
936
+ /*
937
+ * It's defined by caller (_bt_insertonpg)
938
+ */
939
+ /*
915
940
if(IndexTupleDSize(newItem->bti_itup) >
916
941
IndexTupleDSize(item->bti_itup)) {
917
942
elog(NOTICE, "trying to overwrite a smaller value with a bigger one in _bt_updateitem");
918
943
elog(WARN, "this is not good.");
919
944
}
945
+ */
920
946
921
947
oldIndexTuple = & (item -> bti_itup );
922
948
newIndexTuple = & (newItem -> bti_itup );
923
949
924
950
/* 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
+
928
955
}
929
- #endif
0 commit comments