7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.14 1997/02 /1817:13:48 momjian Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.15 1997/03 /1818:38:41 scrappy Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -562,7 +562,6 @@ _bt_next(IndexScanDesc scan, ScanDirection dir)
562
562
Page page ;
563
563
OffsetNumber offnum ;
564
564
RetrieveIndexResult res ;
565
- BlockNumber blkno ;
566
565
ItemPointer current ;
567
566
BTItem btitem ;
568
567
IndexTuple itup ;
@@ -584,31 +583,35 @@ _bt_next(IndexScanDesc scan, ScanDirection dir)
584
583
585
584
/* we still have the buffer pinned and locked */
586
585
buf = so -> btso_curbuf ;
587
- blkno = BufferGetBlockNumber (buf );
588
586
589
- /* step one tuple in the appropriate direction */
590
- if (!_bt_step (scan ,& buf ,dir ))
591
- return ((RetrieveIndexResult )NULL );
587
+ do
588
+ {
589
+ /* step one tuple in the appropriate direction */
590
+ if (!_bt_step (scan ,& buf ,dir ))
591
+ return ((RetrieveIndexResult )NULL );
592
592
593
- /* by here, current is the tuple we want to return */
594
- offnum = ItemPointerGetOffsetNumber (current );
595
- page = BufferGetPage (buf );
596
- btitem = (BTItem )PageGetItem (page ,PageGetItemId (page ,offnum ));
597
- itup = & btitem -> bti_itup ;
593
+ /* by here, current is the tuple we want to return */
594
+ offnum = ItemPointerGetOffsetNumber (current );
595
+ page = BufferGetPage (buf );
596
+ btitem = (BTItem )PageGetItem (page ,PageGetItemId (page ,offnum ));
597
+ itup = & btitem -> bti_itup ;
598
598
599
- if (_bt_checkqual (scan ,itup )) {
600
- res = FormRetrieveIndexResult (current ,& (itup -> t_tid ));
599
+ if (_bt_checkqual (scan ,itup ))
600
+ {
601
+ res = FormRetrieveIndexResult (current ,& (itup -> t_tid ));
601
602
602
- /* remember which buffer we have pinned and locked */
603
- so -> btso_curbuf = buf ;
604
- }else {
605
- ItemPointerSetInvalid (current );
606
- so -> btso_curbuf = InvalidBuffer ;
607
- _bt_relbuf (rel ,buf ,BT_READ );
608
- res = (RetrieveIndexResult )NULL ;
609
- }
603
+ /* remember which buffer we have pinned and locked */
604
+ so -> btso_curbuf = buf ;
605
+ return (res );
606
+ }
607
+
608
+ }while (_bt_checkforkeys (scan ,itup ,so -> numberOfFirstKeys ) );
609
+
610
+ ItemPointerSetInvalid (current );
611
+ so -> btso_curbuf = InvalidBuffer ;
612
+ _bt_relbuf (rel ,buf ,BT_READ );
610
613
611
- return (res );
614
+ return (( RetrieveIndexResult ) NULL );
612
615
}
613
616
614
617
/*
@@ -660,13 +663,6 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
660
663
* ordered to take advantage of index ordering) to position ourselves
661
664
* at the right place in the scan.
662
665
*/
663
-
664
- /*
665
- * XXX -- The attribute number stored in the scan key is the attno
666
- * in the heap relation. We need to transmogrify this into
667
- * the index relation attno here. For the moment, we have
668
- * hardwired attno == 1.
669
- */
670
666
proc = index_getprocid (rel ,1 ,BTORDER_PROC );
671
667
ScanKeyEntryInitialize (& skdata ,so -> keyData [0 ].sk_flags ,1 ,proc ,
672
668
so -> keyData [0 ].sk_argument );
@@ -802,12 +798,20 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
802
798
btitem = (BTItem )PageGetItem (page ,PageGetItemId (page ,offnum ));
803
799
itup = & btitem -> bti_itup ;
804
800
805
- if (_bt_checkqual (scan ,itup )) {
801
+ if (_bt_checkqual (scan ,itup ) )
802
+ {
806
803
res = FormRetrieveIndexResult (current ,& (itup -> t_tid ));
807
804
808
805
/* remember which buffer we have pinned */
809
806
so -> btso_curbuf = buf ;
810
- }else {
807
+ }
808
+ else if (_bt_checkforkeys (scan ,itup ,so -> numberOfFirstKeys ) )
809
+ {
810
+ so -> btso_curbuf = buf ;
811
+ return (_bt_next (scan ,dir ));
812
+ }
813
+ else
814
+ {
811
815
ItemPointerSetInvalid (current );
812
816
so -> btso_curbuf = InvalidBuffer ;
813
817
_bt_relbuf (rel ,buf ,BT_READ );
@@ -1224,7 +1228,14 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir)
1224
1228
1225
1229
/* remember which buffer we have pinned */
1226
1230
so -> btso_curbuf = buf ;
1227
- }else {
1231
+ }
1232
+ else if (_bt_checkforkeys (scan ,itup ,so -> numberOfFirstKeys ) )
1233
+ {
1234
+ so -> btso_curbuf = buf ;
1235
+ return (_bt_next (scan ,dir ));
1236
+ }
1237
+ else
1238
+ {
1228
1239
_bt_relbuf (rel ,buf ,BT_READ );
1229
1240
res = (RetrieveIndexResult )NULL ;
1230
1241
}