PostgreSQL Source Code  git master
hio.h File Reference
#include "access/htup.h"
#include "utils/relcache.h"
#include "storage/buf.h"
Include dependency graph for hio.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  BulkInsertStateData
 

Typedefs

typedef struct BulkInsertStateData BulkInsertStateData
 

Functions

void RelationPutHeapTuple (Relation relation, Buffer buffer, HeapTuple tuple, bool token)
 
Buffer RelationGetBufferForTuple (Relation relation, Size len, Buffer otherBuffer, int options, BulkInsertStateData *bistate, Buffer *vmbuffer, Buffer *vmbuffer_other)
 

Typedef Documentation

◆ BulkInsertStateData

Function Documentation

◆ RelationGetBufferForTuple()

Buffer RelationGetBufferForTuple ( Relation  relation,
Size  len,
Buffer  otherBuffer,
int  options,
BulkInsertStateData bistate,
Buffer vmbuffer,
Buffer vmbuffer_other 
)

◆ RelationPutHeapTuple()

void RelationPutHeapTuple ( Relation  relation,
Buffer  buffer,
HeapTuple  tuple,
bool  token 
)

Definition at line 36 of file hio.c.

References Assert, BufferGetBlockNumber(), BufferGetPage, elog, HeapTupleHeaderIsSpeculative, InvalidOffsetNumber, ItemPointerSet, PageAddItem, PageGetItem, PageGetItemId, PANIC, HeapTupleHeaderData::t_ctid, HeapTupleData::t_data, HeapTupleData::t_len, and HeapTupleData::t_self.

Referenced by heap_insert(), heap_multi_insert(), and heap_update().

40 {
41  Page pageHeader;
42  OffsetNumber offnum;
43 
44  /*
45  * A tuple that's being inserted speculatively should already have its
46  * token set.
47  */
48  Assert(!token || HeapTupleHeaderIsSpeculative(tuple->t_data));
49 
50  /* Add the tuple to the page */
51  pageHeader = BufferGetPage(buffer);
52 
53  offnum = PageAddItem(pageHeader, (Item) tuple->t_data,
54  tuple->t_len, InvalidOffsetNumber, false, true);
55 
56  if (offnum == InvalidOffsetNumber)
57  elog(PANIC, "failed to add tuple to page");
58 
59  /* Update tuple->t_self to the actual position where it was stored */
60  ItemPointerSet(&(tuple->t_self), BufferGetBlockNumber(buffer), offnum);
61 
62  /*
63  * Insert the correct position into CTID of the stored tuple, too (unless
64  * this is a speculative insertion, in which case the token is held in
65  * CTID field instead)
66  */
67  if (!token)
68  {
69  ItemId itemId = PageGetItemId(pageHeader, offnum);
70  HeapTupleHeader item = (HeapTupleHeader) PageGetItem(pageHeader, itemId);
71 
72  item->t_ctid = tuple->t_self;
73  }
74 }
HeapTupleHeaderData * HeapTupleHeader
Definition: htup.h:23
Pointer Item
Definition: item.h:17
#define HeapTupleHeaderIsSpeculative(tup)
Definition: htup_details.h:429
#define PageAddItem(page, item, size, offsetNumber, overwrite, is_heap)
Definition: bufpage.h:416
#define PANIC
Definition: elog.h:53
uint16 OffsetNumber
Definition: off.h:24
HeapTupleHeader t_data
Definition: htup.h:68
ItemPointerData t_ctid
Definition: htup_details.h:160
ItemPointerData t_self
Definition: htup.h:65
uint32 t_len
Definition: htup.h:64
#define BufferGetPage(buffer)
Definition: bufmgr.h:159
#define PageGetItemId(page, offsetNumber)
Definition: bufpage.h:235
#define InvalidOffsetNumber
Definition: off.h:26
#define Assert(condition)
Definition: c.h:732
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition: bufmgr.c:2613
#define elog(elevel,...)
Definition: elog.h:226
#define PageGetItem(page, itemId)
Definition: bufpage.h:340
Pointer Page
Definition: bufpage.h:78
#define ItemPointerSet(pointer, blockNumber, offNum)
Definition: itemptr.h:127