diff options
| author | Bruce Momjian | 2002-07-20 05:16:59 +0000 |
|---|---|---|
| committer | Bruce Momjian | 2002-07-20 05:16:59 +0000 |
| commit | b0f5086e4133d1d8ec092799952dda65ebd717c8 (patch) | |
| tree | 0f717342af7cce7896d40fdb34ccc572e435d499 /src/include/access | |
| parent | 38dd3ae7d032eecc6ddadcbd402d90f6ac38f6a3 (diff) | |
oid is needed, it is added at the end of the struct (after the null
bitmap, if present).
Per Tom Lane's suggestion the information whether a tuple has an oid
or not is carried in the tuple descriptor. For debugging reasons
tdhasoid is of type char, not bool. There are predefined values for
WITHOID, WITHOUTOID and UNDEFOID.
This patch has been generated against a cvs snapshot from last week
and I don't expect it to apply cleanly to current sources. While I
post it here for public review, I'm working on a new version against a
current snapshot. (There's been heavy activity recently; hope to
catch up some day ...)
This is a long patch; if it is too hard to swallow, I can provide it
in smaller pieces:
Part 1: Accessor macros
Part 2: tdhasoid in TupDesc
Part 3: Regression test
Part 4: Parameter withoid to heap_addheader
Part 5: Eliminate t_oid from HeapTupleHeader
Part 2 is the most hairy part because of changes in the executor and
even in the parser; the other parts are straightforward.
Up to part 4 the patched postmaster stays binary compatible to
databases created with an unpatched version. Part 5 is small (100
lines) and finally breaks compatibility.
Manfred Koizar
Diffstat (limited to 'src/include/access')
| -rw-r--r-- | src/include/access/heapam.h | 4 | ||||
| -rw-r--r-- | src/include/access/htup.h | 44 | ||||
| -rw-r--r-- | src/include/access/tupdesc.h | 27 |
3 files changed, 67 insertions, 8 deletions
diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h index eafa3224572..b0e32214adf 100644 --- a/src/include/access/heapam.h +++ b/src/include/access/heapam.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: heapam.h,v 1.77 2002/06/20 20:29:43 momjian Exp $ + * $Id: heapam.h,v 1.78 2002/07/20 05:16:59 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -200,6 +200,6 @@ extern HeapTuple heap_formtuple(TupleDesc tupleDescriptor, extern HeapTuple heap_modifytuple(HeapTuple tuple, Relation relation, Datum *replValue, char *replNull, char *repl); extern void heap_freetuple(HeapTuple tuple); -extern HeapTuple heap_addheader(int natts, Size structlen, void *structure); +extern HeapTuple heap_addheader(int natts, bool withoid, Size structlen, void *structure); #endif /* HEAPAM_H */ diff --git a/src/include/access/htup.h b/src/include/access/htup.h index 87f1727f9e4..5da1c3608ed 100644 --- a/src/include/access/htup.h +++ b/src/include/access/htup.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: htup.h,v 1.56 2002/07/08 01:52:23 momjian Exp $ + * $Id: htup.h,v 1.57 2002/07/20 05:16:59 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -70,8 +70,6 @@ */ typedef struct HeapTupleHeaderData { - Oid t_oid; /* OID of this tuple -- 4 bytes */ - TransactionId t_xmin; /* Xmin -- 4 bytes each */ TransactionId t_cid; /* Cmin, Cmax, Xvac */ TransactionId t_xmax; /* Xmax, Cmax */ @@ -84,7 +82,7 @@ typedef struct HeapTupleHeaderData uint8 t_hoff; /* sizeof header incl. bitmap, padding */ - /* ^ - 27 bytes - ^ */ + /* ^ - 23 bytes - ^ */ bits8 t_bits[1]; /* bitmap of NULLs -- VARIABLE LENGTH */ @@ -123,10 +121,42 @@ typedef HeapTupleHeaderData *HeapTupleHeader; #define HEAP_XACT_MASK 0xFFF0 /* visibility-related bits */ +/* paranoid checking */ + +#ifdef DEBUG_TUPLE_ACCESS + +#define HeapTupleHeaderExpectedLen(tup, withoid) \ + MAXALIGN(offsetof(HeapTupleHeaderData, t_bits) + \ + (((tup)->t_infomask & HEAP_HASNULL) \ + ? BITMAPLEN((tup)->t_natts) : 0) + \ + ((withoid) ? sizeof(Oid) : 0) \ + ) + +#define AssertHeapTupleHeaderHoffIsValid(tup, withoid) \ + AssertMacro((tup)->t_hoff == HeapTupleHeaderExpectedLen(tup, withoid)) + +#else + +#define AssertHeapTupleHeaderHoffIsValid(tup, withoid) ((void)true) + +#endif /* DEBUG_TUPLE_ACCESS */ /* HeapTupleHeader accessor macros */ +#define HeapTupleHeaderGetOid(tup) \ +( \ + AssertHeapTupleHeaderHoffIsValid(tup, true), \ + *((Oid *)((char *)(tup) + (tup)->t_hoff - sizeof(Oid))) \ +) + +#define HeapTupleHeaderSetOid(tup, oid) \ +( \ + AssertHeapTupleHeaderHoffIsValid(tup, true), \ + *((Oid *)((char *)(tup) + (tup)->t_hoff - sizeof(Oid))) = (oid) \ +) + + #define HeapTupleHeaderGetXmin(tup) \ ( \ (tup)->t_xmin \ @@ -406,4 +436,10 @@ typedef HeapTupleData *HeapTuple; #define HeapTupleHasExtended(tuple) \ ((((HeapTuple)(tuple))->t_data->t_infomask & HEAP_HASEXTENDED) != 0) +#define HeapTupleGetOid(tuple) \ + HeapTupleHeaderGetOid(((HeapTuple)(tuple))->t_data) + +#define HeapTupleSetOid(tuple, oid) \ + HeapTupleHeaderSetOid(((HeapTuple)(tuple))->t_data, (oid)) + #endif /* HTUP_H */ diff --git a/src/include/access/tupdesc.h b/src/include/access/tupdesc.h index 0f277d1c9e8..c8c9839985e 100644 --- a/src/include/access/tupdesc.h +++ b/src/include/access/tupdesc.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: tupdesc.h,v 1.36 2002/07/12 18:43:19 tgl Exp $ + * $Id: tupdesc.h,v 1.37 2002/07/20 05:16:59 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -41,6 +41,11 @@ typedef struct tupleConstr bool has_not_null; } TupleConstr; +typedef char hasoid_t; +#define WITHOID 'C' +#define WITHOUTOID 'S' +#define UNDEFOID '?' +#define BoolToHasOid(b) ((b) ? WITHOID : WITHOUTOID) /* * This structure contains all information (i.e. from Classes * pg_attribute, pg_attrdef, pg_constraint) for a tuple. @@ -51,9 +56,27 @@ typedef struct tupleDesc Form_pg_attribute *attrs; /* attrs[N] is a pointer to the description of Attribute Number N+1. */ TupleConstr *constr; + hasoid_t tdhasoid; /* Tuple has an oid attribute in its header */ } *TupleDesc; -extern TupleDesc CreateTemplateTupleDesc(int natts); +#ifdef DEBUG_TUPLE_ACCESS + +#define AssertTupleDescHasOidIsValid(td) \ + Assert(((td)->tdhasoid == WITHOID) || ((td)->tdhasoid == WITHOUTOID)) +#define AssertTupleDescHasOid(td) \ + Assert((td)->tdhasoid == WITHOID) +#define AssertTupleDescHasNoOid(td) \ + Assert((td)->tdhasoid == WITHOUTOID) + +#else + +#define AssertTupleDescHasOidIsValid(td) +#define AssertTupleDescHasOid(td) +#define AssertTupleDescHasNoOid(td) + +#endif + +extern TupleDesc CreateTemplateTupleDesc(int natts, hasoid_t withoid); extern TupleDesc CreateTupleDesc(int natts, Form_pg_attribute *attrs); |
