PostgreSQL Source Code  git master
hio.h File Reference
#include "access/htup.h"
#include "storage/buf.h"
#include "utils/relcache.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, HEAP_KEYS_UPDATED, HEAP_XMAX_COMMITTED, HEAP_XMAX_IS_MULTI, HEAP_XMAX_LOCK_ONLY, HeapTupleHeaderIsSpeculative, InvalidOffsetNumber, ItemPointerSet, PageAddItem, PageGetItem, PageGetItemId, PANIC, HeapTupleHeaderData::t_ctid, HeapTupleData::t_data, HeapTupleHeaderData::t_infomask, HeapTupleHeaderData::t_infomask2, 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  /*
51  * Do not allow tuples with invalid combinations of hint bits to be placed
52  * on a page. These combinations are detected as corruption by the
53  * contrib/amcheck logic, so if you disable one or both of these
54  * assertions, make corresponding changes there.
55  */
57  (tuple->t_data->t_infomask2 & HEAP_KEYS_UPDATED)));
59  (tuple->t_data->t_infomask & HEAP_XMAX_IS_MULTI)));
60 
61  /* Add the tuple to the page */
62  pageHeader = BufferGetPage(buffer);
63 
64  offnum = PageAddItem(pageHeader, (Item) tuple->t_data,
65  tuple->t_len, InvalidOffsetNumber, false, true);
66 
67  if (offnum == InvalidOffsetNumber)
68  elog(PANIC, "failed to add tuple to page");
69 
70  /* Update tuple->t_self to the actual position where it was stored */
71  ItemPointerSet(&(tuple->t_self), BufferGetBlockNumber(buffer), offnum);
72 
73  /*
74  * Insert the correct position into CTID of the stored tuple, too (unless
75  * this is a speculative insertion, in which case the token is held in
76  * CTID field instead)
77  */
78  if (!token)
79  {
80  ItemId itemId = PageGetItemId(pageHeader, offnum);
81  HeapTupleHeader item = (HeapTupleHeader) PageGetItem(pageHeader, itemId);
82 
83  item->t_ctid = tuple->t_self;
84  }
85 }
#define HEAP_XMAX_LOCK_ONLY
Definition: htup_details.h:196
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 HEAP_XMAX_COMMITTED
Definition: htup_details.h:206
#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:169
#define PageGetItemId(page, offsetNumber)
Definition: bufpage.h:235
#define HEAP_KEYS_UPDATED
Definition: htup_details.h:278
#define HEAP_XMAX_IS_MULTI
Definition: htup_details.h:208
#define InvalidOffsetNumber
Definition: off.h:26
#define Assert(condition)
Definition: c.h:800
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition: bufmgr.c:2663
#define elog(elevel,...)
Definition: elog.h:228
#define PageGetItem(page, itemId)
Definition: bufpage.h:340
Pointer Page
Definition: bufpage.h:78
#define ItemPointerSet(pointer, blockNumber, offNum)
Definition: itemptr.h:127