1 /*-------------------------------------------------------------------------
4 * POSTGRES heap tuple definitions.
7 * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/include/access/htup.h
12 *-------------------------------------------------------------------------
17 #include "storage/itemptr.h"
19 /* typedefs and forward declarations for structs defined in htup_details.h */
21 typedef struct HeapTupleHeaderData HeapTupleHeaderData;
23 typedef HeapTupleHeaderData *HeapTupleHeader;
25 typedef struct MinimalTupleData MinimalTupleData;
27 typedef MinimalTupleData *MinimalTuple;
31 * HeapTupleData is an in-memory data structure that points to a tuple.
33 * There are several ways in which this data structure is used:
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).
39 * * Pointer to nothing: t_data is NULL. This is used as a failure indication
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.
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.)
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.
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.
62 typedef struct HeapTupleData
64 uint32 t_len; /* length of *t_data */
65 ItemPointerData t_self; /* SelfItemPointer */
66 Oid t_tableOid; /* table the tuple came from */
67 HeapTupleHeader t_data; /* -> tuple header and data */
70 typedef HeapTupleData *HeapTuple;
72 #define HEAPTUPLESIZE MAXALIGN(sizeof(HeapTupleData))
75 * Accessor macros to be used with HeapTuple pointers.
77 #define HeapTupleIsValid(tuple) PointerIsValid(tuple)
79 /* HeapTupleHeader functions implemented in utils/time/combocid.c */
80 extern CommandId HeapTupleHeaderGetCmin(HeapTupleHeader tup);
81 extern CommandId HeapTupleHeaderGetCmax(HeapTupleHeader tup);
82 extern void HeapTupleHeaderAdjustCmax(HeapTupleHeader tup,
83 CommandId *cmax, bool *iscombo);
85 /* Prototype for HeapTupleHeader accessors in heapam.c */
86 extern TransactionId HeapTupleGetUpdateXid(HeapTupleHeader tuple);