Clean up comments to be careful about the distinction between variable-

width types and varlena types, since with the introduction of CSTRING as
a more-or-less-real type, these concepts aren't identical.  I've tried to
use varlena consistently to denote datatypes with typlen = -1, ie, they
have a length word and are potentially TOASTable; while the term variable
width covers both varlena and cstring (and, perhaps, someday other types
with other rules for computing the actual width).  No code changes in this
commit except for renaming a couple macros.
This commit is contained in:
Tom Lane 2002-08-25 17:20:01 +00:00
parent d46172e4fa
commit 58de480999
11 changed files with 66 additions and 68 deletions

View File

@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.79 2002/08/24 15:00:45 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.80 2002/08/25 17:20:00 tgl Exp $
* *
* NOTES * NOTES
* The old interface functions have been converted to macros * The old interface functions have been converted to macros
@ -116,7 +116,7 @@ DataFill(char *data,
else if (att[i]->attlen == -1) else if (att[i]->attlen == -1)
{ {
/* varlena */ /* varlena */
*infomask |= HEAP_HASVARLENA; *infomask |= HEAP_HASVARWIDTH;
if (VARATT_IS_EXTERNAL(value[i])) if (VARATT_IS_EXTERNAL(value[i]))
*infomask |= HEAP_HASEXTERNAL; *infomask |= HEAP_HASEXTERNAL;
if (VARATT_IS_COMPRESSED(value[i])) if (VARATT_IS_COMPRESSED(value[i]))
@ -127,7 +127,7 @@ DataFill(char *data,
else if (att[i]->attlen == -2) else if (att[i]->attlen == -2)
{ {
/* cstring */ /* cstring */
*infomask |= HEAP_HASVARLENA; *infomask |= HEAP_HASVARWIDTH;
data_length = strlen(DatumGetCString(value[i])) + 1; data_length = strlen(DatumGetCString(value[i])) + 1;
memcpy(data, DatumGetPointer(value[i]), data_length); memcpy(data, DatumGetPointer(value[i]), data_length);
} }
@ -230,9 +230,9 @@ nocachegetattr(HeapTuple tuple,
/* ---------------- /* ----------------
* Three cases: * Three cases:
* *
* 1: No nulls and no variable length attributes. * 1: No nulls and no variable-width attributes.
* 2: Has a null or a varlena AFTER att. * 2: Has a null or a var-width AFTER att.
* 3: Has nulls or varlenas BEFORE att. * 3: Has nulls or var-widths BEFORE att.
* ---------------- * ----------------
*/ */
@ -326,7 +326,7 @@ nocachegetattr(HeapTuple tuple,
/* /*
* If slow is false, and we got here, we know that we have a tuple * If slow is false, and we got here, we know that we have a tuple
* with no nulls or varlenas before the target attribute. If possible, * with no nulls or var-widths before the target attribute. If possible,
* we also want to initialize the remainder of the attribute cached * we also want to initialize the remainder of the attribute cached
* offset values. * offset values.
*/ */

View File

@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/common/indextuple.c,v 1.58 2002/08/24 15:00:45 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/access/common/indextuple.c,v 1.59 2002/08/25 17:20:00 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -151,7 +151,7 @@ index_formtuple(TupleDesc tupleDescriptor,
* already set the hasnull bit above. * already set the hasnull bit above.
*/ */
if (tupmask & HEAP_HASVARLENA) if (tupmask & HEAP_HASVARWIDTH)
infomask |= INDEX_VAR_MASK; infomask |= INDEX_VAR_MASK;
/* /*
@ -211,9 +211,9 @@ nocache_index_getattr(IndexTuple tup,
/* ---------------- /* ----------------
* Three cases: * Three cases:
* *
* 1: No nulls and no variable length attributes. * 1: No nulls and no variable-width attributes.
* 2: Has a null or a varlena AFTER att. * 2: Has a null or a var-width AFTER att.
* 3: Has nulls or varlenas BEFORE att. * 3: Has nulls or var-widths BEFORE att.
* ---------------- * ----------------
*/ */
@ -302,7 +302,7 @@ nocache_index_getattr(IndexTuple tup,
return fetchatt(att[attnum], return fetchatt(att[attnum],
tp + att[attnum]->attcacheoff); tp + att[attnum]->attcacheoff);
} }
else if (IndexTupleHasVarlenas(tup)) else if (IndexTupleHasVarwidths(tup))
{ {
int j; int j;
@ -319,7 +319,7 @@ nocache_index_getattr(IndexTuple tup,
/* /*
* If slow is false, and we got here, we know that we have a tuple * If slow is false, and we got here, we know that we have a tuple
* with no nulls or varlenas before the target attribute. If possible, * with no nulls or var-widths before the target attribute. If possible,
* we also want to initialize the remainder of the attribute cached * we also want to initialize the remainder of the attribute cached
* offset values. * offset values.
*/ */

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.128 2002/08/22 00:01:42 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.129 2002/08/25 17:20:00 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -261,7 +261,7 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint)
foreach(le, stmt->args) foreach(le, stmt->args)
{ {
char *ar = ((Value *) lfirst(le))->val.str; char *ar = strVal(lfirst(le));
len += strlen(ar) + 4; len += strlen(ar) + 4;
for (; *ar; ar++) for (; *ar; ar++)
@ -274,7 +274,7 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint)
args[0] = '\0'; args[0] = '\0';
foreach(le, stmt->args) foreach(le, stmt->args)
{ {
char *s = ((Value *) lfirst(le))->val.str; char *s = strVal(lfirst(le));
char *d = args + strlen(args); char *d = args + strlen(args);
while (*s) while (*s)
@ -653,8 +653,6 @@ RelationBuildTriggers(Relation relation)
ScanKeyData skey; ScanKeyData skey;
SysScanDesc tgscan; SysScanDesc tgscan;
HeapTuple htup; HeapTuple htup;
struct varlena *val;
bool isnull;
triggers = (Trigger *) MemoryContextAlloc(CacheMemoryContext, triggers = (Trigger *) MemoryContextAlloc(CacheMemoryContext,
ntrigs * sizeof(Trigger)); ntrigs * sizeof(Trigger));
@ -702,12 +700,14 @@ RelationBuildTriggers(Relation relation)
FUNC_MAX_ARGS * sizeof(int16)); FUNC_MAX_ARGS * sizeof(int16));
if (build->tgnargs > 0) if (build->tgnargs > 0)
{ {
bytea *val;
bool isnull;
char *p; char *p;
int i; int i;
val = (struct varlena *) fastgetattr(htup, val = (bytea *) fastgetattr(htup,
Anum_pg_trigger_tgargs, Anum_pg_trigger_tgargs,
tgrel->rd_att, &isnull); tgrel->rd_att, &isnull);
if (isnull) if (isnull)
elog(ERROR, "RelationBuildTriggers: tgargs IS NULL for rel %s", elog(ERROR, "RelationBuildTriggers: tgargs IS NULL for rel %s",
RelationGetRelationName(relation)); RelationGetRelationName(relation));

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.107 2002/08/05 03:29:17 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.108 2002/08/25 17:20:01 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -50,7 +50,7 @@ static List *IdArrayToList(IdList *oldarray);
* fputs_quote * fputs_quote
* *
* Outputs string in quotes, with double-quotes duplicated. * Outputs string in quotes, with double-quotes duplicated.
* We could use quote_ident(), but that expects varlena. * We could use quote_ident(), but that expects a TEXT argument.
*/ */
static void fputs_quote(char *str, FILE *fp) static void fputs_quote(char *str, FILE *fp)
{ {

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.61 2002/06/20 20:29:28 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.62 2002/08/25 17:20:01 tgl Exp $
* *
* NOTES * NOTES
* This should be moved to a more appropriate place. It is here * This should be moved to a more appropriate place. It is here
@ -313,24 +313,24 @@ loread(PG_FUNCTION_ARGS)
{ {
int32 fd = PG_GETARG_INT32(0); int32 fd = PG_GETARG_INT32(0);
int32 len = PG_GETARG_INT32(1); int32 len = PG_GETARG_INT32(1);
struct varlena *retval; bytea *retval;
int totalread; int totalread;
if (len < 0) if (len < 0)
len = 0; len = 0;
retval = (struct varlena *) palloc(VARHDRSZ + len); retval = (bytea *) palloc(VARHDRSZ + len);
totalread = lo_read(fd, VARDATA(retval), len); totalread = lo_read(fd, VARDATA(retval), len);
VARATT_SIZEP(retval) = totalread + VARHDRSZ; VARATT_SIZEP(retval) = totalread + VARHDRSZ;
PG_RETURN_POINTER(retval); PG_RETURN_BYTEA_P(retval);
} }
Datum Datum
lowrite(PG_FUNCTION_ARGS) lowrite(PG_FUNCTION_ARGS)
{ {
int32 fd = PG_GETARG_INT32(0); int32 fd = PG_GETARG_INT32(0);
struct varlena *wbuf = PG_GETARG_VARLENA_P(1); bytea *wbuf = PG_GETARG_BYTEA_P(1);
int bytestowrite; int bytestowrite;
int totalwritten; int totalwritten;

View File

@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.94 2002/08/05 03:29:17 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.95 2002/08/25 17:20:01 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -396,7 +396,7 @@ inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes)
bool pfreeit; bool pfreeit;
struct struct
{ {
struct varlena hdr; bytea hdr;
char data[LOBLKSIZE]; char data[LOBLKSIZE];
} workbuf; } workbuf;
char *workb = VARATT_DATA(&workbuf.hdr); char *workb = VARATT_DATA(&workbuf.hdr);

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* 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.57 2002/07/20 05:16:59 momjian Exp $ * $Id: htup.h,v 1.58 2002/08/25 17:20:01 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -95,8 +95,7 @@ typedef HeapTupleHeaderData *HeapTupleHeader;
* information stored in t_infomask: * information stored in t_infomask:
*/ */
#define HEAP_HASNULL 0x0001 /* has null attribute(s) */ #define HEAP_HASNULL 0x0001 /* has null attribute(s) */
#define HEAP_HASVARLENA 0x0002 /* has variable length #define HEAP_HASVARWIDTH 0x0002 /* has variable-width attribute(s) */
* attribute(s) */
#define HEAP_HASEXTERNAL 0x0004 /* has external stored #define HEAP_HASEXTERNAL 0x0004 /* has external stored
* attribute(s) */ * attribute(s) */
#define HEAP_HASCOMPRESSED 0x0008 /* has compressed stored #define HEAP_HASCOMPRESSED 0x0008 /* has compressed stored
@ -425,7 +424,7 @@ typedef HeapTupleData *HeapTuple;
(!(((HeapTuple) (tuple))->t_data->t_infomask & HEAP_HASNULL)) (!(((HeapTuple) (tuple))->t_data->t_infomask & HEAP_HASNULL))
#define HeapTupleAllFixed(tuple) \ #define HeapTupleAllFixed(tuple) \
(!(((HeapTuple) (tuple))->t_data->t_infomask & HEAP_HASVARLENA)) (!(((HeapTuple) (tuple))->t_data->t_infomask & HEAP_HASVARWIDTH))
#define HeapTupleHasExternal(tuple) \ #define HeapTupleHasExternal(tuple) \
((((HeapTuple)(tuple))->t_data->t_infomask & HEAP_HASEXTERNAL) != 0) ((((HeapTuple)(tuple))->t_data->t_infomask & HEAP_HASEXTERNAL) != 0)

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: itup.h,v 1.35 2002/06/20 20:29:43 momjian Exp $ * $Id: itup.h,v 1.36 2002/08/25 17:20:01 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -28,7 +28,7 @@ typedef struct IndexTupleData
* t_info is layed out in the following fashion: * t_info is layed out in the following fashion:
* *
* 15th (high) bit: has nulls * 15th (high) bit: has nulls
* 14th bit: has varlenas * 14th bit: has var-width attributes
* 13th bit: unused * 13th bit: unused
* 12-0 bit: size of tuple * 12-0 bit: size of tuple
* --------------- * ---------------
@ -67,7 +67,7 @@ typedef InsertIndexResultData *InsertIndexResult;
#define IndexTupleSize(itup) ((Size) (((IndexTuple) (itup))->t_info & INDEX_SIZE_MASK)) #define IndexTupleSize(itup) ((Size) (((IndexTuple) (itup))->t_info & INDEX_SIZE_MASK))
#define IndexTupleDSize(itup) ((Size) ((itup).t_info & INDEX_SIZE_MASK)) #define IndexTupleDSize(itup) ((Size) ((itup).t_info & INDEX_SIZE_MASK))
#define IndexTupleHasNulls(itup) ((((IndexTuple) (itup))->t_info & INDEX_NULL_MASK)) #define IndexTupleHasNulls(itup) ((((IndexTuple) (itup))->t_info & INDEX_NULL_MASK))
#define IndexTupleHasVarlenas(itup) ((((IndexTuple) (itup))->t_info & INDEX_VAR_MASK)) #define IndexTupleHasVarwidths(itup) ((((IndexTuple) (itup))->t_info & INDEX_VAR_MASK))
#define IndexTupleHasMinHeader(itup) (!IndexTupleHasNulls(itup)) #define IndexTupleHasMinHeader(itup) (!IndexTupleHasNulls(itup))

View File

@ -4,15 +4,15 @@
* Fundamental C definitions. This is included by every .c file in * Fundamental C definitions. This is included by every .c file in
* PostgreSQL (via either postgres.h or postgres_fe.h, as appropriate). * PostgreSQL (via either postgres.h or postgres_fe.h, as appropriate).
* *
* Note that the definitions here are not intended to be exposed to clients of * Note that the definitions here are not intended to be exposed to clients
* the frontend interface libraries --- so we don't worry much about polluting * of the frontend interface libraries --- so we don't worry much about
* the namespace with lots of stuff... * polluting the namespace with lots of stuff...
* *
* *
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: c.h,v 1.122 2002/08/21 17:20:58 petere Exp $ * $Id: c.h,v 1.123 2002/08/25 17:20:01 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -36,18 +36,19 @@
* 8) system-specific hacks * 8) system-specific hacks
* *
* NOTE: since this file is included by both frontend and backend modules, it's * NOTE: since this file is included by both frontend and backend modules, it's
* almost certainly wrong to put an "extern" declaration here. typedefs and macros * almost certainly wrong to put an "extern" declaration here. typedefs and
* are the kind of thing that might go here. * macros are the kind of thing that might go here.
* *
*---------------------------------------------------------------- *----------------------------------------------------------------
*/ */
#ifndef C_H #ifndef C_H
#define C_H #define C_H
/* We have to include stdlib.h here because it defines many of these macros /*
on some platforms, and we only want our definitions used if stdlib.h doesn't * We have to include stdlib.h here because it defines many of these macros
have its own. The same goes for stddef and stdarg if present. * on some platforms, and we only want our definitions used if stdlib.h doesn't
*/ * have its own. The same goes for stddef and stdarg if present.
*/
#include "pg_config.h" #include "pg_config.h"
#include "postgres_ext.h" #include "postgres_ext.h"
@ -387,10 +388,11 @@ typedef struct
/* ---------------- /* ----------------
* Variable-length datatypes all share the 'struct varlena' header. * Variable-length datatypes all share the 'struct varlena' header.
* *
* NOTE: for TOASTable types, this is an oversimplification, since the value may be * NOTE: for TOASTable types, this is an oversimplification, since the value
* compressed or moved out-of-line. However datatype-specific routines are mostly * may be compressed or moved out-of-line. However datatype-specific routines
* content to deal with de-TOASTed values only, and of course client-side routines * are mostly content to deal with de-TOASTed values only, and of course
* should never see a TOASTed value. See postgres.h for details of the TOASTed form. * client-side routines should never see a TOASTed value. See postgres.h for
* details of the TOASTed form.
* ---------------- * ----------------
*/ */
struct varlena struct varlena
@ -662,9 +664,4 @@ extern int vsnprintf(char *str, size_t count, const char *fmt, va_list args);
#define memmove(d, s, c) bcopy(s, d, c) #define memmove(d, s, c) bcopy(s, d, c)
#endif #endif
/* ----------------
* end of c.h
* ----------------
*/
#endif /* C_H */ #endif /* C_H */

View File

@ -8,7 +8,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: pg_statistic.h,v 1.16 2002/06/20 20:29:49 momjian Exp $ * $Id: pg_statistic.h,v 1.17 2002/08/25 17:20:01 tgl Exp $
* *
* NOTES * NOTES
* the genbki.sh script reads this file and generates .bki * the genbki.sh script reads this file and generates .bki
@ -43,7 +43,7 @@ CATALOG(pg_statistic) BKI_WITHOUT_OIDS
/* /*
* stawidth is the average width in bytes of non-null entries. For * stawidth is the average width in bytes of non-null entries. For
* fixed-width datatypes this is of course the same as the typlen, but * fixed-width datatypes this is of course the same as the typlen, but
* for varlena types it is more useful. Note that this is the average * for var-width types it is more useful. Note that this is the average
* width of the data as actually stored, post-TOASTing (eg, for a * width of the data as actually stored, post-TOASTing (eg, for a
* moved-out-of-line value, only the size of the pointer object is * moved-out-of-line value, only the size of the pointer object is
* counted). This is the appropriate definition for the primary use * counted). This is the appropriate definition for the primary use

View File

@ -10,7 +10,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1995, Regents of the University of California * Portions Copyright (c) 1995, Regents of the University of California
* *
* $Id: postgres.h,v 1.59 2002/08/10 20:29:18 momjian Exp $ * $Id: postgres.h,v 1.60 2002/08/25 17:20:01 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -30,14 +30,15 @@
* *
* NOTES * NOTES
* *
* In general, this file should contain declarations that are widely needed in the * In general, this file should contain declarations that are widely needed
* backend environment, but are of no interest outside the backend. * in the backend environment, but are of no interest outside the backend.
* *
* Simple type definitions live in c.h, where they are shared with postgres_fe.h. * Simple type definitions live in c.h, where they are shared with
* We do that since those type definitions are needed by frontend modules that want * postgres_fe.h. We do that since those type definitions are needed by
* to deal with binary data transmission to or from the backend. Type definitions * frontend modules that want to deal with binary data transmission to or
* in this file should be for representations that never escape the backend, such * from the backend. Type definitions in this file should be for
* as Datum or TOASTed varlena objects. * representations that never escape the backend, such as Datum or
* TOASTed varlena objects.
* *
*---------------------------------------------------------------- *----------------------------------------------------------------
*/ */
@ -54,7 +55,8 @@
*/ */
/* ---------------- /* ----------------
* struct varattrib is the header of a varlena object that may have been TOASTed. * struct varattrib is the header of a varlena object that may have been
* TOASTed.
* ---------------- * ----------------
*/ */
#define TUPLE_TOASTER_ACTIVE #define TUPLE_TOASTER_ACTIVE