Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3212cf9

Browse files
committed
Distinguish between MaxHeapAttributeNumber and MaxTupleAttributeNumber,
where the latter is made slightly larger to allow for in-memory tuplescontaining resjunk attributes. Responds to today's complaint that onecannot UPDATE a table containing the allegedly-legal maximum number ofcolumns.Also, apply Manfred Koizar's recent patch to avoid extra alignment paddingwhen there is a null bitmap. This saves bytes in some cases while notcreating any backward-compatibility problem AFAICS.
1 parent3cde085 commit3212cf9

File tree

3 files changed

+63
-61
lines changed

3 files changed

+63
-61
lines changed

‎src/backend/access/common/heaptuple.c‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.74 2001/10/25 05:49:20 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.75 2002/05/27 19:53:33 tgl Exp $
1313
*
1414
* NOTES
1515
* The old interface functions have been converted to macros
@@ -571,18 +571,15 @@ heap_formtuple(TupleDesc tupleDescriptor,
571571
{
572572
HeapTupletuple;/* return tuple */
573573
HeapTupleHeadertd;/* tuple data */
574-
intbitmaplen;
575574
unsigned longlen;
576575
inthoff;
577576
boolhasnull= false;
578577
inti;
579578
intnumberOfAttributes=tupleDescriptor->natts;
580579

581-
if (numberOfAttributes>MaxHeapAttributeNumber)
582-
elog(ERROR,"heap_formtuple: numberOfAttributes of %d > %d",
583-
numberOfAttributes,MaxHeapAttributeNumber);
584-
585-
len= offsetof(HeapTupleHeaderData,t_bits);
580+
if (numberOfAttributes>MaxTupleAttributeNumber)
581+
elog(ERROR,"heap_formtuple: numberOfAttributes %d exceeds limit %d",
582+
numberOfAttributes,MaxTupleAttributeNumber);
586583

587584
for (i=0;i<numberOfAttributes;i++)
588585
{
@@ -593,13 +590,12 @@ heap_formtuple(TupleDesc tupleDescriptor,
593590
}
594591
}
595592

593+
len= offsetof(HeapTupleHeaderData,t_bits);
594+
596595
if (hasnull)
597-
{
598-
bitmaplen=BITMAPLEN(numberOfAttributes);
599-
len+=bitmaplen;
600-
}
596+
len+=BITMAPLEN(numberOfAttributes);
601597

602-
hoff=len=MAXALIGN(len);/*be conservative here */
598+
hoff=len=MAXALIGN(len);/*align user data safely */
603599

604600
len+=ComputeDataSize(tupleDescriptor,value,nulls);
605601

@@ -615,7 +611,7 @@ heap_formtuple(TupleDesc tupleDescriptor,
615611
td->t_natts=numberOfAttributes;
616612
td->t_hoff=hoff;
617613

618-
DataFill((char*)td+td->t_hoff,
614+
DataFill((char*)td+hoff,
619615
tupleDescriptor,
620616
value,
621617
nulls,

‎src/backend/access/heap/tuptoaster.c‎

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/heap/tuptoaster.c,v 1.31 2002/05/24 18:57:55 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/heap/tuptoaster.c,v 1.32 2002/05/27 19:53:33 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -715,39 +715,34 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
715715
*/
716716
if (need_change)
717717
{
718+
HeapTupleHeaderolddata=newtup->t_data;
718719
char*new_data;
719720
int32new_len;
720-
MemoryContextoldcxt;
721-
HeapTupleHeaderolddata;
722721

723722
/*
724-
* Calculate the new size of the tuple
723+
* Calculate the new size of the tuple. Header size should not
724+
* change, but data size might.
725725
*/
726726
new_len= offsetof(HeapTupleHeaderData,t_bits);
727727
if (has_nulls)
728728
new_len+=BITMAPLEN(numAttrs);
729729
new_len=MAXALIGN(new_len);
730+
Assert(new_len==olddata->t_hoff);
730731
new_len+=ComputeDataSize(tupleDesc,toast_values,toast_nulls);
731732

732733
/*
733-
* Remember the old memory location of the tuple (for below),
734-
* switch to the memory context of the HeapTuple structure and
735-
* allocate the new tuple.
734+
* Allocate new tuple in same context as old one.
736735
*/
737-
olddata=newtup->t_data;
738-
oldcxt=MemoryContextSwitchTo(newtup->t_datamcxt);
739-
new_data=palloc(new_len);
736+
new_data=(char*)MemoryContextAlloc(newtup->t_datamcxt,new_len);
737+
newtup->t_data=(HeapTupleHeader)new_data;
738+
newtup->t_len=new_len;
740739

741740
/*
742741
* Put the tuple header and the changed values into place
743742
*/
744-
memcpy(new_data,newtup->t_data,newtup->t_data->t_hoff);
745-
newtup->t_data= (HeapTupleHeader)new_data;
746-
newtup->t_len=new_len;
743+
memcpy(new_data,olddata,olddata->t_hoff);
747744

748-
DataFill((char*) (MAXALIGN((long)new_data+
749-
offsetof(HeapTupleHeaderData,t_bits)+
750-
((has_nulls) ?BITMAPLEN(numAttrs) :0))),
745+
DataFill((char*)new_data+olddata->t_hoff,
751746
tupleDesc,
752747
toast_values,
753748
toast_nulls,
@@ -760,11 +755,6 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
760755
*/
761756
if ((char*)olddata!= ((char*)newtup+HEAPTUPLESIZE))
762757
pfree(olddata);
763-
764-
/*
765-
* Switch back to the old memory context
766-
*/
767-
MemoryContextSwitchTo(oldcxt);
768758
}
769759

770760
/*

‎src/include/access/htup.h‎

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: htup.h,v 1.51 2001/11/05 17:46:31 momjian Exp $
10+
* $Id: htup.h,v 1.52 2002/05/27 19:53:33 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -17,25 +17,44 @@
1717
#include"storage/bufpage.h"
1818
#include"storage/relfilenode.h"
1919

20-
#defineMinHeapTupleBitmapSize32/* 8 * 4 */
2120

2221
/*
23-
*MaxHeapAttributeNumber limits the number of (user) columns in atable.
22+
*MaxTupleAttributeNumber limits the number of (user) columns in atuple.
2423
* The key limit on this value is that the size of the fixed overhead for
2524
* a tuple, plus the size of the null-values bitmap (at 1 bit per column),
2625
* plus MAXALIGN alignment, must fit into t_hoff which is uint8. On most
27-
* machines the absolute upper limit without making t_hoff wider would be
28-
* about 1700.Note, however, that depending on column data types you will
29-
* likely also be running into the disk-block-based limit on overall tuple
30-
* size if you have more than a thousand or so columns. TOAST won't help.
26+
* machines the upper limit without making t_hoff wider would be a little
27+
* over 1700. We use round numbers here and for MaxHeapAttributeNumber
28+
* so that alterations in HeapTupleHeaderData layout won't change the
29+
* supported max number of columns.
30+
*/
31+
#defineMaxTupleAttributeNumber1664/* 8 * 208 */
32+
33+
/*----------
34+
* MaxHeapAttributeNumber limits the number of (user) columns in a table.
35+
* This should be somewhat less than MaxTupleAttributeNumber. It must be
36+
* at least one less, else we will fail to do UPDATEs on a maximal-width
37+
* table (because UPDATE has to form working tuples that include CTID).
38+
* In practice we want some additional daylight so that we can gracefully
39+
* support operations that add hidden "resjunk" columns, for example
40+
* SELECT * FROM wide_table ORDER BY foo, bar, baz.
41+
* In any case, depending on column data types you will likely be running
42+
* into the disk-block-based limit on overall tuple size if you have more
43+
* than a thousand or so columns. TOAST won't help.
44+
*----------
3145
*/
3246
#defineMaxHeapAttributeNumber1600/* 8 * 200 */
3347

3448
/*
35-
* This is the on-disk copy of the tuple.
49+
* On-disk heap tuple header. Currently this is also used as the header
50+
* format for tuples formed in memory, although in principle they could
51+
* be different.
3652
*
3753
* To avoid wasting space, the attributes should be layed out in such a
38-
* way to reduce structure padding.
54+
* way to reduce structure padding. Note that t_hoff is the offset to
55+
* the start of the user data, and so must be a multiple of MAXALIGN.
56+
* Also note that we omit the nulls bitmap if t_infomask shows that there
57+
* are no nulls in the tuple.
3958
*/
4059
typedefstructHeapTupleHeaderData
4160
{
@@ -51,14 +70,13 @@ typedef struct HeapTupleHeaderData
5170

5271
int16t_natts;/* number of attributes */
5372

54-
uint16t_infomask;/* variousinfos */
73+
uint16t_infomask;/* variousflag bits, see below */
5574

56-
uint8t_hoff;/* sizeof() tupleheader */
75+
uint8t_hoff;/* sizeofheader incl. bitmap, padding */
5776

5877
/* ^ - 31 bytes - ^ */
5978

60-
bits8t_bits[MinHeapTupleBitmapSize /8];
61-
/* bit map of NULLs */
79+
bits8t_bits[1];/* bitmap of NULLs -- VARIABLE LENGTH */
6280

6381
/* MORE DATA FOLLOWS AT END OF STRUCT */
6482
}HeapTupleHeaderData;
@@ -183,7 +201,7 @@ typedef struct xl_heap_clean
183201
#defineFirstLowInvalidHeapAttributeNumber(-8)
184202

185203
/*
186-
*This isthe in-memorycopy of the tuple.
204+
*HeapTupleData isan in-memorydata structure that points to a tuple.
187205
*
188206
* This new HeapTuple for version >= 6.5 and this is why it was changed:
189207
*
@@ -222,11 +240,9 @@ typedef HeapTupleData *HeapTuple;
222240

223241
/*
224242
* BITMAPLEN(NATTS) -
225-
*Computesminimumsize of bitmap given number ofdomains.
243+
*Computes size ofnullbitmap given number ofdata columns.
226244
*/
227-
#defineBITMAPLEN(NATTS) \
228-
((((((int)(NATTS) - 1) >> 3) + 4 - (MinHeapTupleBitmapSize >> 3)) \
229-
& ~03) + (MinHeapTupleBitmapSize >> 3))
245+
#defineBITMAPLEN(NATTS)(((int)(NATTS) + 7) / 8)
230246

231247
/*
232248
* HeapTupleIsValid
@@ -240,26 +256,26 @@ typedef HeapTupleData *HeapTuple;
240256
#defineHEAP_HASNULL0x0001/* has null attribute(s) */
241257
#defineHEAP_HASVARLENA0x0002/* has variable length
242258
* attribute(s) */
243-
#defineHEAP_HASEXTERNAL0x0004/* has external stored */
244-
/* attribute(s) */
245-
#defineHEAP_HASCOMPRESSED0x0008/* has compressed stored */
246-
/* attribute(s) */
259+
#defineHEAP_HASEXTERNAL0x0004/* has external stored
260+
* attribute(s) */
261+
#defineHEAP_HASCOMPRESSED0x0008/* has compressed stored
262+
* attribute(s) */
247263
#defineHEAP_HASEXTENDED0x000C/* the two above combined */
248264

249-
#defineHEAP_XMAX_UNLOGGED0x0080/* to lock tuple for update */
250-
/* without logging */
265+
#defineHEAP_XMAX_UNLOGGED0x0080/* to lock tuple for update
266+
* without logging */
251267
#defineHEAP_XMIN_COMMITTED0x0100/* t_xmin committed */
252268
#defineHEAP_XMIN_INVALID0x0200/* t_xmin invalid/aborted */
253269
#defineHEAP_XMAX_COMMITTED0x0400/* t_xmax committed */
254270
#defineHEAP_XMAX_INVALID0x0800/* t_xmax invalid/aborted */
255271
#defineHEAP_MARKED_FOR_UPDATE0x1000/* marked for UPDATE */
256272
#defineHEAP_UPDATED0x2000/* this is UPDATEd version of row */
257-
#defineHEAP_MOVED_OFF0x4000/*removed ormoved to another
258-
*place byvacuum */
273+
#defineHEAP_MOVED_OFF0x4000/* moved to another place by
274+
* vacuum */
259275
#defineHEAP_MOVED_IN0x8000/* moved from another place by
260276
* vacuum */
261277

262-
#defineHEAP_XACT_MASK0xFFF0/* */
278+
#defineHEAP_XACT_MASK0xFFF0/*visibility-related bits*/
263279

264280
#defineHeapTupleNoNulls(tuple) \
265281
(!(((HeapTuple) (tuple))->t_data->t_infomask & HEAP_HASNULL))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp