Previous change exposed some opportunities for further simplification
in _bt_first().
This commit is contained in:
parent
569659ae16
commit
2a0caefeb5
@ -8,7 +8,7 @@
|
|||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.84 2003/12/21 01:23:06 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.85 2003/12/21 03:00:04 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -495,10 +495,9 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
|
|||||||
BlockNumber blkno;
|
BlockNumber blkno;
|
||||||
StrategyNumber strat;
|
StrategyNumber strat;
|
||||||
bool res;
|
bool res;
|
||||||
int32 result;
|
|
||||||
bool nextkey;
|
bool nextkey;
|
||||||
bool continuescan;
|
bool continuescan;
|
||||||
ScanKey scankeys = NULL;
|
ScanKey scankeys;
|
||||||
ScanKey *startKeys = NULL;
|
ScanKey *startKeys = NULL;
|
||||||
int keysCount = 0;
|
int keysCount = 0;
|
||||||
int i;
|
int i;
|
||||||
@ -695,8 +694,6 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
|
|||||||
|
|
||||||
pfree(startKeys);
|
pfree(startKeys);
|
||||||
|
|
||||||
current = &(scan->currentItemData);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We want to locate either the first item >= boundary point, or
|
* We want to locate either the first item >= boundary point, or
|
||||||
* first item > boundary point, depending on the initial-positioning
|
* first item > boundary point, depending on the initial-positioning
|
||||||
@ -746,6 +743,8 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
|
|||||||
/* don't need to keep the stack around... */
|
/* don't need to keep the stack around... */
|
||||||
_bt_freestack(stack);
|
_bt_freestack(stack);
|
||||||
|
|
||||||
|
current = &(scan->currentItemData);
|
||||||
|
|
||||||
if (!BufferIsValid(buf))
|
if (!BufferIsValid(buf))
|
||||||
{
|
{
|
||||||
/* Only get here if index is completely empty */
|
/* Only get here if index is completely empty */
|
||||||
@ -765,6 +764,9 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
|
|||||||
|
|
||||||
ItemPointerSet(current, blkno, offnum);
|
ItemPointerSet(current, blkno, offnum);
|
||||||
|
|
||||||
|
/* done with manufactured scankey, now */
|
||||||
|
pfree(scankeys);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* It's now time to examine the initial-positioning strategy to find the
|
* It's now time to examine the initial-positioning strategy to find the
|
||||||
* exact place to start the scan.
|
* exact place to start the scan.
|
||||||
@ -802,10 +804,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
|
|||||||
* that is always the correct starting position.)
|
* that is always the correct starting position.)
|
||||||
*/
|
*/
|
||||||
if (!_bt_step(scan, &buf, BackwardScanDirection))
|
if (!_bt_step(scan, &buf, BackwardScanDirection))
|
||||||
{
|
|
||||||
pfree(scankeys);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BTLessEqualStrategyNumber:
|
case BTLessEqualStrategyNumber:
|
||||||
@ -818,10 +817,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
|
|||||||
* that is always the correct starting position.)
|
* that is always the correct starting position.)
|
||||||
*/
|
*/
|
||||||
if (!_bt_step(scan, &buf, BackwardScanDirection))
|
if (!_bt_step(scan, &buf, BackwardScanDirection))
|
||||||
{
|
|
||||||
pfree(scankeys);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BTEqualStrategyNumber:
|
case BTEqualStrategyNumber:
|
||||||
@ -834,40 +830,27 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
|
|||||||
/*
|
/*
|
||||||
* We are on first item > scankey.
|
* We are on first item > scankey.
|
||||||
*
|
*
|
||||||
* Back up one to arrive at last item <= scankey, then
|
* Back up one to arrive at last item <= scankey.
|
||||||
* check to see if it is equal to scankey.
|
* We will check below to see if it is equal to scankey.
|
||||||
*/
|
*/
|
||||||
if (!_bt_step(scan, &buf, BackwardScanDirection))
|
if (!_bt_step(scan, &buf, BackwardScanDirection))
|
||||||
{
|
|
||||||
pfree(scankeys);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* We are on first item >= scankey.
|
* We are on first item >= scankey.
|
||||||
*
|
*
|
||||||
* Make sure we are on a real item; might have to
|
* Make sure we are on a real item; might have to
|
||||||
* step forward if currently at end of page. Then check
|
* step forward if currently at end of page.
|
||||||
* to see if it is equal to scankey.
|
* We will check below to see if it is equal to scankey.
|
||||||
*/
|
*/
|
||||||
if (offnum > PageGetMaxOffsetNumber(page))
|
if (offnum > PageGetMaxOffsetNumber(page))
|
||||||
{
|
{
|
||||||
if (!_bt_step(scan, &buf, ForwardScanDirection))
|
if (!_bt_step(scan, &buf, ForwardScanDirection))
|
||||||
{
|
|
||||||
pfree(scankeys);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* If we are not now on an equal item, then there ain't any. */
|
|
||||||
offnum = ItemPointerGetOffsetNumber(current);
|
|
||||||
page = BufferGetPage(buf);
|
|
||||||
result = _bt_compare(rel, keysCount, scankeys, page, offnum);
|
|
||||||
if (result != 0)
|
|
||||||
goto nomatches; /* no equal items! */
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BTGreaterEqualStrategyNumber:
|
case BTGreaterEqualStrategyNumber:
|
||||||
@ -879,11 +862,8 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
|
|||||||
if (offnum > PageGetMaxOffsetNumber(page))
|
if (offnum > PageGetMaxOffsetNumber(page))
|
||||||
{
|
{
|
||||||
if (!_bt_step(scan, &buf, ForwardScanDirection))
|
if (!_bt_step(scan, &buf, ForwardScanDirection))
|
||||||
{
|
|
||||||
pfree(scankeys);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BTGreaterStrategyNumber:
|
case BTGreaterStrategyNumber:
|
||||||
@ -895,11 +875,8 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
|
|||||||
if (offnum > PageGetMaxOffsetNumber(page))
|
if (offnum > PageGetMaxOffsetNumber(page))
|
||||||
{
|
{
|
||||||
if (!_bt_step(scan, &buf, ForwardScanDirection))
|
if (!_bt_step(scan, &buf, ForwardScanDirection))
|
||||||
{
|
|
||||||
pfree(scankeys);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -924,15 +901,12 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* no tuples in the index match this scan key */
|
/* no tuples in the index match this scan key */
|
||||||
nomatches:
|
|
||||||
ItemPointerSetInvalid(current);
|
ItemPointerSetInvalid(current);
|
||||||
so->btso_curbuf = InvalidBuffer;
|
so->btso_curbuf = InvalidBuffer;
|
||||||
_bt_relbuf(rel, buf);
|
_bt_relbuf(rel, buf);
|
||||||
res = false;
|
res = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pfree(scankeys);
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user