Commit d961a568 authored by Tom Lane's avatar Tom Lane

Avoid unnecessary palloc overhead in _bt_first(). The temporary

scankeys arrays that it needs can never have more than INDEX_MAX_KEYS
entries, so it's reasonable to just allocate them as fixed-size local
arrays, and save the cost of palloc/pfree.  Not a huge savings, but
a cycle saved is a cycle earned ...
parent fc654583
...@@ -8,7 +8,7 @@ ...@@ -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.92 2005/06/13 23:14:48 tgl Exp $ * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.93 2005/06/19 22:41:00 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -495,8 +495,8 @@ _bt_first(IndexScanDesc scan, ScanDirection dir) ...@@ -495,8 +495,8 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
bool nextkey; bool nextkey;
bool goback; bool goback;
bool continuescan; bool continuescan;
ScanKey scankeys; ScanKey startKeys[INDEX_MAX_KEYS];
ScanKey *startKeys = NULL; ScanKeyData scankeys[INDEX_MAX_KEYS];
int keysCount = 0; int keysCount = 0;
int i; int i;
StrategyNumber strat_total; StrategyNumber strat_total;
...@@ -552,8 +552,6 @@ _bt_first(IndexScanDesc scan, ScanDirection dir) ...@@ -552,8 +552,6 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
ScanKey chosen; ScanKey chosen;
ScanKey cur; ScanKey cur;
startKeys = (ScanKey *) palloc(so->numberOfKeys * sizeof(ScanKey));
/* /*
* chosen is the so-far-chosen key for the current attribute, if * chosen is the so-far-chosen key for the current attribute, if
* any. We don't cast the decision in stone until we reach keys * any. We don't cast the decision in stone until we reach keys
...@@ -636,18 +634,14 @@ _bt_first(IndexScanDesc scan, ScanDirection dir) ...@@ -636,18 +634,14 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
* scan from there. * scan from there.
*/ */
if (keysCount == 0) if (keysCount == 0)
{
if (startKeys)
pfree(startKeys);
return _bt_endpoint(scan, dir); return _bt_endpoint(scan, dir);
}
/* /*
* We want to start the scan somewhere within the index. Set up a * We want to start the scan somewhere within the index. Set up a
* 3-way-comparison scankey we can use to search for the boundary * 3-way-comparison scankey we can use to search for the boundary
* point we identified above. * point we identified above.
*/ */
scankeys = (ScanKey) palloc(keysCount * sizeof(ScanKeyData)); Assert(keysCount <= INDEX_MAX_KEYS);
for (i = 0; i < keysCount; i++) for (i = 0; i < keysCount; i++)
{ {
ScanKey cur = startKeys[i]; ScanKey cur = startKeys[i];
...@@ -657,12 +651,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir) ...@@ -657,12 +651,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
* code later * code later
*/ */
if (cur->sk_flags & SK_ISNULL) if (cur->sk_flags & SK_ISNULL)
{
pfree(startKeys);
pfree(scankeys);
elog(ERROR, "btree doesn't support is(not)null, yet"); elog(ERROR, "btree doesn't support is(not)null, yet");
return false;
}
/* /*
* If scankey operator is of default subtype, we can use the * If scankey operator is of default subtype, we can use the
...@@ -699,8 +688,6 @@ _bt_first(IndexScanDesc scan, ScanDirection dir) ...@@ -699,8 +688,6 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
} }
} }
pfree(startKeys);
/* /*
* Examine the selected initial-positioning strategy to determine * Examine the selected initial-positioning strategy to determine
* exactly where we need to start the scan, and set flag variables to * exactly where we need to start the scan, and set flag variables to
...@@ -809,7 +796,6 @@ _bt_first(IndexScanDesc scan, ScanDirection dir) ...@@ -809,7 +796,6 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
/* Only get here if index is completely empty */ /* Only get here if index is completely empty */
ItemPointerSetInvalid(current); ItemPointerSetInvalid(current);
so->btso_curbuf = InvalidBuffer; so->btso_curbuf = InvalidBuffer;
pfree(scankeys);
return false; return false;
} }
...@@ -823,9 +809,6 @@ _bt_first(IndexScanDesc scan, ScanDirection dir) ...@@ -823,9 +809,6 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
blkno = BufferGetBlockNumber(buf); blkno = BufferGetBlockNumber(buf);
ItemPointerSet(current, blkno, offnum); ItemPointerSet(current, blkno, offnum);
/* done with manufactured scankey, now */
pfree(scankeys);
/* /*
* If nextkey = false, we are positioned at the first item >= scan * If nextkey = false, we are positioned at the first item >= scan
* key, or possibly at the end of a page on which all the existing * key, or possibly at the end of a page on which all the existing
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment