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.92 2005/06/13 23:14:48 tgl Exp $
11+ * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.93 2005/06/19 22:41:00 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -495,8 +495,8 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
495495bool nextkey ;
496496bool goback ;
497497bool continuescan ;
498- ScanKey scankeys ;
499- ScanKey * startKeys = NULL ;
498+ ScanKey startKeys [ INDEX_MAX_KEYS ] ;
499+ ScanKeyData scankeys [ INDEX_MAX_KEYS ] ;
500500int keysCount = 0 ;
501501int i ;
502502StrategyNumber strat_total ;
@@ -552,8 +552,6 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
552552ScanKey chosen ;
553553ScanKey cur ;
554554
555- startKeys = (ScanKey * )palloc (so -> numberOfKeys * sizeof (ScanKey ));
556-
557555/*
558556 * chosen is the so-far-chosen key for the current attribute, if
559557 * any. We don't cast the decision in stone until we reach keys
@@ -636,18 +634,14 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
636634 * scan from there.
637635 */
638636if (keysCount == 0 )
639- {
640- if (startKeys )
641- pfree (startKeys );
642637return _bt_endpoint (scan ,dir );
643- }
644638
645639/*
646640 * We want to start the scan somewhere within the index. Set up a
647641 * 3-way-comparison scankey we can use to search for the boundary
648642 * point we identified above.
649643 */
650- scankeys = ( ScanKey ) palloc ( keysCount * sizeof ( ScanKeyData ) );
644+ Assert ( keysCount <= INDEX_MAX_KEYS );
651645for (i = 0 ;i < keysCount ;i ++ )
652646{
653647ScanKey cur = startKeys [i ];
@@ -657,12 +651,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
657651 * code later
658652 */
659653if (cur -> sk_flags & SK_ISNULL )
660- {
661- pfree (startKeys );
662- pfree (scankeys );
663654elog (ERROR ,"btree doesn't support is(not)null, yet" );
664- return false;
665- }
666655
667656/*
668657 * If scankey operator is of default subtype, we can use the
@@ -699,8 +688,6 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
699688}
700689}
701690
702- pfree (startKeys );
703-
704691/*
705692 * Examine the selected initial-positioning strategy to determine
706693 * exactly where we need to start the scan, and set flag variables to
@@ -809,7 +796,6 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
809796/* Only get here if index is completely empty */
810797ItemPointerSetInvalid (current );
811798so -> btso_curbuf = InvalidBuffer ;
812- pfree (scankeys );
813799return false;
814800}
815801
@@ -823,9 +809,6 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
823809blkno = BufferGetBlockNumber (buf );
824810ItemPointerSet (current ,blkno ,offnum );
825811
826- /* done with manufactured scankey, now */
827- pfree (scankeys );
828-
829812/*
830813 * If nextkey = false, we are positioned at the first item >= scan
831814 * key, or possibly at the end of a page on which all the existing