From eba41848aafd2d109c38009466e135d672a6a41f Mon Sep 17 00:00:00 2001
From: Bruce Momjian <bruce@momjian.us>
Date: Sun, 4 Jul 1999 04:56:02 +0000
Subject: [PATCH] Clarify maximum tuple and max attribute lengths.

---
 src/backend/parser/gram.y             |  6 +++---
 src/backend/utils/adt/varchar.c       | 18 +++++++++---------
 src/include/access/htup.h             |  6 ++++--
 src/interfaces/ecpg/preproc/preproc.y |  4 ++--
 4 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index dcb61ec1329..88438af70c8 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -10,7 +10,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.85 1999/07/03 00:32:44 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.86 1999/07/04 04:55:59 momjian Exp $
  *
  * HISTORY
  *	  AUTHOR			DATE			MAJOR EVENT
@@ -3385,9 +3385,9 @@ Character:  character '(' Iconst ')'
 
 					if ($3 < 1)
 						elog(ERROR,"length for '%s' type must be at least 1",$1);
-					else if ($3 > MaxTupleSize)
+					else if ($3 > MaxAttrSize)
 						elog(ERROR,"length for type '%s' cannot exceed %d",$1,
-							MaxTupleSize);
+							MaxAttrSize);
 
 					/* we actually implement this sort of like a varlen, so
 					 * the first 4 bytes is the length. (the difference
diff --git a/src/backend/utils/adt/varchar.c b/src/backend/utils/adt/varchar.c
index 1f1b8d64975..d7bb2738cb8 100644
--- a/src/backend/utils/adt/varchar.c
+++ b/src/backend/utils/adt/varchar.c
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.47 1999/07/03 00:32:50 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.48 1999/07/04 04:56:00 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -82,9 +82,9 @@ bpcharin(char *s, int dummy, int32 atttypmod)
 	else
 		len = atttypmod - VARHDRSZ;
 
-	if (len > MaxTupleSize)
+	if (len > MaxAttrSize)
 		elog(ERROR, "bpcharin: length of char() must be less than %d",
-				MaxTupleSize);
+				MaxAttrSize);
 
 	result = (char *) palloc(atttypmod);
 	VARSIZE(result) = atttypmod;
@@ -153,9 +153,9 @@ bpchar(char *s, int32 len)
 
 	rlen = len - VARHDRSZ;
 
-	if (rlen > MaxTupleSize)
+	if (rlen > MaxAttrSize)
 		elog(ERROR, "bpchar: length of char() must be less than %d",
-			MaxTupleSize);
+			MaxAttrSize);
 
 #ifdef STRINGDEBUG
 	printf("bpchar- convert string length %d (%d) ->%d (%d)\n",
@@ -335,9 +335,9 @@ varcharin(char *s, int dummy, int32 atttypmod)
 	if (atttypmod != -1 && len > atttypmod)
 		len = atttypmod;		/* clip the string at max length */
 
-	if (len > MaxTupleSize)
+	if (len > MaxAttrSize)
 		elog(ERROR, "varcharin: length of char() must be less than %d",
-				MaxTupleSize);
+				MaxAttrSize);
 
 	result = (char *) palloc(len);
 	VARSIZE(result) = len;
@@ -407,9 +407,9 @@ varchar(char *s, int32 slen)
 	len = slen - VARHDRSZ;
 #endif
 
-	if (len > MaxTupleSize)
+	if (len > MaxAttrSize)
 		elog(ERROR, "varchar: length of varchar() must be less than %d",
-			MaxTupleSize);
+			MaxAttrSize);
 
 	result = (char *) palloc(slen);
 	VARSIZE(result) = slen;
diff --git a/src/include/access/htup.h b/src/include/access/htup.h
index 9ad5d4e123f..8eda1020d35 100644
--- a/src/include/access/htup.h
+++ b/src/include/access/htup.h
@@ -6,7 +6,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: htup.h,v 1.18 1999/07/03 01:57:53 momjian Exp $
+ * $Id: htup.h,v 1.19 1999/07/04 04:56:01 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -56,7 +56,9 @@ typedef HeapTupleHeaderData *HeapTupleHeader;
 #define MinTupleSize	(DOUBLEALIGN(sizeof (PageHeaderData) + \
 						 sizeof(HeapTupleHeaderData) + sizeof(int4)))
 
-#define MaxTupleSize	(BLCKSZ/2 - MinTupleSize)
+#define MaxTupleSize	(BLCKSZ - MinTupleSize)
+
+#define MaxAttrSize		(MaxTupleSize - sizeof(HeapTupleHeaderData))
 
 #define SelfItemPointerAttributeNumber			(-1)
 #define ObjectIdAttributeNumber					(-2)
diff --git a/src/interfaces/ecpg/preproc/preproc.y b/src/interfaces/ecpg/preproc/preproc.y
index 75127b308d9..bbb1e785b43 100644
--- a/src/interfaces/ecpg/preproc/preproc.y
+++ b/src/interfaces/ecpg/preproc/preproc.y
@@ -3354,8 +3354,8 @@ Character:  character '(' Iconst ')'
 						sprintf(errortext, "length for '%s' type must be at least 1",$1);
 						yyerror(errortext);
 					}
-					else if (atol($3) > MaxTupleSize) {
-						sprintf(errortext, "length for type '%s' cannot exceed %d",$1,MaxTupleSize);
+					else if (atol($3) > MaxAttrSize) {
+						sprintf(errortext, "length for type '%s' cannot exceed %d",$1,MaxAttrSize);
 						yyerror(errortext);
 					}
 
-- 
GitLab