8
8
* Portions Copyright (c) 1994, Regents of the University of California
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.84 2003/12/21 01:23:06 tgl Exp $
11
+ * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.85 2003/12/21 03:00:04 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -495,10 +495,9 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
495
495
BlockNumber blkno ;
496
496
StrategyNumber strat ;
497
497
bool res ;
498
- int32 result ;
499
498
bool nextkey ;
500
499
bool continuescan ;
501
- ScanKey scankeys = NULL ;
500
+ ScanKey scankeys ;
502
501
ScanKey * startKeys = NULL ;
503
502
int keysCount = 0 ;
504
503
int i ;
@@ -695,8 +694,6 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
695
694
696
695
pfree (startKeys );
697
696
698
- current = & (scan -> currentItemData );
699
-
700
697
/*
701
698
* We want to locate either the first item >= boundary point, or
702
699
* first item > boundary point, depending on the initial-positioning
@@ -746,6 +743,8 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
746
743
/* don't need to keep the stack around... */
747
744
_bt_freestack (stack );
748
745
746
+ current = & (scan -> currentItemData );
747
+
749
748
if (!BufferIsValid (buf ))
750
749
{
751
750
/* Only get here if index is completely empty */
@@ -765,6 +764,9 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
765
764
766
765
ItemPointerSet (current , blkno , offnum );
767
766
767
+ /* done with manufactured scankey, now */
768
+ pfree (scankeys );
769
+
768
770
/*
769
771
* It's now time to examine the initial-positioning strategy to find the
770
772
* exact place to start the scan.
@@ -802,10 +804,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
802
804
* that is always the correct starting position.)
803
805
*/
804
806
if (!_bt_step (scan , & buf , BackwardScanDirection ))
805
- {
806
- pfree (scankeys );
807
807
return false;
808
- }
809
808
break ;
810
809
811
810
case BTLessEqualStrategyNumber :
@@ -818,10 +817,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
818
817
* that is always the correct starting position.)
819
818
*/
820
819
if (!_bt_step (scan , & buf , BackwardScanDirection ))
821
- {
822
- pfree (scankeys );
823
820
return false;
824
- }
825
821
break ;
826
822
827
823
case BTEqualStrategyNumber :
@@ -834,40 +830,27 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
834
830
/*
835
831
* We are on first item > scankey.
836
832
*
837
- * Back up one to arrive at last item <= scankey, then
838
- * check to see if it is equal to scankey.
833
+ * Back up one to arrive at last item <= scankey.
834
+ * We will check below to see if it is equal to scankey.
839
835
*/
840
836
if (!_bt_step (scan , & buf , BackwardScanDirection ))
841
- {
842
- pfree (scankeys );
843
837
return false;
844
- }
845
838
}
846
839
else
847
840
{
848
841
/*
849
842
* We are on first item >= scankey.
850
843
*
851
844
* Make sure we are on a real item; might have to
852
- * step forward if currently at end of page. Then check
853
- * to see if it is equal to scankey.
845
+ * step forward if currently at end of page.
846
+ * We will check below to see if it is equal to scankey.
854
847
*/
855
848
if (offnum > PageGetMaxOffsetNumber (page ))
856
849
{
857
850
if (!_bt_step (scan , & buf , ForwardScanDirection ))
858
- {
859
- pfree (scankeys );
860
851
return false;
861
- }
862
852
}
863
853
}
864
-
865
- /* If we are not now on an equal item, then there ain't any. */
866
- offnum = ItemPointerGetOffsetNumber (current );
867
- page = BufferGetPage (buf );
868
- result = _bt_compare (rel , keysCount , scankeys , page , offnum );
869
- if (result != 0 )
870
- goto nomatches ; /* no equal items! */
871
854
break ;
872
855
873
856
case BTGreaterEqualStrategyNumber :
@@ -879,10 +862,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
879
862
if (offnum > PageGetMaxOffsetNumber (page ))
880
863
{
881
864
if (!_bt_step (scan , & buf , ForwardScanDirection ))
882
- {
883
- pfree (scankeys );
884
865
return false;
885
- }
886
866
}
887
867
break ;
888
868
@@ -895,10 +875,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
895
875
if (offnum > PageGetMaxOffsetNumber (page ))
896
876
{
897
877
if (!_bt_step (scan , & buf , ForwardScanDirection ))
898
- {
899
- pfree (scankeys );
900
878
return false;
901
- }
902
879
}
903
880
break ;
904
881
}
@@ -924,15 +901,12 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
924
901
else
925
902
{
926
903
/* no tuples in the index match this scan key */
927
- nomatches :
928
904
ItemPointerSetInvalid (current );
929
905
so -> btso_curbuf = InvalidBuffer ;
930
906
_bt_relbuf (rel , buf );
931
907
res = false;
932
908
}
933
909
934
- pfree (scankeys );
935
-
936
910
return res ;
937
911
}
938
912
0 commit comments