* Portions Copyright (c) 1994, Regents of the University of California
*
* 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 $
*
*-------------------------------------------------------------------------
*/
BlockNumber blkno;
StrategyNumber strat;
bool res;
- int32 result;
bool nextkey;
bool continuescan;
- ScanKey scankeys = NULL;
+ ScanKey scankeys;
ScanKey *startKeys = NULL;
int keysCount = 0;
int i;
pfree(startKeys);
- current = &(scan->currentItemData);
-
/*
* We want to locate either the first item >= boundary point, or
* first item > boundary point, depending on the initial-positioning
/* don't need to keep the stack around... */
_bt_freestack(stack);
+ current = &(scan->currentItemData);
+
if (!BufferIsValid(buf))
{
/* Only get here if index is completely empty */
ItemPointerSet(current, blkno, offnum);
+ /* done with manufactured scankey, now */
+ pfree(scankeys);
+
/*
* It's now time to examine the initial-positioning strategy to find the
* exact place to start the scan.
* that is always the correct starting position.)
*/
if (!_bt_step(scan, &buf, BackwardScanDirection))
- {
- pfree(scankeys);
return false;
- }
break;
case BTLessEqualStrategyNumber:
* that is always the correct starting position.)
*/
if (!_bt_step(scan, &buf, BackwardScanDirection))
- {
- pfree(scankeys);
return false;
- }
break;
case BTEqualStrategyNumber:
/*
* We are on first item > scankey.
*
- * Back up one to arrive at last item <= scankey, then
- * check to see if it is equal to scankey.
+ * Back up one to arrive at last item <= scankey.
+ * We will check below to see if it is equal to scankey.
*/
if (!_bt_step(scan, &buf, BackwardScanDirection))
- {
- pfree(scankeys);
return false;
- }
}
else
{
* We are on first item >= scankey.
*
* Make sure we are on a real item; might have to
- * step forward if currently at end of page. Then check
- * to see if it is equal to scankey.
+ * step forward if currently at end of page.
+ * We will check below to see if it is equal to scankey.
*/
if (offnum > PageGetMaxOffsetNumber(page))
{
if (!_bt_step(scan, &buf, ForwardScanDirection))
- {
- pfree(scankeys);
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;
case BTGreaterEqualStrategyNumber:
if (offnum > PageGetMaxOffsetNumber(page))
{
if (!_bt_step(scan, &buf, ForwardScanDirection))
- {
- pfree(scankeys);
return false;
- }
}
break;
if (offnum > PageGetMaxOffsetNumber(page))
{
if (!_bt_step(scan, &buf, ForwardScanDirection))
- {
- pfree(scankeys);
return false;
- }
}
break;
}
else
{
/* no tuples in the index match this scan key */
-nomatches:
ItemPointerSetInvalid(current);
so->btso_curbuf = InvalidBuffer;
_bt_relbuf(rel, buf);
res = false;
}
- pfree(scankeys);
-
return res;
}