00001 /*------------------------------------------------------------------------- 00002 * 00003 * htup.h 00004 * POSTGRES heap tuple definitions. 00005 * 00006 * 00007 * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group 00008 * Portions Copyright (c) 1994, Regents of the University of California 00009 * 00010 * src/include/access/htup.h 00011 * 00012 *------------------------------------------------------------------------- 00013 */ 00014 #ifndef HTUP_H 00015 #define HTUP_H 00016 00017 #include "storage/itemptr.h" 00018 00019 /* typedefs and forward declarations for structs defined in htup.h */ 00020 00021 typedef struct HeapTupleHeaderData HeapTupleHeaderData; 00022 00023 typedef HeapTupleHeaderData *HeapTupleHeader; 00024 00025 typedef struct MinimalTupleData MinimalTupleData; 00026 00027 typedef MinimalTupleData *MinimalTuple; 00028 00029 00030 /* 00031 * HeapTupleData is an in-memory data structure that points to a tuple. 00032 * 00033 * There are several ways in which this data structure is used: 00034 * 00035 * * Pointer to a tuple in a disk buffer: t_data points directly into the 00036 * buffer (which the code had better be holding a pin on, but this is not 00037 * reflected in HeapTupleData itself). 00038 * 00039 * * Pointer to nothing: t_data is NULL. This is used as a failure indication 00040 * in some functions. 00041 * 00042 * * Part of a palloc'd tuple: the HeapTupleData itself and the tuple 00043 * form a single palloc'd chunk. t_data points to the memory location 00044 * immediately following the HeapTupleData struct (at offset HEAPTUPLESIZE). 00045 * This is the output format of heap_form_tuple and related routines. 00046 * 00047 * * Separately allocated tuple: t_data points to a palloc'd chunk that 00048 * is not adjacent to the HeapTupleData. (This case is deprecated since 00049 * it's difficult to tell apart from case #1. It should be used only in 00050 * limited contexts where the code knows that case #1 will never apply.) 00051 * 00052 * * Separately allocated minimal tuple: t_data points MINIMAL_TUPLE_OFFSET 00053 * bytes before the start of a MinimalTuple. As with the previous case, 00054 * this can't be told apart from case #1 by inspection; code setting up 00055 * or destroying this representation has to know what it's doing. 00056 * 00057 * t_len should always be valid, except in the pointer-to-nothing case. 00058 * t_self and t_tableOid should be valid if the HeapTupleData points to 00059 * a disk buffer, or if it represents a copy of a tuple on disk. They 00060 * should be explicitly set invalid in manufactured tuples. 00061 */ 00062 typedef struct HeapTupleData 00063 { 00064 uint32 t_len; /* length of *t_data */ 00065 ItemPointerData t_self; /* SelfItemPointer */ 00066 Oid t_tableOid; /* table the tuple came from */ 00067 HeapTupleHeader t_data; /* -> tuple header and data */ 00068 } HeapTupleData; 00069 00070 typedef HeapTupleData *HeapTuple; 00071 00072 #define HEAPTUPLESIZE MAXALIGN(sizeof(HeapTupleData)) 00073 00074 /* 00075 * Accessor macros to be used with HeapTuple pointers. 00076 */ 00077 #define HeapTupleIsValid(tuple) PointerIsValid(tuple) 00078 00079 /* HeapTupleHeader functions implemented in utils/time/combocid.c */ 00080 extern CommandId HeapTupleHeaderGetCmin(HeapTupleHeader tup); 00081 extern CommandId HeapTupleHeaderGetCmax(HeapTupleHeader tup); 00082 extern void HeapTupleHeaderAdjustCmax(HeapTupleHeader tup, 00083 CommandId *cmax, bool *iscombo); 00084 00085 /* Prototype for HeapTupleHeader accessors in heapam.c */ 00086 extern TransactionId HeapTupleGetUpdateXid(HeapTupleHeader tuple); 00087 00088 #endif /* HTUP_H */