1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-25 13:17:41 +03:00

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
This commit is contained in:
Bruce Momjian
2002-07-20 05:16:59 +00:00
parent 38dd3ae7d0
commit b0f5086e41
57 changed files with 414 additions and 198 deletions

View File

@@ -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 */

View File

@@ -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 */

View File

@@ -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);