7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.11 1997/03/24 08 :48:09 vadim Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.12 1997/04/16 01 :48:11 vadim Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -33,7 +33,7 @@ static OffsetNumber _bt_findsplitloc(Relation rel, Page page, OffsetNumber start
33
33
static void _bt_newroot (Relation rel , Buffer lbuf , Buffer rbuf );
34
34
static OffsetNumber _bt_pgaddtup (Relation rel , Buffer buf , int keysz , ScanKey itup_scankey , Size itemsize , BTItem btitem , BTItem afteritem );
35
35
static bool _bt_goesonpg (Relation rel , Buffer buf , Size keysz , ScanKey scankey , BTItem afteritem );
36
- static void _bt_updateitem (Relation rel , Size keysz , Buffer buf , Oid bti_oid , BTItem newItem );
36
+ static void _bt_updateitem (Relation rel , Size keysz , Buffer buf , BTItem oldItem , BTItem newItem );
37
37
static bool _bt_isequal (TupleDesc itupdesc , Page page , OffsetNumber offnum , int keysz , ScanKey scankey );
38
38
39
39
/*
@@ -357,7 +357,7 @@ _bt_insertonpg(Relation rel,
357
357
DOUBLEALIGN (IndexTupleDSize (stack -> bts_btitem -> bti_itup )) )
358
358
{
359
359
_bt_updateitem (rel , keysz , pbuf ,
360
- stack -> bts_btitem -> bti_oid , lowLeftItem );
360
+ stack -> bts_btitem , lowLeftItem );
361
361
_bt_relbuf (rel , buf , BT_WRITE );
362
362
_bt_relbuf (rel , rbuf , BT_WRITE );
363
363
}
@@ -644,23 +644,14 @@ _bt_findsplitloc(Relation rel,
644
644
OffsetNumber saferight ;
645
645
ItemId nxtitemid , safeitemid ;
646
646
BTItem safeitem , nxtitem ;
647
- IndexTuple safetup , nxttup ;
648
647
Size nbytes ;
649
- TupleDesc itupdesc ;
650
648
int natts ;
651
- int attno ;
652
- Datum attsafe ;
653
- Datum attnext ;
654
- bool null ;
655
649
656
- itupdesc = RelationGetTupleDescriptor (rel );
657
650
natts = rel -> rd_rel -> relnatts ;
658
-
659
651
saferight = start ;
660
652
safeitemid = PageGetItemId (page , saferight );
661
653
nbytes = ItemIdGetLength (safeitemid ) + sizeof (ItemIdData );
662
654
safeitem = (BTItem ) PageGetItem (page , safeitemid );
663
- safetup = & (safeitem -> bti_itup );
664
655
665
656
i = OffsetNumberNext (start );
666
657
@@ -670,26 +661,17 @@ _bt_findsplitloc(Relation rel,
670
661
nxtitemid = PageGetItemId (page , i );
671
662
nbytes += (ItemIdGetLength (nxtitemid ) + sizeof (ItemIdData ));
672
663
nxtitem = (BTItem ) PageGetItem (page , nxtitemid );
673
- nxttup = & (nxtitem -> bti_itup );
674
-
675
- /* test against last known safe item */
676
- for (attno = 1 ; attno <= natts ; attno ++ ) {
677
- attsafe = index_getattr (safetup , attno , itupdesc , & null );
678
- attnext = index_getattr (nxttup , attno , itupdesc , & null );
679
664
680
- /*
681
- * If the tuple we're looking at isn't equal to the last safe one
682
- * we saw, then it's our new safe tuple.
683
- */
684
-
685
- if (!_bt_invokestrat (rel , attno , BTEqualStrategyNumber ,
686
- attsafe , attnext )) {
687
- safetup = nxttup ;
688
- saferight = i ;
689
-
690
- /* break is for the attno for loop */
691
- break ;
692
- }
665
+ /*
666
+ * Test against last known safe item:
667
+ * if the tuple we're looking at isn't equal to the last safe
668
+ * one we saw, then it's our new safe tuple.
669
+ */
670
+ if ( !_bt_itemcmp (rel , natts ,
671
+ safeitem , nxtitem , BTEqualStrategyNumber ) )
672
+ {
673
+ safeitem = nxtitem ;
674
+ saferight = i ;
693
675
}
694
676
i = OffsetNumberNext (i );
695
677
}
@@ -753,7 +735,7 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
753
735
rbkno = BufferGetBlockNumber (rbuf );
754
736
lpage = BufferGetPage (lbuf );
755
737
rpage = BufferGetPage (rbuf );
756
-
738
+
757
739
/*
758
740
* step over the high key on the left page while building the
759
741
* left page pointer.
@@ -793,7 +775,7 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
793
775
_bt_wrtbuf (rel , rootbuf );
794
776
795
777
/* update metadata page with new root block number */
796
- _bt_metaproot (rel , rootbknum );
778
+ _bt_metaproot (rel , rootbknum , 0 );
797
779
}
798
780
799
781
/*
@@ -820,7 +802,6 @@ _bt_pgaddtup(Relation rel,
820
802
Page page ;
821
803
BTPageOpaque opaque ;
822
804
BTItem chkitem ;
823
- Oid afteroid ;
824
805
825
806
page = BufferGetPage (buf );
826
807
opaque = (BTPageOpaque ) PageGetSpecialPointer (page );
@@ -829,14 +810,13 @@ _bt_pgaddtup(Relation rel,
829
810
if (afteritem == (BTItem ) NULL ) {
830
811
itup_off = _bt_binsrch (rel , buf , keysz , itup_scankey , BT_INSERTION );
831
812
} else {
832
- afteroid = afteritem -> bti_oid ;
833
813
itup_off = first ;
834
814
835
815
do {
836
816
chkitem =
837
817
(BTItem ) PageGetItem (page , PageGetItemId (page , itup_off ));
838
818
itup_off = OffsetNumberNext (itup_off );
839
- } while (chkitem -> bti_oid != afteroid );
819
+ } while ( ! BTItemSame ( chkitem , afteritem ) );
840
820
}
841
821
842
822
(void ) PageAddItem (page , (Item ) btitem , itemsize , itup_off , LP_USED );
@@ -870,7 +850,6 @@ _bt_goesonpg(Relation rel,
870
850
BTPageOpaque opaque ;
871
851
BTItem chkitem ;
872
852
OffsetNumber offnum , maxoff ;
873
- Oid afteroid ;
874
853
bool found ;
875
854
876
855
page = BufferGetPage (buf );
@@ -908,7 +887,6 @@ _bt_goesonpg(Relation rel,
908
887
return (false);
909
888
910
889
/* damn, have to work for it. i hate that. */
911
- afteroid = afteritem -> bti_oid ;
912
890
maxoff = PageGetMaxOffsetNumber (page );
913
891
914
892
/*
@@ -924,7 +902,8 @@ _bt_goesonpg(Relation rel,
924
902
offnum <= maxoff ;
925
903
offnum = OffsetNumberNext (offnum )) {
926
904
chkitem = (BTItem ) PageGetItem (page , PageGetItemId (page , offnum ));
927
- if (chkitem -> bti_oid == afteroid ) {
905
+
906
+ if ( BTItemSame (chkitem , afteritem ) ) {
928
907
found = true;
929
908
break ;
930
909
}
@@ -1029,7 +1008,7 @@ static void
1029
1008
_bt_updateitem (Relation rel ,
1030
1009
Size keysz ,
1031
1010
Buffer buf ,
1032
- Oid bti_oid ,
1011
+ BTItem oldItem ,
1033
1012
BTItem newItem )
1034
1013
{
1035
1014
Page page ;
@@ -1050,10 +1029,10 @@ _bt_updateitem(Relation rel,
1050
1029
do {
1051
1030
item = (BTItem ) PageGetItem (page , PageGetItemId (page , i ));
1052
1031
i = OffsetNumberNext (i );
1053
- } while (i <= maxoff && item -> bti_oid != bti_oid );
1032
+ } while (i <= maxoff && ! BTItemSame ( item , oldItem ) );
1054
1033
1055
1034
/* this should never happen (in theory) */
1056
- if (item -> bti_oid != bti_oid ) {
1035
+ if ( ! BTItemSame ( item , oldItem ) ) {
1057
1036
elog (FATAL , "_bt_getstackbuf was lying!!" );
1058
1037
}
1059
1038
0 commit comments