diff options
Diffstat (limited to 'src/include/access/htup.h')
-rw-r--r-- | src/include/access/htup.h | 145 |
1 files changed, 131 insertions, 14 deletions
diff --git a/src/include/access/htup.h b/src/include/access/htup.h index 43152e16227..7a77d438933 100644 --- a/src/include/access/htup.h +++ b/src/include/access/htup.h @@ -7,13 +7,15 @@ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/access/htup.h,v 1.98 2008/01/01 19:45:56 momjian Exp $ + * $PostgreSQL: pgsql/src/include/access/htup.h,v 1.99 2008/05/12 00:00:53 alvherre Exp $ * *------------------------------------------------------------------------- */ #ifndef HTUP_H #define HTUP_H +#include "access/tupdesc.h" +#include "access/tupmacs.h" #include "storage/itemptr.h" #include "storage/relfilenode.h" @@ -393,19 +395,6 @@ do { \ /* - * Attribute numbers for the system-defined attributes - */ -#define SelfItemPointerAttributeNumber (-1) -#define ObjectIdAttributeNumber (-2) -#define MinTransactionIdAttributeNumber (-3) -#define MinCommandIdAttributeNumber (-4) -#define MaxTransactionIdAttributeNumber (-5) -#define MaxCommandIdAttributeNumber (-6) -#define TableOidAttributeNumber (-7) -#define FirstLowInvalidHeapAttributeNumber (-8) - - -/* * MinimalTuple is an alternative representation that is used for transient * tuples inside the executor, in places where transaction status information * is not required, the tuple rowtype is known, and shaving off a few bytes @@ -725,4 +714,132 @@ extern void HeapTupleHeaderAdjustCmax(HeapTupleHeader tup, CommandId *cmax, bool *iscombo); +/* ---------------- + * fastgetattr + * + * Fetch a user attribute's value as a Datum (might be either a + * value, or a pointer into the data area of the tuple). + * + * This must not be used when a system attribute might be requested. + * Furthermore, the passed attnum MUST be valid. Use heap_getattr() + * instead, if in doubt. + * + * This gets called many times, so we macro the cacheable and NULL + * lookups, and call nocachegetattr() for the rest. + * ---------------- + */ + +#if !defined(DISABLE_COMPLEX_MACRO) + +#define fastgetattr(tup, attnum, tupleDesc, isnull) \ +( \ + AssertMacro((attnum) > 0), \ + (((isnull) != NULL) ? (*(isnull) = false) : (dummyret)NULL), \ + HeapTupleNoNulls(tup) ? \ + ( \ + (tupleDesc)->attrs[(attnum)-1]->attcacheoff >= 0 ? \ + ( \ + fetchatt((tupleDesc)->attrs[(attnum)-1], \ + (char *) (tup)->t_data + (tup)->t_data->t_hoff + \ + (tupleDesc)->attrs[(attnum)-1]->attcacheoff) \ + ) \ + : \ + nocachegetattr((tup), (attnum), (tupleDesc), (isnull)) \ + ) \ + : \ + ( \ + att_isnull((attnum)-1, (tup)->t_data->t_bits) ? \ + ( \ + (((isnull) != NULL) ? (*(isnull) = true) : (dummyret)NULL), \ + (Datum)NULL \ + ) \ + : \ + ( \ + nocachegetattr((tup), (attnum), (tupleDesc), (isnull)) \ + ) \ + ) \ +) +#else /* defined(DISABLE_COMPLEX_MACRO) */ + +extern Datum fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, + bool *isnull); +#endif /* defined(DISABLE_COMPLEX_MACRO) */ + + +/* ---------------- + * heap_getattr + * + * Extract an attribute of a heap tuple and return it as a Datum. + * This works for either system or user attributes. The given attnum + * is properly range-checked. + * + * If the field in question has a NULL value, we return a zero Datum + * and set *isnull == true. Otherwise, we set *isnull == false. + * + * <tup> is the pointer to the heap tuple. <attnum> is the attribute + * number of the column (field) caller wants. <tupleDesc> is a + * pointer to the structure describing the row and all its fields. + * ---------------- + */ +#define heap_getattr(tup, attnum, tupleDesc, isnull) \ +( \ + AssertMacro((tup) != NULL), \ + ( \ + ((attnum) > 0) ? \ + ( \ + ((attnum) > (int) HeapTupleHeaderGetNatts((tup)->t_data)) ? \ + ( \ + (((isnull) != NULL) ? (*(isnull) = true) : (dummyret)NULL), \ + (Datum)NULL \ + ) \ + : \ + fastgetattr((tup), (attnum), (tupleDesc), (isnull)) \ + ) \ + : \ + heap_getsysattr((tup), (attnum), (tupleDesc), (isnull)) \ + ) \ +) + +/* prototypes for functions in common/heaptuple.c */ +extern Size heap_compute_data_size(TupleDesc tupleDesc, + Datum *values, bool *isnull); +extern void heap_fill_tuple(TupleDesc tupleDesc, + Datum *values, bool *isnull, + char *data, Size data_size, + uint16 *infomask, bits8 *bit); +extern bool heap_attisnull(HeapTuple tup, int attnum); +extern Datum nocachegetattr(HeapTuple tup, int attnum, + TupleDesc att, bool *isnull); +extern Datum heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, + bool *isnull); +extern HeapTuple heap_copytuple(HeapTuple tuple); +extern void heap_copytuple_with_tuple(HeapTuple src, HeapTuple dest); +extern HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, + Datum *values, bool *isnull); +extern HeapTuple heap_formtuple(TupleDesc tupleDescriptor, + Datum *values, char *nulls); +extern HeapTuple heap_modify_tuple(HeapTuple tuple, + TupleDesc tupleDesc, + Datum *replValues, + bool *replIsnull, + bool *doReplace); +extern HeapTuple heap_modifytuple(HeapTuple tuple, + TupleDesc tupleDesc, + Datum *replValues, + char *replNulls, + char *replActions); +extern void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, + Datum *values, bool *isnull); +extern void heap_deformtuple(HeapTuple tuple, TupleDesc tupleDesc, + Datum *values, char *nulls); +extern void heap_freetuple(HeapTuple htup); +extern MinimalTuple heap_form_minimal_tuple(TupleDesc tupleDescriptor, + Datum *values, bool *isnull); +extern void heap_free_minimal_tuple(MinimalTuple mtup); +extern MinimalTuple heap_copy_minimal_tuple(MinimalTuple mtup); +extern HeapTuple heap_tuple_from_minimal_tuple(MinimalTuple mtup); +extern MinimalTuple minimal_tuple_from_heap_tuple(HeapTuple htup); +extern HeapTuple heap_addheader(int natts, bool withoid, + Size structlen, void *structure); + #endif /* HTUP_H */ |