Commit 02241774 authored by Tom Lane's avatar Tom Lane

TOAST mop-up work: update comments for tuple-size-related symbols such

as MaxHeapAttributeNumber.  Increase MaxAttrSize to something more
reasonable (given what it's used for, namely checking char(n) declarations,
I didn't make it the full 1G that it could theoretically be --- 10Mb
seemed a more reasonable number).  Improve calculation of MaxTupleSize.
parent d2165a4a
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.183 2000/08/07 06:54:51 thomas Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.184 2000/08/07 20:16:13 tgl Exp $
* *
* HISTORY * HISTORY
* AUTHOR DATE MAJOR EVENT * AUTHOR DATE MAJOR EVENT
...@@ -4153,10 +4153,11 @@ Bit: bit '(' Iconst ')' ...@@ -4153,10 +4153,11 @@ Bit: bit '(' Iconst ')'
$$ = makeNode(TypeName); $$ = makeNode(TypeName);
$$->name = $1; $$->name = $1;
if ($3 < 1) if ($3 < 1)
elog(ERROR,"length for type '%s' must be at least 1",$1); elog(ERROR,"length for type '%s' must be at least 1",
else if ($3 > (MaxAttrSize * sizeof(char))) $1);
elog(ERROR,"length for type '%s' cannot exceed %ld",$1, else if ($3 > (MaxAttrSize * BITSPERBYTE))
(MaxAttrSize * sizeof(char))); elog(ERROR,"length for type '%s' cannot exceed %d",
$1, (MaxAttrSize * BITSPERBYTE));
$$->typmod = $3; $$->typmod = $3;
} }
| bit | bit
...@@ -4187,10 +4188,11 @@ Character: character '(' Iconst ')' ...@@ -4187,10 +4188,11 @@ Character: character '(' Iconst ')'
$$ = makeNode(TypeName); $$ = makeNode(TypeName);
$$->name = $1; $$->name = $1;
if ($3 < 1) if ($3 < 1)
elog(ERROR,"length for type '%s' must be at least 1",$1); elog(ERROR,"length for type '%s' must be at least 1",
$1);
else if ($3 > MaxAttrSize) else if ($3 > MaxAttrSize)
elog(ERROR,"length for type '%s' cannot exceed %ld",$1, elog(ERROR,"length for type '%s' cannot exceed %d",
MaxAttrSize); $1, MaxAttrSize);
/* we actually implement these like a varlen, so /* we actually implement these like a varlen, so
* the first 4 bytes is the length. (the difference * the first 4 bytes is the length. (the difference
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* Functions for the built-in type bit() and varying bit(). * Functions for the built-in type bit() and varying bit().
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varbit.c,v 1.6 2000/07/28 02:13:31 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/varbit.c,v 1.7 2000/08/07 20:15:37 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -107,7 +107,7 @@ zpbit_in(char *s, int dummy, int32 atttypmod) ...@@ -107,7 +107,7 @@ zpbit_in(char *s, int dummy, int32 atttypmod)
if (len > MaxAttrSize) if (len > MaxAttrSize)
elog(ERROR, "zpbit_in: length of bit() must be less than %ld", elog(ERROR, "zpbit_in: length of bit() must be less than %ld",
(MaxAttrSize - VARHDRSZ - VARBITHDRSZ) * BITSPERBYTE); (long) ((MaxAttrSize - VARHDRSZ - VARBITHDRSZ) * BITSPERBYTE));
result = (bits8 *) palloc(len); result = (bits8 *) palloc(len);
/* set to 0 so that *r is always initialised and strin is zero-padded */ /* set to 0 so that *r is always initialised and strin is zero-padded */
...@@ -338,7 +338,7 @@ varbit_in(char *s, int dummy, int32 atttypmod) ...@@ -338,7 +338,7 @@ varbit_in(char *s, int dummy, int32 atttypmod)
if (len > MaxAttrSize) if (len > MaxAttrSize)
elog(ERROR, "varbit_in: length of bit() must be less than %ld", elog(ERROR, "varbit_in: length of bit() must be less than %ld",
(MaxAttrSize - VARHDRSZ - VARBITHDRSZ) * BITSPERBYTE); (long) ((MaxAttrSize - VARHDRSZ - VARBITHDRSZ) * BITSPERBYTE));
result = (bits8 *) palloc(len); result = (bits8 *) palloc(len);
/* set to 0 so that *r is always initialised and strin is zero-padded */ /* set to 0 so that *r is always initialised and strin is zero-padded */
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: htup.h,v 1.33 2000/07/04 01:49:43 vadim Exp $ * $Id: htup.h,v 1.34 2000/08/07 20:15:40 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -18,8 +18,16 @@ ...@@ -18,8 +18,16 @@
#define MinHeapTupleBitmapSize 32 /* 8 * 4 */ #define MinHeapTupleBitmapSize 32 /* 8 * 4 */
/* check these, they are likely to be more severely limited by t_hoff */ /*
* MaxHeapAttributeNumber limits the number of (user) columns in a table.
* The key limit on this value is that the size of the fixed overhead for
* a tuple, plus the size of the null-values bitmap (at 1 bit per column),
* plus MAXALIGN alignment, must fit into t_hoff which is uint8. On most
* machines the absolute upper limit without making t_hoff wider would be
* about 1700. Note, however, that depending on column data types you will
* likely also be running into the disk-block-based limit on overall tuple
* size if you have more than a thousand or so columns. TOAST won't help.
*/
#define MaxHeapAttributeNumber 1600 /* 8 * 200 */ #define MaxHeapAttributeNumber 1600 /* 8 * 200 */
/* /*
...@@ -130,13 +138,32 @@ typedef struct xl_heap_move ...@@ -130,13 +138,32 @@ typedef struct xl_heap_move
#endif /* XLOG */ #endif /* XLOG */
#define MinTupleSize (MAXALIGN(sizeof (PageHeaderData)) + \
MAXALIGN(sizeof(HeapTupleHeaderData)) + \
MAXALIGN(sizeof(char)))
#define MaxTupleSize (BLCKSZ - MinTupleSize) /*
* MaxTupleSize is the maximum allowed size of a tuple, including header and
* MAXALIGN alignment padding. Basically it's BLCKSZ minus the other stuff
* that has to be on a disk page. The "other stuff" includes access-method-
* dependent "special space", which we assume will be no more than
* MaxSpecialSpace bytes (currently, on heap pages it's actually zero).
*
* NOTE: we do not need to count an ItemId for the tuple because
* sizeof(PageHeaderData) includes the first ItemId on the page.
*/
#define MaxSpecialSpace 32
#define MaxTupleSize \
(BLCKSZ - MAXALIGN(sizeof(PageHeaderData) + MaxSpecialSpace))
/*
* MaxAttrSize is a somewhat arbitrary upper limit on the declared size of
* data fields of char(n) and similar types. It need not have anything
* directly to do with the *actual* upper limit of varlena values, which
* is currently 1Gb (see struct varattrib in postgres.h). I've set it
* at 10Mb which seems like a reasonable number --- tgl 8/6/00.
*/
#define MaxAttrSize (10 * 1024 * 1024)
#define MaxAttrSize (MaxTupleSize - MAXALIGN(sizeof(HeapTupleHeaderData)))
#define SelfItemPointerAttributeNumber (-1) #define SelfItemPointerAttributeNumber (-1)
#define ObjectIdAttributeNumber (-2) #define ObjectIdAttributeNumber (-2)
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* or in config.h afterwards. Of course, if you edit config.h, then your * or in config.h afterwards. Of course, if you edit config.h, then your
* changes will be overwritten the next time you run configure. * changes will be overwritten the next time you run configure.
* *
* $Id: config.h.in,v 1.129 2000/08/07 00:51:38 tgl Exp $ * $Id: config.h.in,v 1.130 2000/08/07 20:15:44 tgl Exp $
*/ */
#ifndef CONFIG_H #ifndef CONFIG_H
...@@ -106,12 +106,16 @@ ...@@ -106,12 +106,16 @@
#define DEF_NBUFFERS (DEF_MAXBACKENDS > 8 ? DEF_MAXBACKENDS * 2 : 16) #define DEF_NBUFFERS (DEF_MAXBACKENDS > 8 ? DEF_MAXBACKENDS * 2 : 16)
/* /*
* Size of a disk block --- currently, this limits the size of a tuple. * Size of a disk block --- this also limits the size of a tuple.
* You can set it bigger if you need bigger tuples. * You can set it bigger if you need bigger tuples (although TOAST
* should reduce the need to have large tuples, since fields can now
* be spread across multiple tuples).
* *
* CAUTION: changing BLCKSZ requires an initdb. * The maximum possible value of BLCKSZ is currently 2^15 (32768).
* This is determined by the 15-bit widths of the lp_off and lp_len
* fields in ItemIdData (see include/storage/itemid.h).
* *
* currently must be <= 32k bjm * CAUTION: changing BLCKSZ requires an initdb.
*/ */
#define BLCKSZ 8192 #define BLCKSZ 8192
...@@ -213,6 +217,12 @@ ...@@ -213,6 +217,12 @@
*/ */
#define DEFAULT_MAX_EXPR_DEPTH 10000 #define DEFAULT_MAX_EXPR_DEPTH 10000
/*
* You can try changing this if you have a machine with bytes of another
* size, but no guarantee...
*/
#define BITSPERBYTE 8
/* /*
*------------------------------------------------------------------------ *------------------------------------------------------------------------
* These hand-configurable symbols are for enabling debugging code, * These hand-configurable symbols are for enabling debugging code,
......
...@@ -7,36 +7,21 @@ ...@@ -7,36 +7,21 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: bufmgr.h,v 1.39 2000/06/15 03:33:00 momjian Exp $ * $Id: bufmgr.h,v 1.40 2000/08/07 20:15:50 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#ifndef BUFMGR_H #ifndef BUFMGR_H
#define BUFMGR_H #define BUFMGR_H
#include "storage/buf_internals.h" #include "storage/buf_internals.h"
/*
* the maximum size of a disk block for any possible installation.
*
* in theory this could be anything, but in practice this is actually
* limited to 2^13 bytes because we have limited ItemIdData.lp_off and
* ItemIdData.lp_len to 13 bits (see itemid.h).
*
* limit is now 2^15. Took four bits from ItemIdData.lp_flags and gave
* two apiece to ItemIdData.lp_len and lp_off. darrenk 01/06/98
*
*/
#define MAXBLCKSZ 32768
typedef void *Block; typedef void *Block;
/* special pageno for bget */ /* special pageno for bget */
#define P_NEW InvalidBlockNumber /* grow the file to get a new page */ #define P_NEW InvalidBlockNumber /* grow the file to get a new page */
typedef bits16 BufferLock;
/********************************************************************** /**********************************************************************
......
...@@ -7,38 +7,48 @@ ...@@ -7,38 +7,48 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: itemid.h,v 1.10 2000/01/26 05:58:33 momjian Exp $ * $Id: itemid.h,v 1.11 2000/08/07 20:15:50 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#ifndef ITEMID_H #ifndef ITEMID_H
#define ITEMID_H #define ITEMID_H
typedef uint16 ItemOffset;
typedef uint16 ItemLength;
typedef bits16 ItemIdFlags;
/*
* An item pointer (also called line pointer) on a buffer page
*/
typedef struct ItemIdData typedef struct ItemIdData
{ /* line pointers */ { /* line pointers */
unsigned lp_off:15, /* offset to find tup */ unsigned lp_off:15, /* offset to start of tuple */
/* can be reduced by 2 if necc. */ lp_flags:2, /* flags for tuple */
lp_flags:2, /* flags on tuple */
lp_len:15; /* length of tuple */ lp_len:15; /* length of tuple */
} ItemIdData; } ItemIdData;
typedef struct ItemIdData *ItemId; typedef ItemIdData *ItemId;
#ifndef LP_USED /*
* lp_flags contains these flags:
*/
#define LP_USED 0x01 /* this line pointer is being used */ #define LP_USED 0x01 /* this line pointer is being used */
#endif /* currently, there is one unused flag bit ... */
/*
* Item offsets, lengths, and flags are represented by these types when
* they're not actually stored in an ItemIdData.
*/
typedef uint16 ItemOffset;
typedef uint16 ItemLength;
typedef bits16 ItemIdFlags;
/* ---------------- /* ----------------
* support macros * support macros
* ---------------- * ----------------
*/ */
/* /*
* ItemIdGetLength * ItemIdGetLength
*/ */
......
...@@ -18,8 +18,6 @@ struct varbita ...@@ -18,8 +18,6 @@ struct varbita
bits8 vl_dat[1]; bits8 vl_dat[1];
}; };
#undef BITSPERBYTE /* sometimes declared in <values.h> */
#define BITSPERBYTE 8
#define VARBITHDRSZ sizeof(int32) #define VARBITHDRSZ sizeof(int32)
/* Number of bits in this bit string */ /* Number of bits in this bit string */
#define VARBITLEN(PTR) (((struct varbita *)VARDATA(PTR))->vl_len) #define VARBITLEN(PTR) (((struct varbita *)VARDATA(PTR))->vl_len)
......
...@@ -3114,12 +3114,13 @@ Bit: bit '(' Iconst ')' ...@@ -3114,12 +3114,13 @@ Bit: bit '(' Iconst ')'
if (atol($3) < 1) if (atol($3) < 1)
{ {
sprintf(errortext,"length for type '%s' must be at least 1",$1); sprintf(errortext,"length for type '%s' must be at least 1",$1);
mmerror(ET_ERROR, errortext); mmerror(ET_ERROR, errortext);
} }
else if (atol($3) > (MaxAttrSize *sizeof(char))) else if (atol($3) > (MaxAttrSize * BITSPERBYTE))
{ {
sprintf(errortext, "length for type '%s' cannot exceed %ld", $1, sprintf(errortext, "length for type '%s' cannot exceed %d", $1,
(MaxAttrSize * sizeof(char))); (MaxAttrSize * BITSPERBYTE));
mmerror(ET_ERROR, errortext);
} }
} }
| bit | bit
...@@ -3147,7 +3148,7 @@ Character: character '(' Iconst ')' ...@@ -3147,7 +3148,7 @@ Character: character '(' Iconst ')'
} }
else if (atol($3) > MaxAttrSize) else if (atol($3) > MaxAttrSize)
{ {
sprintf(errortext, "length for type '%s' cannot exceed %ld", $1, MaxAttrSize); sprintf(errortext, "length for type '%s' cannot exceed %d", $1, MaxAttrSize);
mmerror(ET_ERROR, errortext); mmerror(ET_ERROR, errortext);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment