From 8c2f099ab5de5d0396dd2eb81cd5c55fae5e1579 Mon Sep 17 00:00:00 2001 From: "Vadim B. Mikheev" Date: Thu, 21 Nov 1996 06:13:43 +0000 Subject: [PATCH] Fix memory overhelding while forming index' result: memory allocation for ItemPointerData of heap' tuple is useless because of FormRetrieveIndexResult makes neccessary palloc. --- src/backend/access/nbtree/nbtsearch.c | 21 ++++----------------- src/backend/access/rtree/rtget.c | 20 +++++++------------- 2 files changed, 11 insertions(+), 30 deletions(-) diff --git a/src/backend/access/nbtree/nbtsearch.c b/src/backend/access/nbtree/nbtsearch.c index d6658ea701..b3c5e007ca 100644 --- a/src/backend/access/nbtree/nbtsearch.c +++ b/src/backend/access/nbtree/nbtsearch.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.9 1996/11/13 20:47:20 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.10 1996/11/21 06:10:55 vadim Exp $ * *------------------------------------------------------------------------- */ @@ -535,7 +535,6 @@ _bt_next(IndexScanDesc scan, ScanDirection dir) RetrieveIndexResult res; BlockNumber blkno; ItemPointer current; - ItemPointer iptr; BTItem btitem; IndexTuple itup; BTScanOpaque so; @@ -569,10 +568,7 @@ _bt_next(IndexScanDesc scan, ScanDirection dir) itup = &btitem->bti_itup; if (_bt_checkqual(scan, itup)) { - iptr = (ItemPointer) palloc(sizeof(ItemPointerData)); - memmove((char *) iptr, (char *) &(itup->t_tid), - sizeof(ItemPointerData)); - res = FormRetrieveIndexResult(current, iptr); + res = FormRetrieveIndexResult(current, &(itup->t_tid)); /* remember which buffer we have pinned and locked */ so->btso_curbuf = buf; @@ -608,7 +604,6 @@ _bt_first(IndexScanDesc scan, ScanDirection dir) BTItem btitem; IndexTuple itup; ItemPointer current; - ItemPointer iptr; BlockNumber blkno; StrategyNumber strat; RetrieveIndexResult res; @@ -764,11 +759,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir) itup = &btitem->bti_itup; if (_bt_checkqual(scan, itup)) { - iptr = (ItemPointer) palloc(sizeof(ItemPointerData)); - memmove((char *) iptr, (char *) &(itup->t_tid), - sizeof(ItemPointerData)); - res = FormRetrieveIndexResult(current, iptr); - pfree(iptr); + res = FormRetrieveIndexResult(current, &(itup->t_tid)); /* remember which buffer we have pinned */ so->btso_curbuf = buf; @@ -1035,7 +1026,6 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir) Page page; BTPageOpaque opaque; ItemPointer current; - ItemPointer iptr; OffsetNumber offnum, maxoff; OffsetNumber start = 0; BlockNumber blkno; @@ -1132,10 +1122,7 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir) /* see if we picked a winner */ if (_bt_checkqual(scan, itup)) { - iptr = (ItemPointer) palloc(sizeof(ItemPointerData)); - memmove((char *) iptr, (char *) &(itup->t_tid), - sizeof(ItemPointerData)); - res = FormRetrieveIndexResult(current, iptr); + res = FormRetrieveIndexResult(current, &(itup->t_tid)); /* remember which buffer we have pinned */ so = (BTScanOpaque) scan->opaque; diff --git a/src/backend/access/rtree/rtget.c b/src/backend/access/rtree/rtget.c index a21f29f67c..09f10f1aa9 100644 --- a/src/backend/access/rtree/rtget.c +++ b/src/backend/access/rtree/rtget.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtget.c,v 1.6 1996/11/05 10:54:16 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtget.c,v 1.7 1996/11/21 06:13:43 vadim Exp $ * *------------------------------------------------------------------------- */ @@ -66,7 +66,6 @@ rtfirst(IndexScanDesc s, ScanDirection dir) RTSTACK *stk; BlockNumber blk; IndexTuple it; - ItemPointer ip; b = ReadBuffer(s->relation, P_ROOT); p = BufferGetPage(b); @@ -106,13 +105,10 @@ rtfirst(IndexScanDesc s, ScanDirection dir) ItemPointerSet(&(s->currentItemData), BufferGetBlockNumber(b), n); it = (IndexTuple) PageGetItem(p, PageGetItemId(p, n)); - ip = (ItemPointer) palloc(sizeof(ItemPointerData)); - memmove((char *) ip, (char *) &(it->t_tid), - sizeof(ItemPointerData)); - ReleaseBuffer(b); - res = FormRetrieveIndexResult(&(s->currentItemData), ip); + res = FormRetrieveIndexResult(&(s->currentItemData), &(it->t_tid)); + ReleaseBuffer(b); return (res); } else { stk = (RTSTACK *) palloc(sizeof(RTSTACK)); @@ -145,7 +141,6 @@ rtnext(IndexScanDesc s, ScanDirection dir) RTSTACK *stk; BlockNumber blk; IndexTuple it; - ItemPointer ip; blk = ItemPointerGetBlockNumber(&(s->currentItemData)); n = ItemPointerGetOffsetNumber(&(s->currentItemData)); @@ -191,13 +186,10 @@ rtnext(IndexScanDesc s, ScanDirection dir) ItemPointerSet(&(s->currentItemData), BufferGetBlockNumber(b), n); it = (IndexTuple) PageGetItem(p, PageGetItemId(p, n)); - ip = (ItemPointer) palloc(sizeof(ItemPointerData)); - memmove((char *) ip, (char *) &(it->t_tid), - sizeof(ItemPointerData)); - ReleaseBuffer(b); - res = FormRetrieveIndexResult(&(s->currentItemData), ip); + res = FormRetrieveIndexResult(&(s->currentItemData), &(it->t_tid)); + ReleaseBuffer(b); return (res); } else { stk = (RTSTACK *) palloc(sizeof(RTSTACK)); @@ -288,6 +280,8 @@ rtscancache(IndexScanDesc s, ScanDirection dir) else res = (RetrieveIndexResult) NULL; + pfree (ip); + return (res); } -- 2.40.0