Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2a0caef

Browse files
committed
Previous change exposed some opportunities for further simplification
in _bt_first().
1 parent569659a commit2a0caef

File tree

1 file changed

+11
-37
lines changed

1 file changed

+11
-37
lines changed

‎src/backend/access/nbtree/nbtsearch.c

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.84 2003/12/2101:23:06 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.85 2003/12/2103:00:04 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -495,10 +495,9 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
495495
BlockNumberblkno;
496496
StrategyNumberstrat;
497497
boolres;
498-
int32result;
499498
boolnextkey;
500499
boolcontinuescan;
501-
ScanKeyscankeys=NULL;
500+
ScanKeyscankeys;
502501
ScanKey*startKeys=NULL;
503502
intkeysCount=0;
504503
inti;
@@ -695,8 +694,6 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
695694

696695
pfree(startKeys);
697696

698-
current=&(scan->currentItemData);
699-
700697
/*
701698
* We want to locate either the first item >= boundary point, or
702699
* first item > boundary point, depending on the initial-positioning
@@ -746,6 +743,8 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
746743
/* don't need to keep the stack around... */
747744
_bt_freestack(stack);
748745

746+
current=&(scan->currentItemData);
747+
749748
if (!BufferIsValid(buf))
750749
{
751750
/* Only get here if index is completely empty */
@@ -765,6 +764,9 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
765764

766765
ItemPointerSet(current,blkno,offnum);
767766

767+
/* done with manufactured scankey, now */
768+
pfree(scankeys);
769+
768770
/*
769771
* It's now time to examine the initial-positioning strategy to find the
770772
* exact place to start the scan.
@@ -802,10 +804,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
802804
* that is always the correct starting position.)
803805
*/
804806
if (!_bt_step(scan,&buf,BackwardScanDirection))
805-
{
806-
pfree(scankeys);
807807
return false;
808-
}
809808
break;
810809

811810
caseBTLessEqualStrategyNumber:
@@ -818,10 +817,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
818817
* that is always the correct starting position.)
819818
*/
820819
if (!_bt_step(scan,&buf,BackwardScanDirection))
821-
{
822-
pfree(scankeys);
823820
return false;
824-
}
825821
break;
826822

827823
caseBTEqualStrategyNumber:
@@ -834,40 +830,27 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
834830
/*
835831
* We are on first item > scankey.
836832
*
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 willcheck below to see if it is equal to scankey.
839835
*/
840836
if (!_bt_step(scan,&buf,BackwardScanDirection))
841-
{
842-
pfree(scankeys);
843837
return false;
844-
}
845838
}
846839
else
847840
{
848841
/*
849842
* We are on first item >= scankey.
850843
*
851844
* 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 belowto see if it is equal to scankey.
854847
*/
855848
if (offnum>PageGetMaxOffsetNumber(page))
856849
{
857850
if (!_bt_step(scan,&buf,ForwardScanDirection))
858-
{
859-
pfree(scankeys);
860851
return false;
861-
}
862852
}
863853
}
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-
gotonomatches;/* no equal items! */
871854
break;
872855

873856
caseBTGreaterEqualStrategyNumber:
@@ -879,10 +862,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
879862
if (offnum>PageGetMaxOffsetNumber(page))
880863
{
881864
if (!_bt_step(scan,&buf,ForwardScanDirection))
882-
{
883-
pfree(scankeys);
884865
return false;
885-
}
886866
}
887867
break;
888868

@@ -895,10 +875,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
895875
if (offnum>PageGetMaxOffsetNumber(page))
896876
{
897877
if (!_bt_step(scan,&buf,ForwardScanDirection))
898-
{
899-
pfree(scankeys);
900878
return false;
901-
}
902879
}
903880
break;
904881
}
@@ -924,15 +901,12 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
924901
else
925902
{
926903
/* no tuples in the index match this scan key */
927-
nomatches:
928904
ItemPointerSetInvalid(current);
929905
so->btso_curbuf=InvalidBuffer;
930906
_bt_relbuf(rel,buf);
931907
res= false;
932908
}
933909

934-
pfree(scankeys);
935-
936910
returnres;
937911
}
938912

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp