*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.131 2006/01/17 00:09:00 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.132 2006/01/25 23:04:20 tgl Exp $
*
*-------------------------------------------------------------------------
*/
static Buffer _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf);
-static TransactionId _bt_check_unique(Relation rel, BTItem btitem,
+static TransactionId _bt_check_unique(Relation rel, IndexTuple itup,
Relation heapRel, Buffer buf,
ScanKey itup_scankey);
static void _bt_insertonpg(Relation rel, Buffer buf,
BTStack stack,
int keysz, ScanKey scankey,
- BTItem btitem,
+ IndexTuple itup,
OffsetNumber afteritem,
bool split_only_page);
static Buffer _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
OffsetNumber newitemoff, Size newitemsz,
- BTItem newitem, bool newitemonleft);
+ IndexTuple newitem, bool newitemonleft);
static OffsetNumber _bt_findsplitloc(Relation rel, Page page,
OffsetNumber newitemoff,
Size newitemsz,
int leftfree, int rightfree,
bool newitemonleft, Size firstrightitemsz);
static void _bt_pgaddtup(Relation rel, Page page,
- Size itemsize, BTItem btitem,
+ Size itemsize, IndexTuple itup,
OffsetNumber itup_off, const char *where);
static bool _bt_isequal(TupleDesc itupdesc, Page page, OffsetNumber offnum,
int keysz, ScanKey scankey);
/*
- * _bt_doinsert() -- Handle insertion of a single btitem in the tree.
+ * _bt_doinsert() -- Handle insertion of a single index tuple in the tree.
*
* This routine is called by the public interface routines, btbuild
- * and btinsert. By here, btitem is filled in, including the TID.
+ * and btinsert. By here, itup is filled in, including the TID.
*/
void
-_bt_doinsert(Relation rel, BTItem btitem,
+_bt_doinsert(Relation rel, IndexTuple itup,
bool index_is_unique, Relation heapRel)
{
- IndexTuple itup = &(btitem->bti_itup);
int natts = rel->rd_rel->relnatts;
ScanKey itup_scankey;
BTStack stack;
{
TransactionId xwait;
- xwait = _bt_check_unique(rel, btitem, heapRel, buf, itup_scankey);
+ xwait = _bt_check_unique(rel, itup, heapRel, buf, itup_scankey);
if (TransactionIdIsValid(xwait))
{
}
/* do the insertion */
- _bt_insertonpg(rel, buf, stack, natts, itup_scankey, btitem, 0, false);
+ _bt_insertonpg(rel, buf, stack, natts, itup_scankey, itup, 0, false);
/* be tidy */
_bt_freestack(stack);
* conflict is detected, no return --- just ereport().
*/
static TransactionId
-_bt_check_unique(Relation rel, BTItem btitem, Relation heapRel,
+_bt_check_unique(Relation rel, IndexTuple itup, Relation heapRel,
Buffer buf, ScanKey itup_scankey)
{
TupleDesc itupdesc = RelationGetDescr(rel);
HeapTupleData htup;
Buffer hbuffer;
ItemId curitemid;
- BTItem cbti;
+ IndexTuple curitup;
BlockNumber nblkno;
/*
break; /* we're past all the equal tuples */
/* okay, we gotta fetch the heap tuple ... */
- cbti = (BTItem) PageGetItem(page, curitemid);
- htup.t_self = cbti->bti_itup.t_tid;
+ curitup = (IndexTuple) PageGetItem(page, curitemid);
+ htup.t_self = curitup->t_tid;
if (heap_fetch(heapRel, SnapshotDirty, &htup, &hbuffer,
true, NULL))
{
BTStack stack,
int keysz,
ScanKey scankey,
- BTItem btitem,
+ IndexTuple itup,
OffsetNumber afteritem,
bool split_only_page)
{
page = BufferGetPage(buf);
lpageop = (BTPageOpaque) PageGetSpecialPointer(page);
- itemsz = IndexTupleDSize(btitem->bti_itup)
- + (sizeof(BTItemData) - sizeof(IndexTupleData));
-
+ itemsz = IndexTupleDSize(*itup);
itemsz = MAXALIGN(itemsz); /* be safe, PageAddItem will do this but we
* need to be consistent */
/* split the buffer into left and right halves */
rbuf = _bt_split(rel, buf, firstright,
- newitemoff, itemsz, btitem, newitemonleft);
+ newitemoff, itemsz, itup, newitemonleft);
/*----------
* By here,
/* Do the update. No ereport(ERROR) until changes are logged */
START_CRIT_SECTION();
- _bt_pgaddtup(rel, page, itemsz, btitem, newitemoff, "page");
+ _bt_pgaddtup(rel, page, itemsz, itup, newitemoff, "page");
if (BufferIsValid(metabuf))
{
XLogRecPtr recptr;
XLogRecData rdata[3];
XLogRecData *nextrdata;
- BTItemData truncitem;
+ IndexTupleData trunctuple;
xlrec.target.node = rel->rd_node;
ItemPointerSet(&(xlrec.target.tid), itup_blkno, itup_off);
/* Read comments in _bt_pgaddtup */
if (!P_ISLEAF(lpageop) && newitemoff == P_FIRSTDATAKEY(lpageop))
{
- truncitem = *btitem;
- truncitem.bti_itup.t_info = sizeof(BTItemData);
- nextrdata->data = (char *) &truncitem;
- nextrdata->len = sizeof(BTItemData);
+ trunctuple = *itup;
+ trunctuple.t_info = sizeof(IndexTupleData);
+ nextrdata->data = (char *) &trunctuple;
+ nextrdata->len = sizeof(IndexTupleData);
}
else
{
- nextrdata->data = (char *) btitem;
- nextrdata->len = IndexTupleDSize(btitem->bti_itup) +
- (sizeof(BTItemData) - sizeof(IndexTupleData));
+ nextrdata->data = (char *) itup;
+ nextrdata->len = IndexTupleDSize(*itup);
}
nextrdata->buffer = buf;
nextrdata->buffer_std = true;
*/
static Buffer
_bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
- OffsetNumber newitemoff, Size newitemsz, BTItem newitem,
+ OffsetNumber newitemoff, Size newitemsz, IndexTuple newitem,
bool newitemonleft)
{
Buffer rbuf;
BlockNumber itup_blkno = 0;
Size itemsz;
ItemId itemid;
- BTItem item;
+ IndexTuple item;
OffsetNumber leftoff,
rightoff;
OffsetNumber maxoff;
{
itemid = PageGetItemId(origpage, P_HIKEY);
itemsz = ItemIdGetLength(itemid);
- item = (BTItem) PageGetItem(origpage, itemid);
+ item = (IndexTuple) PageGetItem(origpage, itemid);
if (PageAddItem(rightpage, (Item) item, itemsz, rightoff,
LP_USED) == InvalidOffsetNumber)
elog(PANIC, "failed to add hikey to the right sibling");
/* existing item at firstright will become first on right page */
itemid = PageGetItemId(origpage, firstright);
itemsz = ItemIdGetLength(itemid);
- item = (BTItem) PageGetItem(origpage, itemid);
+ item = (IndexTuple) PageGetItem(origpage, itemid);
}
if (PageAddItem(leftpage, (Item) item, itemsz, leftoff,
LP_USED) == InvalidOffsetNumber)
{
itemid = PageGetItemId(origpage, i);
itemsz = ItemIdGetLength(itemid);
- item = (BTItem) PageGetItem(origpage, itemid);
+ item = (IndexTuple) PageGetItem(origpage, itemid);
/* does new item belong before this one? */
if (i == newitemoff)
*/
if (!state->is_leaf)
rightfree += (int) firstrightitemsz -
- (int) (MAXALIGN(sizeof(BTItemData)) + sizeof(ItemIdData));
+ (int) (MAXALIGN(sizeof(IndexTupleData)) + sizeof(ItemIdData));
/*
* If feasible split point, remember best delta.
BlockNumber bknum = BufferGetBlockNumber(buf);
BlockNumber rbknum = BufferGetBlockNumber(rbuf);
Page page = BufferGetPage(buf);
- BTItem new_item;
+ IndexTuple new_item;
BTStackData fakestack;
- BTItem ritem;
+ IndexTuple ritem;
Buffer pbuf;
if (stack == NULL)
stack = &fakestack;
stack->bts_blkno = BufferGetBlockNumber(pbuf);
stack->bts_offset = InvalidOffsetNumber;
- /* bts_btitem will be initialized below */
+ /* bts_btentry will be initialized below */
stack->bts_parent = NULL;
_bt_relbuf(rel, pbuf);
}
/* get high key from left page == lowest key on new right page */
- ritem = (BTItem) PageGetItem(page,
- PageGetItemId(page, P_HIKEY));
+ ritem = (IndexTuple) PageGetItem(page,
+ PageGetItemId(page, P_HIKEY));
/* form an index tuple that points at the new right page */
- new_item = _bt_formitem(&(ritem->bti_itup));
- ItemPointerSet(&(new_item->bti_itup.t_tid), rbknum, P_HIKEY);
+ new_item = CopyIndexTuple(ritem);
+ ItemPointerSet(&(new_item->t_tid), rbknum, P_HIKEY);
/*
* Find the parent buffer and get the parent page.
* want to find parent pointing to where we are, right ? - vadim
* 05/27/97
*/
- ItemPointerSet(&(stack->bts_btitem.bti_itup.t_tid),
- bknum, P_HIKEY);
+ ItemPointerSet(&(stack->bts_btentry.t_tid), bknum, P_HIKEY);
pbuf = _bt_getstackbuf(rel, stack, BT_WRITE);
minoff,
maxoff;
ItemId itemid;
- BTItem item;
+ IndexTuple item;
minoff = P_FIRSTDATAKEY(opaque);
maxoff = PageGetMaxOffsetNumber(page);
offnum = OffsetNumberNext(offnum))
{
itemid = PageGetItemId(page, offnum);
- item = (BTItem) PageGetItem(page, itemid);
- if (BTItemSame(item, &stack->bts_btitem))
+ item = (IndexTuple) PageGetItem(page, itemid);
+ if (BTEntrySame(item, &stack->bts_btentry))
{
/* Return accurate pointer to where link is now */
stack->bts_blkno = blkno;
offnum = OffsetNumberPrev(offnum))
{
itemid = PageGetItemId(page, offnum);
- item = (BTItem) PageGetItem(page, itemid);
- if (BTItemSame(item, &stack->bts_btitem))
+ item = (IndexTuple) PageGetItem(page, itemid);
+ if (BTEntrySame(item, &stack->bts_btentry))
{
/* Return accurate pointer to where link is now */
stack->bts_blkno = blkno;
BlockNumber rootblknum;
BTPageOpaque rootopaque;
ItemId itemid;
- BTItem item;
+ IndexTuple item;
Size itemsz;
- BTItem new_item;
+ IndexTuple new_item;
Buffer metabuf;
Page metapg;
BTMetaPageData *metad;
* first item in a non-leaf page, it implicitly has minus-infinity key
* value, so we need not store any actual key in it.
*/
- itemsz = sizeof(BTItemData);
- new_item = (BTItem) palloc(itemsz);
- new_item->bti_itup.t_info = itemsz;
- ItemPointerSet(&(new_item->bti_itup.t_tid), lbkno, P_HIKEY);
+ itemsz = sizeof(IndexTupleData);
+ new_item = (IndexTuple) palloc(itemsz);
+ new_item->t_info = itemsz;
+ ItemPointerSet(&(new_item->t_tid), lbkno, P_HIKEY);
/*
* Insert the left page pointer into the new root page. The root page is
*/
itemid = PageGetItemId(lpage, P_HIKEY);
itemsz = ItemIdGetLength(itemid);
- item = (BTItem) PageGetItem(lpage, itemid);
- new_item = _bt_formitem(&(item->bti_itup));
- ItemPointerSet(&(new_item->bti_itup.t_tid), rbkno, P_HIKEY);
+ item = (IndexTuple) PageGetItem(lpage, itemid);
+ new_item = CopyIndexTuple(item);
+ ItemPointerSet(&(new_item->t_tid), rbkno, P_HIKEY);
/*
* insert the right page pointer into the new root page.
* the buffer afterwards, either.
*
* The main difference between this routine and a bare PageAddItem call
- * is that this code knows that the leftmost data item on a non-leaf
+ * is that this code knows that the leftmost index tuple on a non-leaf
* btree page doesn't need to have a key. Therefore, it strips such
- * items down to just the item header. CAUTION: this works ONLY if
- * we insert the items in order, so that the given itup_off does
- * represent the final position of the item!
+ * tuples down to just the tuple header. CAUTION: this works ONLY if
+ * we insert the tuples in order, so that the given itup_off does
+ * represent the final position of the tuple!
*/
static void
_bt_pgaddtup(Relation rel,
Page page,
Size itemsize,
- BTItem btitem,
+ IndexTuple itup,
OffsetNumber itup_off,
const char *where)
{
BTPageOpaque opaque = (BTPageOpaque) PageGetSpecialPointer(page);
- BTItemData truncitem;
+ IndexTupleData trunctuple;
if (!P_ISLEAF(opaque) && itup_off == P_FIRSTDATAKEY(opaque))
{
- memcpy(&truncitem, btitem, sizeof(BTItemData));
- truncitem.bti_itup.t_info = sizeof(BTItemData);
- btitem = &truncitem;
- itemsize = sizeof(BTItemData);
+ trunctuple = *itup;
+ trunctuple.t_info = sizeof(IndexTupleData);
+ itup = &trunctuple;
+ itemsize = sizeof(IndexTupleData);
}
- if (PageAddItem(page, (Item) btitem, itemsize, itup_off,
+ if (PageAddItem(page, (Item) itup, itemsize, itup_off,
LP_USED) == InvalidOffsetNumber)
elog(PANIC, "failed to add item to the %s for \"%s\"",
where, RelationGetRelationName(rel));
_bt_isequal(TupleDesc itupdesc, Page page, OffsetNumber offnum,
int keysz, ScanKey scankey)
{
- BTItem btitem;
IndexTuple itup;
int i;
/* Better be comparing to a leaf item */
Assert(P_ISLEAF((BTPageOpaque) PageGetSpecialPointer(page)));
- btitem = (BTItem) PageGetItem(page, PageGetItemId(page, offnum));
- itup = &(btitem->bti_itup);
+ itup = (IndexTuple) PageGetItem(page, PageGetItemId(page, offnum));
for (i = 1; i <= keysz; i++)
{
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtpage.c,v 1.91 2006/01/17 00:09:01 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtpage.c,v 1.92 2006/01/25 23:04:20 tgl Exp $
*
* NOTES
* Postgres btree pages look like ordinary relation pages. The opaque
uint32 targetlevel,
ilevel;
ItemId itemid;
- BTItem targetkey,
- btitem;
+ IndexTuple targetkey,
+ itup;
ScanKey itup_scankey;
BTStack stack;
Buffer lbuf,
targetlevel = opaque->btpo.level;
leftsib = opaque->btpo_prev;
itemid = PageGetItemId(page, P_HIKEY);
- targetkey = CopyBTItem((BTItem) PageGetItem(page, itemid));
+ targetkey = CopyIndexTuple((IndexTuple) PageGetItem(page, itemid));
/*
* We need to get an approximate pointer to the page's parent page. Use
*/
_bt_relbuf(rel, buf);
/* we need an insertion scan key to do our search, so build one */
- itup_scankey = _bt_mkscankey(rel, &(targetkey->bti_itup));
+ itup_scankey = _bt_mkscankey(rel, targetkey);
/* find the leftmost leaf page containing this key */
stack = _bt_search(rel, rel->rd_rel->relnatts, itup_scankey, false,
&lbuf, BT_READ);
* Next find and write-lock the current parent of the target page. This is
* essentially the same as the corresponding step of splitting.
*/
- ItemPointerSet(&(stack->bts_btitem.bti_itup.t_tid),
- target, P_HIKEY);
+ ItemPointerSet(&(stack->bts_btentry.t_tid), target, P_HIKEY);
pbuf = _bt_getstackbuf(rel, stack, BT_WRITE);
if (pbuf == InvalidBuffer)
elog(ERROR, "failed to re-find parent key in \"%s\"",
OffsetNumber nextoffset;
itemid = PageGetItemId(page, poffset);
- btitem = (BTItem) PageGetItem(page, itemid);
- Assert(ItemPointerGetBlockNumber(&(btitem->bti_itup.t_tid)) == target);
- ItemPointerSet(&(btitem->bti_itup.t_tid), rightsib, P_HIKEY);
+ itup = (IndexTuple) PageGetItem(page, itemid);
+ Assert(ItemPointerGetBlockNumber(&(itup->t_tid)) == target);
+ ItemPointerSet(&(itup->t_tid), rightsib, P_HIKEY);
nextoffset = OffsetNumberNext(poffset);
/* This part is just for double-checking */
itemid = PageGetItemId(page, nextoffset);
- btitem = (BTItem) PageGetItem(page, itemid);
- if (ItemPointerGetBlockNumber(&(btitem->bti_itup.t_tid)) != rightsib)
+ itup = (IndexTuple) PageGetItem(page, itemid);
+ if (ItemPointerGetBlockNumber(&(itup->t_tid)) != rightsib)
elog(PANIC, "right sibling is not next child in \"%s\"",
RelationGetRelationName(rel));
PageIndexTupleDelete(page, nextoffset);
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.135 2005/12/07 19:37:53 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.136 2006/01/25 23:04:20 tgl Exp $
*
*-------------------------------------------------------------------------
*/
{
BTBuildState *buildstate = (BTBuildState *) state;
IndexTuple itup;
- BTItem btitem;
/* form an index tuple and point it at the heap tuple */
itup = index_form_tuple(RelationGetDescr(index), values, isnull);
itup->t_tid = htup->t_self;
- btitem = _bt_formitem(itup);
-
/*
* if we are doing bottom-up btree build, we insert the index into a spool
* file for subsequent processing. otherwise, we insert into the btree.
if (buildstate->usefast)
{
if (tupleIsAlive || buildstate->spool2 == NULL)
- _bt_spool(btitem, buildstate->spool);
+ _bt_spool(itup, buildstate->spool);
else
{
/* dead tuples are put into spool2 */
buildstate->haveDead = true;
- _bt_spool(btitem, buildstate->spool2);
+ _bt_spool(itup, buildstate->spool2);
}
}
else
{
- _bt_doinsert(index, btitem,
+ _bt_doinsert(index, itup,
buildstate->isUnique, buildstate->heapRel);
}
buildstate->indtuples += 1;
- pfree(btitem);
pfree(itup);
}
ItemPointer ht_ctid = (ItemPointer) PG_GETARG_POINTER(3);
Relation heapRel = (Relation) PG_GETARG_POINTER(4);
bool checkUnique = PG_GETARG_BOOL(5);
- BTItem btitem;
IndexTuple itup;
/* generate an index tuple */
itup = index_form_tuple(RelationGetDescr(rel), values, isnull);
itup->t_tid = *ht_ctid;
- btitem = _bt_formitem(itup);
- _bt_doinsert(rel, btitem, checkUnique, heapRel);
+ _bt_doinsert(rel, itup, checkUnique, heapRel);
- pfree(btitem);
pfree(itup);
PG_RETURN_BOOL(true);
offnum <= maxoff;
offnum = OffsetNumberNext(offnum))
{
- BTItem btitem;
+ IndexTuple itup;
ItemPointer htup;
- btitem = (BTItem) PageGetItem(page,
- PageGetItemId(page, offnum));
- htup = &(btitem->bti_itup.t_tid);
+ itup = (IndexTuple)
+ PageGetItem(page, PageGetItemId(page, offnum));
+ htup = &(itup->t_tid);
if (callback(htup, callback_state))
{
deletable[ndeletable++] = offnum;
BTPageOpaque opaque;
Buffer nextbuf;
ItemPointer target = &(so->curHeapIptr);
- BTItem item;
+ IndexTuple itup;
BlockNumber blkno;
/*
offnum <= maxoff;
offnum = OffsetNumberNext(offnum))
{
- item = (BTItem) PageGetItem(page, PageGetItemId(page, offnum));
- if (BTTidSame(item->bti_itup.t_tid, *target))
+ itup = (IndexTuple) PageGetItem(page, PageGetItemId(page, offnum));
+ if (BTTidSame(itup->t_tid, *target))
{
/* Found it */
current->ip_posid = offnum;
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.102 2006/01/25 20:29:23 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.103 2006/01/25 23:04:20 tgl Exp $
*
*-------------------------------------------------------------------------
*/
BTPageOpaque opaque;
OffsetNumber offnum;
ItemId itemid;
- BTItem btitem;
IndexTuple itup;
BlockNumber blkno;
BlockNumber par_blkno;
*/
offnum = _bt_binsrch(rel, *bufP, keysz, scankey, nextkey);
itemid = PageGetItemId(page, offnum);
- btitem = (BTItem) PageGetItem(page, itemid);
- itup = &(btitem->bti_itup);
+ itup = (IndexTuple) PageGetItem(page, itemid);
blkno = ItemPointerGetBlockNumber(&(itup->t_tid));
par_blkno = BufferGetBlockNumber(*bufP);
new_stack = (BTStack) palloc(sizeof(BTStackData));
new_stack->bts_blkno = par_blkno;
new_stack->bts_offset = offnum;
- memcpy(&new_stack->bts_btitem, btitem, sizeof(BTItemData));
+ memcpy(&new_stack->bts_btentry, itup, sizeof(IndexTupleData));
new_stack->bts_parent = stack_in;
/* drop the read lock on the parent page, acquire one on the child */
{
TupleDesc itupdesc = RelationGetDescr(rel);
BTPageOpaque opaque = (BTPageOpaque) PageGetSpecialPointer(page);
- BTItem btitem;
IndexTuple itup;
int i;
if (!P_ISLEAF(opaque) && offnum == P_FIRSTDATAKEY(opaque))
return 1;
- btitem = (BTItem) PageGetItem(page, PageGetItemId(page, offnum));
- itup = &(btitem->bti_itup);
+ itup = (IndexTuple) PageGetItem(page, PageGetItemId(page, offnum));
/*
* The scan key is set up with the attribute number associated with each
BTPageOpaque opaque;
OffsetNumber offnum;
BlockNumber blkno;
- BTItem btitem;
IndexTuple itup;
/*
else
offnum = P_FIRSTDATAKEY(opaque);
- btitem = (BTItem) PageGetItem(page, PageGetItemId(page, offnum));
- itup = &(btitem->bti_itup);
+ itup = (IndexTuple) PageGetItem(page, PageGetItemId(page, offnum));
blkno = ItemPointerGetBlockNumber(&(itup->t_tid));
buf = _bt_relandgetbuf(rel, buf, blkno, BT_READ);
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsort.c,v 1.97 2006/01/07 22:45:41 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsort.c,v 1.98 2006/01/25 23:04:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
{
Page btps_page; /* workspace for page building */
BlockNumber btps_blkno; /* block # to write this page at */
- BTItem btps_minkey; /* copy of minimum key (first item) on page */
+ IndexTuple btps_minkey; /* copy of minimum key (first item) on page */
OffsetNumber btps_lastoff; /* last item offset loaded */
uint32 btps_level; /* tree level (0 = leaf) */
Size btps_full; /* "full" if less than this much free space */
} BTWriteState;
-#define BTITEMSZ(btitem) \
- ((btitem) ? \
- (IndexTupleDSize((btitem)->bti_itup) + \
- (sizeof(BTItemData) - sizeof(IndexTupleData))) : \
- 0)
-
-
static Page _bt_blnewpage(uint32 level);
static BTPageState *_bt_pagestate(BTWriteState *wstate, uint32 level);
static void _bt_slideleft(Page page);
static void _bt_sortaddtup(Page page, Size itemsize,
- BTItem btitem, OffsetNumber itup_off);
-static void _bt_buildadd(BTWriteState *wstate, BTPageState *state, BTItem bti);
+ IndexTuple itup, OffsetNumber itup_off);
+static void _bt_buildadd(BTWriteState *wstate, BTPageState *state,
+ IndexTuple itup);
static void _bt_uppershutdown(BTWriteState *wstate, BTPageState *state);
static void _bt_load(BTWriteState *wstate,
BTSpool *btspool, BTSpool *btspool2);
btspool->sortstate = tuplesort_begin_index(index, isunique,
btKbytes, false);
- /*
- * Currently, tuplesort provides sort functions on IndexTuples. If we kept
- * anything in a BTItem other than a regular IndexTuple, we'd need to
- * modify tuplesort to understand BTItems as such.
- */
- Assert(sizeof(BTItemData) == sizeof(IndexTupleData));
-
return btspool;
}
}
/*
- * spool a btitem into the sort file.
+ * spool an index entry into the sort file.
*/
void
-_bt_spool(BTItem btitem, BTSpool *btspool)
+_bt_spool(IndexTuple itup, BTSpool *btspool)
{
- /* A BTItem is really just an IndexTuple */
- tuplesort_puttuple(btspool->sortstate, (void *) btitem);
+ tuplesort_puttuple(btspool->sortstate, (void *) itup);
}
/*
static void
_bt_sortaddtup(Page page,
Size itemsize,
- BTItem btitem,
+ IndexTuple itup,
OffsetNumber itup_off)
{
BTPageOpaque opaque = (BTPageOpaque) PageGetSpecialPointer(page);
- BTItemData truncitem;
+ IndexTupleData trunctuple;
if (!P_ISLEAF(opaque) && itup_off == P_FIRSTKEY)
{
- memcpy(&truncitem, btitem, sizeof(BTItemData));
- truncitem.bti_itup.t_info = sizeof(BTItemData);
- btitem = &truncitem;
- itemsize = sizeof(BTItemData);
+ trunctuple = *itup;
+ trunctuple.t_info = sizeof(IndexTupleData);
+ itup = &trunctuple;
+ itemsize = sizeof(IndexTupleData);
}
- if (PageAddItem(page, (Item) btitem, itemsize, itup_off,
+ if (PageAddItem(page, (Item) itup, itemsize, itup_off,
LP_USED) == InvalidOffsetNumber)
elog(ERROR, "failed to add item to the index page");
}
*----------
*/
static void
-_bt_buildadd(BTWriteState *wstate, BTPageState *state, BTItem bti)
+_bt_buildadd(BTWriteState *wstate, BTPageState *state, IndexTuple itup)
{
Page npage;
BlockNumber nblkno;
OffsetNumber last_off;
Size pgspc;
- Size btisz;
+ Size itupsz;
npage = state->btps_page;
nblkno = state->btps_blkno;
last_off = state->btps_lastoff;
pgspc = PageGetFreeSpace(npage);
- btisz = BTITEMSZ(bti);
- btisz = MAXALIGN(btisz);
+ itupsz = IndexTupleDSize(*itup);
+ itupsz = MAXALIGN(itupsz);
/*
* Check whether the item can fit on a btree page at all. (Eventually, we
* ought to try to apply TOAST methods if not.) We actually need to be
* able to fit three items on every page, so restrict any one item to 1/3
- * the per-page available space. Note that at this point, btisz doesn't
+ * the per-page available space. Note that at this point, itupsz doesn't
* include the ItemId.
*
* NOTE: similar code appears in _bt_insertonpg() to defend against
* oversize items being inserted into an already-existing index. But
* during creation of an index, we don't go through there.
*/
- if (btisz > BTMaxItemSize(npage))
+ if (itupsz > BTMaxItemSize(npage))
ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("index row size %lu exceeds btree maximum, %lu",
- (unsigned long) btisz,
+ (unsigned long) itupsz,
(unsigned long) BTMaxItemSize(npage)),
errhint("Values larger than 1/3 of a buffer page cannot be indexed.\n"
"Consider a function index of an MD5 hash of the value, "
"or use full text indexing.")));
- if (pgspc < btisz || pgspc < state->btps_full)
+ if (pgspc < itupsz || pgspc < state->btps_full)
{
/*
* Item won't fit on this page, or we feel the page is full enough
BlockNumber oblkno = nblkno;
ItemId ii;
ItemId hii;
- BTItem obti;
+ IndexTuple oitup;
/* Create new page of same level */
npage = _bt_blnewpage(state->btps_level);
*/
Assert(last_off > P_FIRSTKEY);
ii = PageGetItemId(opage, last_off);
- obti = (BTItem) PageGetItem(opage, ii);
- _bt_sortaddtup(npage, ItemIdGetLength(ii), obti, P_FIRSTKEY);
+ oitup = (IndexTuple) PageGetItem(opage, ii);
+ _bt_sortaddtup(npage, ItemIdGetLength(ii), oitup, P_FIRSTKEY);
/*
* Move 'last' into the high key position on opage
state->btps_next = _bt_pagestate(wstate, state->btps_level + 1);
Assert(state->btps_minkey != NULL);
- ItemPointerSet(&(state->btps_minkey->bti_itup.t_tid),
- oblkno, P_HIKEY);
+ ItemPointerSet(&(state->btps_minkey->t_tid), oblkno, P_HIKEY);
_bt_buildadd(wstate, state->btps_next, state->btps_minkey);
pfree(state->btps_minkey);
* it off the old page, not the new one, in case we are not at leaf
* level.
*/
- state->btps_minkey = _bt_formitem(&(obti->bti_itup));
+ state->btps_minkey = CopyIndexTuple(oitup);
/*
* Set the sibling links for both pages.
if (last_off == P_HIKEY)
{
Assert(state->btps_minkey == NULL);
- state->btps_minkey = _bt_formitem(&(bti->bti_itup));
+ state->btps_minkey = CopyIndexTuple(itup);
}
/*
* Add the new item into the current page.
*/
last_off = OffsetNumberNext(last_off);
- _bt_sortaddtup(npage, btisz, bti, last_off);
+ _bt_sortaddtup(npage, itupsz, itup, last_off);
state->btps_page = npage;
state->btps_blkno = nblkno;
else
{
Assert(s->btps_minkey != NULL);
- ItemPointerSet(&(s->btps_minkey->bti_itup.t_tid),
- blkno, P_HIKEY);
+ ItemPointerSet(&(s->btps_minkey->t_tid), blkno, P_HIKEY);
_bt_buildadd(wstate, s->btps_next, s->btps_minkey);
pfree(s->btps_minkey);
s->btps_minkey = NULL;
{
BTPageState *state = NULL;
bool merge = (btspool2 != NULL);
- BTItem bti,
- bti2 = NULL;
+ IndexTuple itup,
+ itup2 = NULL;
bool should_free,
should_free2,
load1;
*/
/* the preparation of merge */
- bti = (BTItem) tuplesort_getindextuple(btspool->sortstate,
- true, &should_free);
- bti2 = (BTItem) tuplesort_getindextuple(btspool2->sortstate,
- true, &should_free2);
+ itup = tuplesort_getindextuple(btspool->sortstate,
+ true, &should_free);
+ itup2 = tuplesort_getindextuple(btspool2->sortstate,
+ true, &should_free2);
indexScanKey = _bt_mkscankey_nodata(wstate->index);
for (;;)
{
load1 = true; /* load BTSpool next ? */
- if (bti2 == NULL)
+ if (itup2 == NULL)
{
- if (bti == NULL)
+ if (itup == NULL)
break;
}
- else if (bti != NULL)
+ else if (itup != NULL)
{
for (i = 1; i <= keysz; i++)
{
isSecondNull;
entry = indexScanKey + i - 1;
- attrDatum1 = index_getattr((IndexTuple) bti, i, tupdes,
+ attrDatum1 = index_getattr(itup, i, tupdes,
&isFirstNull);
- attrDatum2 = index_getattr((IndexTuple) bti2, i, tupdes,
+ attrDatum2 = index_getattr(itup2, i, tupdes,
&isSecondNull);
if (isFirstNull)
{
if (load1)
{
- _bt_buildadd(wstate, state, bti);
+ _bt_buildadd(wstate, state, itup);
if (should_free)
- pfree(bti);
- bti = (BTItem) tuplesort_getindextuple(btspool->sortstate,
- true, &should_free);
+ pfree(itup);
+ itup = tuplesort_getindextuple(btspool->sortstate,
+ true, &should_free);
}
else
{
- _bt_buildadd(wstate, state, bti2);
+ _bt_buildadd(wstate, state, itup2);
if (should_free2)
- pfree(bti2);
- bti2 = (BTItem) tuplesort_getindextuple(btspool2->sortstate,
- true, &should_free2);
+ pfree(itup2);
+ itup2 = tuplesort_getindextuple(btspool2->sortstate,
+ true, &should_free2);
}
}
_bt_freeskey(indexScanKey);
else
{
/* merge is unnecessary */
- while ((bti = (BTItem) tuplesort_getindextuple(btspool->sortstate,
- true, &should_free)) != NULL)
+ while ((itup = tuplesort_getindextuple(btspool->sortstate,
+ true, &should_free)) != NULL)
{
/* When we see first tuple, create first index page */
if (state == NULL)
state = _bt_pagestate(wstate, 0);
- _bt_buildadd(wstate, state, bti);
+ _bt_buildadd(wstate, state, itup);
if (should_free)
- pfree(bti);
+ pfree(itup);
}
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtutils.c,v 1.70 2006/01/25 20:29:23 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtutils.c,v 1.71 2006/01/25 23:04:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
}
}
-/*
- * Construct a BTItem from a plain IndexTuple.
- *
- * This is now useless code, since a BTItem *is* an index tuple with
- * no extra stuff. We hang onto it for the moment to preserve the
- * notational distinction, in case we want to add some extra stuff
- * again someday.
- */
-BTItem
-_bt_formitem(IndexTuple itup)
-{
- int nbytes_btitem;
- BTItem btitem;
- Size tuplen;
-
- /* make a copy of the index tuple with room for extra stuff */
- tuplen = IndexTupleSize(itup);
- nbytes_btitem = tuplen + (sizeof(BTItemData) - sizeof(IndexTupleData));
-
- btitem = (BTItem) palloc(nbytes_btitem);
- memcpy((char *) &(btitem->bti_itup), (char *) itup, tuplen);
-
- return btitem;
-}
/*----------
* _bt_preprocess_keys() -- Preprocess scan keys
{
ItemId iid = PageGetItemId(page, offnum);
bool tuple_valid;
- BTItem btitem;
IndexTuple tuple;
TupleDesc tupdesc;
BTScanOpaque so;
else
tuple_valid = true;
- btitem = (BTItem) PageGetItem(page, iid);
- tuple = &btitem->bti_itup;
+ tuple = (IndexTuple) PageGetItem(page, iid);
IncrIndexProcessed();
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtxlog.c,v 1.24 2005/10/18 01:06:23 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtxlog.c,v 1.25 2006/01/25 23:04:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
{
Buffer buffer;
Page page;
- BTItem btitem;
+ IndexTuple itup;
BlockNumber rightblk;
ListCell *l;
if (!BufferIsValid(buffer))
elog(PANIC, "forget_matching_split: block unfound");
page = (Page) BufferGetPage(buffer);
- btitem = (BTItem) PageGetItem(page, PageGetItemId(page, offnum));
- rightblk = ItemPointerGetBlockNumber(&(btitem->bti_itup.t_tid));
- Assert(ItemPointerGetOffsetNumber(&(btitem->bti_itup.t_tid)) == P_HIKEY);
+ itup = (IndexTuple) PageGetItem(page, PageGetItemId(page, offnum));
+ rightblk = ItemPointerGetBlockNumber(&(itup->t_tid));
+ Assert(ItemPointerGetOffsetNumber(&(itup->t_tid)) == P_HIKEY);
LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
ReleaseBuffer(buffer);
static void
_bt_restore_page(Page page, char *from, int len)
{
- BTItemData btdata;
+ IndexTupleData itupdata;
Size itemsz;
char *end = from + len;
for (; from < end;)
{
- memcpy(&btdata, from, sizeof(BTItemData));
- itemsz = IndexTupleDSize(btdata.bti_itup) +
- (sizeof(BTItemData) - sizeof(IndexTupleData));
+ /* Need to copy tuple header due to alignment considerations */
+ memcpy(&itupdata, from, sizeof(IndexTupleData));
+ itemsz = IndexTupleDSize(itupdata);
itemsz = MAXALIGN(itemsz);
if (PageAddItem(page, (Item) from, itemsz,
FirstOffsetNumber, LP_USED) == InvalidOffsetNumber)
else
{
ItemId itemid;
- BTItem btitem;
+ IndexTuple itup;
OffsetNumber nextoffset;
itemid = PageGetItemId(page, poffset);
- btitem = (BTItem) PageGetItem(page, itemid);
- ItemPointerSet(&(btitem->bti_itup.t_tid), rightsib, P_HIKEY);
+ itup = (IndexTuple) PageGetItem(page, itemid);
+ ItemPointerSet(&(itup->t_tid), rightsib, P_HIKEY);
nextoffset = OffsetNumberNext(poffset);
PageIndexTupleDelete(page, nextoffset);
}
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/access/nbtree.h,v 1.90 2006/01/23 22:31:41 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/access/nbtree.h,v 1.91 2006/01/25 23:04:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
MAXALIGN(sizeof(BTPageOpaqueData))) / 3 - sizeof(ItemIdData))
/*
- * BTItems are what we store in the btree. Each item is an index tuple,
- * including key and pointer values. (In some cases either the key or the
- * pointer may go unused, see backend/access/nbtree/README for details.)
+ * Test whether two btree entries are "the same".
*
* Old comments:
* In addition, we must guarantee that all tuples in the index are unique,
*
* New comments:
* actually, we must guarantee that all tuples in A LEVEL
- * are unique, not in ALL INDEX. So, we can use bti_itup->t_tid
+ * are unique, not in ALL INDEX. So, we can use the t_tid
* as unique identifier for a given index tuple (logical position
* within a level). - vadim 04/09/97
*/
-
-typedef struct BTItemData
-{
- IndexTupleData bti_itup;
-} BTItemData;
-
-typedef BTItemData *BTItem;
-
-#define CopyBTItem(btitem) ((BTItem) CopyIndexTuple((IndexTuple) (btitem)))
-
-/*
- * For XLOG: size without alignment. Sizeof works as long as
- * IndexTupleData has exactly 8 bytes.
- */
-#define SizeOfBTItem sizeof(BTItemData)
-
-/* Test whether items are the "same" per the above notes */
#define BTTidSame(i1, i2) \
( (i1).ip_blkid.bi_hi == (i2).ip_blkid.bi_hi && \
(i1).ip_blkid.bi_lo == (i2).ip_blkid.bi_lo && \
(i1).ip_posid == (i2).ip_posid )
-#define BTItemSame(i1, i2) \
- BTTidSame((i1)->bti_itup.t_tid, (i2)->bti_itup.t_tid)
+#define BTEntrySame(i1, i2) \
+ BTTidSame((i1)->t_tid, (i2)->t_tid)
/*
* XLOG allows to store some information in high 4 bits of log
* record xl_info field
*/
-#define XLOG_BTREE_INSERT_LEAF 0x00 /* add btitem without split */
+#define XLOG_BTREE_INSERT_LEAF 0x00 /* add index tuple without split */
#define XLOG_BTREE_INSERT_UPPER 0x10 /* same, on a non-leaf page */
#define XLOG_BTREE_INSERT_META 0x20 /* same, plus update metapage */
-#define XLOG_BTREE_SPLIT_L 0x30 /* add btitem with split */
+#define XLOG_BTREE_SPLIT_L 0x30 /* add index tuple with split */
#define XLOG_BTREE_SPLIT_R 0x40 /* as above, new item on right */
-#define XLOG_BTREE_SPLIT_L_ROOT 0x50 /* add btitem with split of root */
+#define XLOG_BTREE_SPLIT_L_ROOT 0x50 /* add tuple with split of root */
#define XLOG_BTREE_SPLIT_R_ROOT 0x60 /* as above, new item on right */
-#define XLOG_BTREE_DELETE 0x70 /* delete leaf btitem */
+#define XLOG_BTREE_DELETE 0x70 /* delete leaf index tuple */
#define XLOG_BTREE_DELETE_PAGE 0x80 /* delete an entire page */
-#define XLOG_BTREE_DELETE_PAGE_META 0x90 /* same, plus update metapage */
+#define XLOG_BTREE_DELETE_PAGE_META 0x90 /* same, plus update metapage */
#define XLOG_BTREE_NEWROOT 0xA0 /* new root page */
#define XLOG_BTREE_NEWMETA 0xB0 /* update metadata page */
{
xl_btreetid target; /* inserted tuple id */
/* xl_btree_metadata FOLLOWS IF XLOG_BTREE_INSERT_META */
- /* BTITEM FOLLOWS AT END OF STRUCT */
+ /* INDEX TUPLE FOLLOWS AT END OF STRUCT */
} xl_btree_insert;
#define SizeOfBtreeInsert (offsetof(xl_btreetid, tid) + SizeOfIptrData)
* whole page image.
*
* Note: the four XLOG_BTREE_SPLIT xl_info codes all use this data record.
- * The _L and _R variants indicate whether the inserted btitem went into the
+ * The _L and _R variants indicate whether the inserted tuple went into the
* left or right split page (and thus, whether otherblk is the right or left
* page of the split pair). The _ROOT variants indicate that we are splitting
* the root page, and thus that a newroot record rather than an insert or
#define SizeOfBtreeSplit (offsetof(xl_btree_split, leftlen) + sizeof(uint16))
/*
- * This is what we need to know about delete of individual leaf btitems.
- * The WAL record can represent deletion of any number of btitems on a
+ * This is what we need to know about delete of individual leaf index tuples.
+ * The WAL record can represent deletion of any number of index tuples on a
* single index page.
*/
typedef struct xl_btree_delete
#define SizeOfBtreeDeletePage (offsetof(xl_btree_delete_page, rightblk) + sizeof(BlockNumber))
/*
- * New root log record. There are zero btitems if this is to establish an
+ * New root log record. There are zero tuples if this is to establish an
* empty root, or two if it is the result of splitting an old root.
*
* Note that although this implies rewriting the metadata page, we don't need
RelFileNode node;
BlockNumber rootblk; /* location of new root */
uint32 level; /* its tree level */
- /* 0 or 2 BTITEMS FOLLOW AT END OF STRUCT */
+ /* 0 or 2 INDEX TUPLES FOLLOW AT END OF STRUCT */
} xl_btree_newroot;
#define SizeOfBtreeNewroot (offsetof(xl_btree_newroot, level) + sizeof(uint32))
{
BlockNumber bts_blkno;
OffsetNumber bts_offset;
- BTItemData bts_btitem;
+ IndexTupleData bts_btentry;
struct BTStackData *bts_parent;
} BTStackData;
/*
* prototypes for functions in nbtinsert.c
*/
-extern void _bt_doinsert(Relation rel, BTItem btitem,
+extern void _bt_doinsert(Relation rel, IndexTuple itup,
bool index_is_unique, Relation heapRel);
extern Buffer _bt_getstackbuf(Relation rel, BTStack stack, int access);
extern void _bt_insert_parent(Relation rel, Buffer buf, Buffer rbuf,
extern bool _bt_checkkeys(IndexScanDesc scan,
Page page, OffsetNumber offnum,
ScanDirection dir, bool *continuescan);
-extern BTItem _bt_formitem(IndexTuple itup);
/*
* prototypes for functions in nbtsort.c
extern BTSpool *_bt_spoolinit(Relation index, bool isunique, bool isdead);
extern void _bt_spooldestroy(BTSpool *btspool);
-extern void _bt_spool(BTItem btitem, BTSpool *btspool);
+extern void _bt_spool(IndexTuple itup, BTSpool *btspool);
extern void _bt_leafbuild(BTSpool *btspool, BTSpool *spool2);
/*