Commit 12179c99 authored by Tom Lane's avatar Tom Lane

Marginal hack to merge adjacent ReleaseBuffer/ReadBuffer calls into

ReleaseAndReadBuffer during GIST index searches.  We already did this
in btree and rtree, might as well do it here too.
parent 11635c3f
...@@ -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/gist/gistget.c,v 1.43 2004/12/31 21:59:10 pgsql Exp $ * $PostgreSQL: pgsql/src/backend/access/gist/gistget.c,v 1.44 2005/02/05 19:38:58 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -60,10 +60,11 @@ gistfirst(IndexScanDesc s, ScanDirection dir) ...@@ -60,10 +60,11 @@ gistfirst(IndexScanDesc s, ScanDirection dir)
BlockNumber blk; BlockNumber blk;
IndexTuple it; IndexTuple it;
so = (GISTScanOpaque) s->opaque;
b = ReadBuffer(s->indexRelation, GISTP_ROOT); b = ReadBuffer(s->indexRelation, GISTP_ROOT);
p = BufferGetPage(b); p = BufferGetPage(b);
po = (GISTPageOpaque) PageGetSpecialPointer(p); po = (GISTPageOpaque) PageGetSpecialPointer(p);
so = (GISTScanOpaque) s->opaque;
for (;;) for (;;)
{ {
...@@ -75,12 +76,14 @@ gistfirst(IndexScanDesc s, ScanDirection dir) ...@@ -75,12 +76,14 @@ gistfirst(IndexScanDesc s, ScanDirection dir)
while (n < FirstOffsetNumber || n > maxoff) while (n < FirstOffsetNumber || n > maxoff)
{ {
ReleaseBuffer(b); stk = so->s_stack;
if (so->s_stack == NULL) if (stk == NULL)
{
ReleaseBuffer(b);
return false; return false;
}
stk = so->s_stack; b = ReleaseAndReadBuffer(b, s->indexRelation, stk->gs_blk);
b = ReadBuffer(s->indexRelation, stk->gs_blk);
p = BufferGetPage(b); p = BufferGetPage(b);
po = (GISTPageOpaque) PageGetSpecialPointer(p); po = (GISTPageOpaque) PageGetSpecialPointer(p);
maxoff = PageGetMaxOffsetNumber(p); maxoff = PageGetMaxOffsetNumber(p);
...@@ -89,6 +92,7 @@ gistfirst(IndexScanDesc s, ScanDirection dir) ...@@ -89,6 +92,7 @@ gistfirst(IndexScanDesc s, ScanDirection dir)
n = OffsetNumberPrev(stk->gs_child); n = OffsetNumberPrev(stk->gs_child);
else else
n = OffsetNumberNext(stk->gs_child); n = OffsetNumberNext(stk->gs_child);
so->s_stack = stk->gs_parent; so->s_stack = stk->gs_parent;
pfree(stk); pfree(stk);
...@@ -116,8 +120,7 @@ gistfirst(IndexScanDesc s, ScanDirection dir) ...@@ -116,8 +120,7 @@ gistfirst(IndexScanDesc s, ScanDirection dir)
it = (IndexTuple) PageGetItem(p, PageGetItemId(p, n)); it = (IndexTuple) PageGetItem(p, PageGetItemId(p, n));
blk = ItemPointerGetBlockNumber(&(it->t_tid)); blk = ItemPointerGetBlockNumber(&(it->t_tid));
ReleaseBuffer(b); b = ReleaseAndReadBuffer(b, s->indexRelation, blk);
b = ReadBuffer(s->indexRelation, blk);
p = BufferGetPage(b); p = BufferGetPage(b);
po = (GISTPageOpaque) PageGetSpecialPointer(p); po = (GISTPageOpaque) PageGetSpecialPointer(p);
} }
...@@ -137,6 +140,8 @@ gistnext(IndexScanDesc s, ScanDirection dir) ...@@ -137,6 +140,8 @@ gistnext(IndexScanDesc s, ScanDirection dir)
BlockNumber blk; BlockNumber blk;
IndexTuple it; IndexTuple it;
so = (GISTScanOpaque) s->opaque;
blk = ItemPointerGetBlockNumber(&(s->currentItemData)); blk = ItemPointerGetBlockNumber(&(s->currentItemData));
n = ItemPointerGetOffsetNumber(&(s->currentItemData)); n = ItemPointerGetOffsetNumber(&(s->currentItemData));
...@@ -148,7 +153,6 @@ gistnext(IndexScanDesc s, ScanDirection dir) ...@@ -148,7 +153,6 @@ gistnext(IndexScanDesc s, ScanDirection dir)
b = ReadBuffer(s->indexRelation, blk); b = ReadBuffer(s->indexRelation, blk);
p = BufferGetPage(b); p = BufferGetPage(b);
po = (GISTPageOpaque) PageGetSpecialPointer(p); po = (GISTPageOpaque) PageGetSpecialPointer(p);
so = (GISTScanOpaque) s->opaque;
for (;;) for (;;)
{ {
...@@ -157,20 +161,23 @@ gistnext(IndexScanDesc s, ScanDirection dir) ...@@ -157,20 +161,23 @@ gistnext(IndexScanDesc s, ScanDirection dir)
while (n < FirstOffsetNumber || n > maxoff) while (n < FirstOffsetNumber || n > maxoff)
{ {
ReleaseBuffer(b); stk = so->s_stack;
if (so->s_stack == NULL) if (stk == NULL)
{
ReleaseBuffer(b);
return false; return false;
}
stk = so->s_stack; b = ReleaseAndReadBuffer(b, s->indexRelation, stk->gs_blk);
b = ReadBuffer(s->indexRelation, stk->gs_blk);
p = BufferGetPage(b); p = BufferGetPage(b);
maxoff = PageGetMaxOffsetNumber(p);
po = (GISTPageOpaque) PageGetSpecialPointer(p); po = (GISTPageOpaque) PageGetSpecialPointer(p);
maxoff = PageGetMaxOffsetNumber(p);
if (ScanDirectionIsBackward(dir)) if (ScanDirectionIsBackward(dir))
n = OffsetNumberPrev(stk->gs_child); n = OffsetNumberPrev(stk->gs_child);
else else
n = OffsetNumberNext(stk->gs_child); n = OffsetNumberNext(stk->gs_child);
so->s_stack = stk->gs_parent; so->s_stack = stk->gs_parent;
pfree(stk); pfree(stk);
...@@ -198,8 +205,7 @@ gistnext(IndexScanDesc s, ScanDirection dir) ...@@ -198,8 +205,7 @@ gistnext(IndexScanDesc s, ScanDirection dir)
it = (IndexTuple) PageGetItem(p, PageGetItemId(p, n)); it = (IndexTuple) PageGetItem(p, PageGetItemId(p, n));
blk = ItemPointerGetBlockNumber(&(it->t_tid)); blk = ItemPointerGetBlockNumber(&(it->t_tid));
ReleaseBuffer(b); b = ReleaseAndReadBuffer(b, s->indexRelation, blk);
b = ReadBuffer(s->indexRelation, blk);
p = BufferGetPage(b); p = BufferGetPage(b);
po = (GISTPageOpaque) PageGetSpecialPointer(p); po = (GISTPageOpaque) PageGetSpecialPointer(p);
......
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