Minor code cleanup/beautification in RelationPutHeapTuple.

This commit is contained in:
Tom Lane 2001-07-13 22:52:58 +00:00
parent 379ac0d03a
commit 20ca834ce9
1 changed files with 11 additions and 15 deletions

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Id: hio.c,v 1.41 2001/06/29 21:08:23 tgl Exp $ * $Id: hio.c,v 1.42 2001/07/13 22:52:58 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -25,8 +25,7 @@
* *
* !!! ELOG(ERROR) IS DISALLOWED HERE !!! * !!! ELOG(ERROR) IS DISALLOWED HERE !!!
* *
* Note - we assume that caller hold BUFFER_LOCK_EXCLUSIVE on the buffer. * Note - caller must hold BUFFER_LOCK_EXCLUSIVE on the buffer.
*
*/ */
void void
RelationPutHeapTuple(Relation relation, RelationPutHeapTuple(Relation relation,
@ -35,7 +34,6 @@ RelationPutHeapTuple(Relation relation,
{ {
Page pageHeader; Page pageHeader;
OffsetNumber offnum; OffsetNumber offnum;
Size len;
ItemId itemId; ItemId itemId;
Item item; Item item;
@ -45,24 +43,22 @@ RelationPutHeapTuple(Relation relation,
IncrHeapAccessStat(local_RelationPutHeapTuple); IncrHeapAccessStat(local_RelationPutHeapTuple);
IncrHeapAccessStat(global_RelationPutHeapTuple); IncrHeapAccessStat(global_RelationPutHeapTuple);
pageHeader = (Page) BufferGetPage(buffer); /* Add the tuple to the page */
len = MAXALIGN(tuple->t_len); /* be conservative */ pageHeader = BufferGetPage(buffer);
Assert(len <= PageGetFreeSpace(pageHeader));
offnum = PageAddItem((Page) pageHeader, (Item) tuple->t_data, offnum = PageAddItem(pageHeader, (Item) tuple->t_data,
tuple->t_len, InvalidOffsetNumber, LP_USED); tuple->t_len, InvalidOffsetNumber, LP_USED);
if (offnum == InvalidOffsetNumber) if (offnum == InvalidOffsetNumber)
elog(STOP, "RelationPutHeapTuple: failed to add tuple"); elog(STOP, "RelationPutHeapTuple: failed to add tuple");
itemId = PageGetItemId((Page) pageHeader, offnum); /* Update tuple->t_self to the actual position where it was stored */
item = PageGetItem((Page) pageHeader, itemId); ItemPointerSet(&(tuple->t_self), BufferGetBlockNumber(buffer), offnum);
ItemPointerSet(&((HeapTupleHeader) item)->t_ctid, /* Insert the correct position into CTID of the stored tuple, too */
BufferGetBlockNumber(buffer), offnum); itemId = PageGetItemId(pageHeader, offnum);
item = PageGetItem(pageHeader, itemId);
/* return an accurate tuple */ ((HeapTupleHeader) item)->t_ctid = tuple->t_self;
ItemPointerSet(&tuple->t_self, BufferGetBlockNumber(buffer), offnum);
} }
/* /*