PostgreSQL Source Code git master
htup.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * htup.h
4 * POSTGRES heap tuple definitions.
5 *
6 *
7 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
9 *
10 * src/include/access/htup.h
11 *
12 *-------------------------------------------------------------------------
13 */
14#ifndef HTUP_H
15#define HTUP_H
16
17#include "storage/itemptr.h"
18
19/* typedefs and forward declarations for structs defined in htup_details.h */
20
22
24
26
28
29
30/*
31 * HeapTupleData is an in-memory data structure that points to a tuple.
32 *
33 * There are several ways in which this data structure is used:
34 *
35 * * Pointer to a tuple in a disk buffer: t_data points directly into the
36 * buffer (which the code had better be holding a pin on, but this is not
37 * reflected in HeapTupleData itself).
38 *
39 * * Pointer to nothing: t_data is NULL. This is used as a failure indication
40 * in some functions.
41 *
42 * * Part of a palloc'd tuple: the HeapTupleData itself and the tuple
43 * form a single palloc'd chunk. t_data points to the memory location
44 * immediately following the HeapTupleData struct (at offset HEAPTUPLESIZE).
45 * This is the output format of heap_form_tuple and related routines.
46 *
47 * * Separately allocated tuple: t_data points to a palloc'd chunk that
48 * is not adjacent to the HeapTupleData. (This case is deprecated since
49 * it's difficult to tell apart from case #1. It should be used only in
50 * limited contexts where the code knows that case #1 will never apply.)
51 *
52 * * Separately allocated minimal tuple: t_data points MINIMAL_TUPLE_OFFSET
53 * bytes before the start of a MinimalTuple. As with the previous case,
54 * this can't be told apart from case #1 by inspection; code setting up
55 * or destroying this representation has to know what it's doing.
56 *
57 * t_len should always be valid, except in the pointer-to-nothing case.
58 * t_self and t_tableOid should be valid if the HeapTupleData points to
59 * a disk buffer, or if it represents a copy of a tuple on disk. They
60 * should be explicitly set invalid in manufactured tuples.
61 */
62typedef struct HeapTupleData
63{
64 uint32 t_len; /* length of *t_data */
65 ItemPointerData t_self; /* SelfItemPointer */
66 Oid t_tableOid; /* table the tuple came from */
67#define FIELDNO_HEAPTUPLEDATA_DATA 3
68 HeapTupleHeader t_data; /* -> tuple header and data */
70
72
73#define HEAPTUPLESIZE MAXALIGN(sizeof(HeapTupleData))
74
75/*
76 * Accessor macros to be used with HeapTuple pointers.
77 */
78#define HeapTupleIsValid(tuple) PointerIsValid(tuple)
79
80/* HeapTupleHeader functions implemented in utils/time/combocid.c */
84 CommandId *cmax, bool *iscombo);
85
86/* Prototype for HeapTupleHeader accessors in heapam.c */
88
89#endif /* HTUP_H */
uint32_t uint32
Definition: c.h:488
uint32 CommandId
Definition: c.h:623
uint32 TransactionId
Definition: c.h:609
void HeapTupleHeaderAdjustCmax(HeapTupleHeader tup, CommandId *cmax, bool *iscombo)
Definition: combocid.c:153
TransactionId HeapTupleGetUpdateXid(HeapTupleHeader tuple)
Definition: heapam.c:7440
HeapTupleData * HeapTuple
Definition: htup.h:71
struct HeapTupleData HeapTupleData
MinimalTupleData * MinimalTuple
Definition: htup.h:27
CommandId HeapTupleHeaderGetCmin(HeapTupleHeader tup)
Definition: combocid.c:104
HeapTupleHeaderData * HeapTupleHeader
Definition: htup.h:23
CommandId HeapTupleHeaderGetCmax(HeapTupleHeader tup)
Definition: combocid.c:118
unsigned int Oid
Definition: postgres_ext.h:32
ItemPointerData t_self
Definition: htup.h:65
uint32 t_len
Definition: htup.h:64
HeapTupleHeader t_data
Definition: htup.h:68
Oid t_tableOid
Definition: htup.h:66