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

Commitd961a56

Browse files
committed
Avoid unnecessary palloc overhead in _bt_first(). The temporary
scankeys arrays that it needs can never have more than INDEX_MAX_KEYSentries, so it's reasonable to just allocate them as fixed-size localarrays, and save the cost of palloc/pfree. Not a huge savings, buta cycle saved is a cycle earned ...
1 parentfc65458 commitd961a56

File tree

1 file changed

+4
-21
lines changed

1 file changed

+4
-21
lines changed

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

Lines changed: 4 additions & 21 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.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)
495495
boolnextkey;
496496
boolgoback;
497497
boolcontinuescan;
498-
ScanKeyscankeys;
499-
ScanKey*startKeys=NULL;
498+
ScanKeystartKeys[INDEX_MAX_KEYS];
499+
ScanKeyDatascankeys[INDEX_MAX_KEYS];
500500
intkeysCount=0;
501501
inti;
502502
StrategyNumberstrat_total;
@@ -552,8 +552,6 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
552552
ScanKeychosen;
553553
ScanKeycur;
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
*/
638636
if (keysCount==0)
639-
{
640-
if (startKeys)
641-
pfree(startKeys);
642637
return_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);
651645
for (i=0;i<keysCount;i++)
652646
{
653647
ScanKeycur=startKeys[i];
@@ -657,12 +651,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
657651
* code later
658652
*/
659653
if (cur->sk_flags&SK_ISNULL)
660-
{
661-
pfree(startKeys);
662-
pfree(scankeys);
663654
elog(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 */
810797
ItemPointerSetInvalid(current);
811798
so->btso_curbuf=InvalidBuffer;
812-
pfree(scankeys);
813799
return false;
814800
}
815801

@@ -823,9 +809,6 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
823809
blkno=BufferGetBlockNumber(buf);
824810
ItemPointerSet(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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp