1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-23 03:21:12 +03:00

Distinguish between MaxHeapAttributeNumber and MaxTupleAttributeNumber,

where the latter is made slightly larger to allow for in-memory tuples
containing resjunk attributes.  Responds to today's complaint that one
cannot UPDATE a table containing the allegedly-legal maximum number of
columns.

Also, apply Manfred Koizar's recent patch to avoid extra alignment padding
when there is a null bitmap.  This saves bytes in some cases while not
creating any backward-compatibility problem AFAICS.
This commit is contained in:
Tom Lane
2002-05-27 19:53:33 +00:00
parent 3cde085158
commit 3212cf9417
3 changed files with 64 additions and 62 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/heap/tuptoaster.c,v 1.31 2002/05/24 18:57:55 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/access/heap/tuptoaster.c,v 1.32 2002/05/27 19:53:33 tgl Exp $
*
*
* INTERFACE ROUTINES
@ -715,39 +715,34 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
*/
if (need_change)
{
HeapTupleHeader olddata = newtup->t_data;
char *new_data;
int32 new_len;
MemoryContext oldcxt;
HeapTupleHeader olddata;
/*
* Calculate the new size of the tuple
* Calculate the new size of the tuple. Header size should not
* change, but data size might.
*/
new_len = offsetof(HeapTupleHeaderData, t_bits);
if (has_nulls)
new_len += BITMAPLEN(numAttrs);
new_len = MAXALIGN(new_len);
Assert(new_len == olddata->t_hoff);
new_len += ComputeDataSize(tupleDesc, toast_values, toast_nulls);
/*
* Remember the old memory location of the tuple (for below),
* switch to the memory context of the HeapTuple structure and
* allocate the new tuple.
* Allocate new tuple in same context as old one.
*/
olddata = newtup->t_data;
oldcxt = MemoryContextSwitchTo(newtup->t_datamcxt);
new_data = palloc(new_len);
new_data = (char *) MemoryContextAlloc(newtup->t_datamcxt, new_len);
newtup->t_data = (HeapTupleHeader) new_data;
newtup->t_len = new_len;
/*
* Put the tuple header and the changed values into place
*/
memcpy(new_data, newtup->t_data, newtup->t_data->t_hoff);
newtup->t_data = (HeapTupleHeader) new_data;
newtup->t_len = new_len;
memcpy(new_data, olddata, olddata->t_hoff);
DataFill((char *) (MAXALIGN((long) new_data +
offsetof(HeapTupleHeaderData, t_bits) +
((has_nulls) ? BITMAPLEN(numAttrs) : 0))),
DataFill((char *) new_data + olddata->t_hoff,
tupleDesc,
toast_values,
toast_nulls,
@ -760,11 +755,6 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
*/
if ((char *) olddata != ((char *) newtup + HEAPTUPLESIZE))
pfree(olddata);
/*
* Switch back to the old memory context
*/
MemoryContextSwitchTo(oldcxt);
}
/*