Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 88dc31e

Browse files
committed
First cut at recycling space in btree indexes. Still some rough edges
to fix, but it seems to basically work...
1 parent 2785491 commit 88dc31e

File tree

8 files changed

+745
-32
lines changed

8 files changed

+745
-32
lines changed

src/backend/access/common/indextuple.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/access/common/indextuple.c,v 1.63 2002/11/13 00:39:46 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/access/common/indextuple.c,v 1.64 2003/02/23 06:17:12 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -394,17 +394,16 @@ nocache_index_getattr(IndexTuple tup,
394394
}
395395

396396
/*
397-
* Copies source into target. If *target == NULL, we palloc space; otherwise
398-
* we assume we have space that is already palloc'ed.
397+
* Create a palloc'd copy of an index tuple.
399398
*/
400-
void
401-
CopyIndexTuple(IndexTuple source, IndexTuple *target)
399+
IndexTuple
400+
CopyIndexTuple(IndexTuple source)
402401
{
402+
IndexTuple result;
403403
Size size;
404404

405405
size = IndexTupleSize(source);
406-
if (*target == NULL)
407-
*target = (IndexTuple) palloc(size);
408-
409-
memmove((char *) *target, (char *) source, size);
406+
result = (IndexTuple) palloc(size);
407+
memcpy(result, source, size);
408+
return result;
410409
}

src/backend/access/nbtree/nbtinsert.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.98 2003/02/22 00:45:03 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.99 2003/02/23 06:17:13 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -58,7 +58,6 @@ static OffsetNumber _bt_findsplitloc(Relation rel, Page page,
5858
static void _bt_checksplitloc(FindSplitData *state, OffsetNumber firstright,
5959
int leftfree, int rightfree,
6060
bool newitemonleft, Size firstrightitemsz);
61-
static Buffer _bt_getstackbuf(Relation rel, BTStack stack, int access);
6261
static void _bt_pgaddtup(Relation rel, Page page,
6362
Size itemsize, BTItem btitem,
6463
OffsetNumber itup_off, const char *where);
@@ -666,7 +665,6 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
666665
rightoff;
667666
OffsetNumber maxoff;
668667
OffsetNumber i;
669-
BTItem lhikey;
670668

671669
rbuf = _bt_getbuf(rel, P_NEW, BT_WRITE);
672670
origpage = BufferGetPage(buf);
@@ -730,7 +728,6 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
730728
itemsz = ItemIdGetLength(itemid);
731729
item = (BTItem) PageGetItem(origpage, itemid);
732730
}
733-
lhikey = item;
734731
if (PageAddItem(leftpage, (Item) item, itemsz, leftoff,
735732
LP_USED) == InvalidOffsetNumber)
736733
elog(PANIC, "btree: failed to add hikey to the left sibling");
@@ -1262,7 +1259,7 @@ _bt_insert_parent(Relation rel,
12621259
*
12631260
* Returns InvalidBuffer if item not found (should not happen).
12641261
*/
1265-
static Buffer
1262+
Buffer
12661263
_bt_getstackbuf(Relation rel, BTStack stack, int access)
12671264
{
12681265
BlockNumber blkno;

0 commit comments

Comments
 (0)