1 /*-------------------------------------------------------------------------
2  *
3  * htup.h
4  *	  POSTGRES heap tuple definitions.
5  *
6  *
7  * Portions Copyright (c) 1996-2020, 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 
21 typedef struct HeapTupleHeaderData HeapTupleHeaderData;
22 
23 typedef HeapTupleHeaderData *HeapTupleHeader;
24 
25 typedef struct MinimalTupleData MinimalTupleData;
26 
27 typedef MinimalTupleData *MinimalTuple;
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  */
62 typedef 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 */
69 } HeapTupleData;
70 
71 typedef HeapTupleData *HeapTuple;
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 */
81 extern CommandId HeapTupleHeaderGetCmin(HeapTupleHeader tup);
82 extern CommandId HeapTupleHeaderGetCmax(HeapTupleHeader tup);
83 extern void HeapTupleHeaderAdjustCmax(HeapTupleHeader tup,
84 									  CommandId *cmax, bool *iscombo);
85 
86 /* Prototype for HeapTupleHeader accessors in heapam.c */
87 extern TransactionId HeapTupleGetUpdateXid(HeapTupleHeader tuple);
88 
89 #endif							/* HTUP_H */
90