Skip to content

Commit 20ca834

Browse files
committed
Minor code cleanup/beautification in RelationPutHeapTuple.
1 parent 379ac0d commit 20ca834

File tree

1 file changed

+11
-15
lines changed
  • src/backend/access/heap

1 file changed

+11
-15
lines changed

src/backend/access/heap/hio.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Id: hio.c,v 1.41 2001/06/29 21:08:23 tgl Exp $
11+
* $Id: hio.c,v 1.42 2001/07/13 22:52:58 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -25,8 +25,7 @@
2525
*
2626
* !!! ELOG(ERROR) IS DISALLOWED HERE !!!
2727
*
28-
* Note - we assume that caller hold BUFFER_LOCK_EXCLUSIVE on the buffer.
29-
*
28+
* Note - caller must hold BUFFER_LOCK_EXCLUSIVE on the buffer.
3029
*/
3130
void
3231
RelationPutHeapTuple(Relation relation,
@@ -35,7 +34,6 @@ RelationPutHeapTuple(Relation relation,
3534
{
3635
Page pageHeader;
3736
OffsetNumber offnum;
38-
Size len;
3937
ItemId itemId;
4038
Item item;
4139

@@ -45,24 +43,22 @@ RelationPutHeapTuple(Relation relation,
4543
IncrHeapAccessStat(local_RelationPutHeapTuple);
4644
IncrHeapAccessStat(global_RelationPutHeapTuple);
4745

48-
pageHeader = (Page) BufferGetPage(buffer);
49-
len = MAXALIGN(tuple->t_len); /* be conservative */
50-
Assert(len <= PageGetFreeSpace(pageHeader));
46+
/* Add the tuple to the page */
47+
pageHeader = BufferGetPage(buffer);
5148

52-
offnum = PageAddItem((Page) pageHeader, (Item) tuple->t_data,
49+
offnum = PageAddItem(pageHeader, (Item) tuple->t_data,
5350
tuple->t_len, InvalidOffsetNumber, LP_USED);
5451

5552
if (offnum == InvalidOffsetNumber)
5653
elog(STOP, "RelationPutHeapTuple: failed to add tuple");
5754

58-
itemId = PageGetItemId((Page) pageHeader, offnum);
59-
item = PageGetItem((Page) pageHeader, itemId);
60-
61-
ItemPointerSet(&((HeapTupleHeader) item)->t_ctid,
62-
BufferGetBlockNumber(buffer), offnum);
55+
/* Update tuple->t_self to the actual position where it was stored */
56+
ItemPointerSet(&(tuple->t_self), BufferGetBlockNumber(buffer), offnum);
6357

64-
/* return an accurate tuple */
65-
ItemPointerSet(&tuple->t_self, BufferGetBlockNumber(buffer), offnum);
58+
/* Insert the correct position into CTID of the stored tuple, too */
59+
itemId = PageGetItemId(pageHeader, offnum);
60+
item = PageGetItem(pageHeader, itemId);
61+
((HeapTupleHeader) item)->t_ctid = tuple->t_self;
6662
}
6763

6864
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy