diff options
author | Bruce Momjian <bruce@momjian.us> | 2002-07-20 05:16:59 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2002-07-20 05:16:59 +0000 |
commit | b0f5086e4133d1d8ec092799952dda65ebd717c8 (patch) | |
tree | 0f717342af7cce7896d40fdb34ccc572e435d499 /src/backend/access/common/heaptuple.c | |
parent | 38dd3ae7d032eecc6ddadcbd402d90f6ac38f6a3 (diff) | |
download | postgresql-b0f5086e4133d1d8ec092799952dda65ebd717c8.tar.gz postgresql-b0f5086e4133d1d8ec092799952dda65ebd717c8.zip |
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/backend/access/common/heaptuple.c')
-rw-r--r-- | src/backend/access/common/heaptuple.c | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/backend/access/common/heaptuple.c b/src/backend/access/common/heaptuple.c index adad245c643..19e02dee67e 100644 --- a/src/backend/access/common/heaptuple.c +++ b/src/backend/access/common/heaptuple.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.77 2002/06/20 20:29:24 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.78 2002/07/20 05:16:56 momjian Exp $ * * NOTES * The old interface functions have been converted to macros @@ -436,7 +436,7 @@ heap_getsysattr(HeapTuple tup, int attnum, bool *isnull) result = PointerGetDatum(&(tup->t_self)); break; case ObjectIdAttributeNumber: - result = ObjectIdGetDatum(tup->t_data->t_oid); + result = ObjectIdGetDatum(HeapTupleGetOid(tup)); break; case MinTransactionIdAttributeNumber: result = TransactionIdGetDatum(HeapTupleHeaderGetXmin(tup->t_data)); @@ -581,6 +581,8 @@ heap_formtuple(TupleDesc tupleDescriptor, elog(ERROR, "heap_formtuple: numberOfAttributes %d exceeds limit %d", numberOfAttributes, MaxTupleAttributeNumber); + AssertTupleDescHasOidIsValid(tupleDescriptor); + for (i = 0; i < numberOfAttributes; i++) { if (nulls[i] != ' ') @@ -595,6 +597,9 @@ heap_formtuple(TupleDesc tupleDescriptor, if (hasnull) len += BITMAPLEN(numberOfAttributes); + if (tupleDescriptor->tdhasoid == WITHOID) + len += sizeof(Oid); + hoff = len = MAXALIGN(len); /* align user data safely */ len += ComputeDataSize(tupleDescriptor, value, nulls); @@ -698,14 +703,18 @@ heap_modifytuple(HeapTuple tuple, * t_infomask */ infomask = newTuple->t_data->t_infomask; - memmove((char *) &newTuple->t_data->t_oid, /* XXX */ - (char *) &tuple->t_data->t_oid, - ((char *) &tuple->t_data->t_hoff - - (char *) &tuple->t_data->t_oid)); /* XXX */ + /* + * copy t_xmin, t_cid, t_xmax, t_ctid, t_natts, t_infomask + */ + memmove((char *) newTuple->t_data, /* XXX */ + (char *) tuple->t_data, + offsetof(HeapTupleHeaderData, t_hoff)); /* XXX */ newTuple->t_data->t_infomask = infomask; newTuple->t_data->t_natts = numberOfAttributes; newTuple->t_self = tuple->t_self; newTuple->t_tableOid = tuple->t_tableOid; + if (relation->rd_rel->relhasoids) + HeapTupleSetOid(newTuple, HeapTupleGetOid(tuple)); return newTuple; } @@ -738,6 +747,7 @@ heap_freetuple(HeapTuple htup) */ HeapTuple heap_addheader(int natts, /* max domain index */ + bool withoid, /* reserve space for oid */ Size structlen, /* its length */ void *structure) /* pointer to the struct */ { @@ -749,7 +759,10 @@ heap_addheader(int natts, /* max domain index */ AssertArg(natts > 0); /* header needs no null bitmap */ - hoff = MAXALIGN(offsetof(HeapTupleHeaderData, t_bits)); + hoff = offsetof(HeapTupleHeaderData, t_bits); + if (withoid) + hoff += sizeof(Oid); + hoff = MAXALIGN(hoff); len = hoff + structlen; tuple = (HeapTuple) palloc(HEAPTUPLESIZE + len); |