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

Commitf1b059a

Browse files
committed
A couple of tiny performance hacks in _bt_step(). Remove PageIsEmpty
checks, which were once needed because PageGetMaxOffsetNumber wouldfail on empty pages, but are now just redundant. Also, don't set uplocal variables that aren't needed in the fast path --- most of thetime, we only need to advance offnum and not step across a page boundary.Motivated by noticing _bt_step at the top of OProfile profile for apgbench run.
1 parent10a2df2 commitf1b059a

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

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

Lines changed: 10 additions & 8 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.97 2005/11/22 18:17:06 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.98 2005/12/07 18:03:48 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -889,9 +889,9 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
889889
bool
890890
_bt_step(IndexScanDescscan,Buffer*bufP,ScanDirectiondir)
891891
{
892-
Relationrel=scan->indexRelation;
893892
ItemPointercurrent=&(scan->currentItemData);
894893
BTScanOpaqueso= (BTScanOpaque)scan->opaque;
894+
Relationrel;
895895
Pagepage;
896896
BTPageOpaqueopaque;
897897
OffsetNumberoffnum,
@@ -905,16 +905,17 @@ _bt_step(IndexScanDesc scan, Buffer *bufP, ScanDirection dir)
905905
offnum=current->ip_posid;
906906

907907
page=BufferGetPage(*bufP);
908-
opaque= (BTPageOpaque)PageGetSpecialPointer(page);
909908
maxoff=PageGetMaxOffsetNumber(page);
910909

911910
if (ScanDirectionIsForward(dir))
912911
{
913-
if (!PageIsEmpty(page)&&offnum<maxoff)
912+
if (offnum<maxoff)
914913
offnum=OffsetNumberNext(offnum);
915914
else
916915
{
917916
/* Walk right to the next page with data */
917+
rel=scan->indexRelation;
918+
opaque= (BTPageOpaque)PageGetSpecialPointer(page);
918919
for (;;)
919920
{
920921
/* if we're at end of scan, release the buffer and return */
@@ -932,10 +933,10 @@ _bt_step(IndexScanDesc scan, Buffer *bufP, ScanDirection dir)
932933
opaque= (BTPageOpaque)PageGetSpecialPointer(page);
933934
if (!P_IGNORE(opaque))
934935
{
935-
maxoff=PageGetMaxOffsetNumber(page);
936936
/* done if it's not empty */
937+
maxoff=PageGetMaxOffsetNumber(page);
937938
offnum=P_FIRSTDATAKEY(opaque);
938-
if (!PageIsEmpty(page)&&offnum <=maxoff)
939+
if (offnum <=maxoff)
939940
break;
940941
}
941942
}
@@ -944,6 +945,7 @@ _bt_step(IndexScanDesc scan, Buffer *bufP, ScanDirection dir)
944945
else
945946
{
946947
/* backwards scan */
948+
opaque= (BTPageOpaque)PageGetSpecialPointer(page);
947949
if (offnum>P_FIRSTDATAKEY(opaque))
948950
offnum=OffsetNumberPrev(offnum);
949951
else
@@ -955,6 +957,7 @@ _bt_step(IndexScanDesc scan, Buffer *bufP, ScanDirection dir)
955957
* plus the possibility that the page we were on gets deleted
956958
* after we leave it. See nbtree/README for details.
957959
*/
960+
rel=scan->indexRelation;
958961
for (;;)
959962
{
960963
*bufP=_bt_walk_left(rel,*bufP);
@@ -978,8 +981,7 @@ _bt_step(IndexScanDesc scan, Buffer *bufP, ScanDirection dir)
978981
{
979982
maxoff=PageGetMaxOffsetNumber(page);
980983
offnum=maxoff;
981-
if (!PageIsEmpty(page)&&
982-
maxoff >=P_FIRSTDATAKEY(opaque))
984+
if (maxoff >=P_FIRSTDATAKEY(opaque))
983985
break;
984986
}
985987
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp