diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2002-08-24 15:00:47 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2002-08-24 15:00:47 +0000 |
commit | 976246cc7e4d8b673fc62fe6daa61c76d94af1af (patch) | |
tree | b61ea3f5bbd8fa025587754bc90c3fd43889337c /src/backend/commands | |
parent | cf4d885c67744637d82f6fec657e8205578c5905 (diff) | |
download | postgresql-976246cc7e4d8b673fc62fe6daa61c76d94af1af.tar.gz postgresql-976246cc7e4d8b673fc62fe6daa61c76d94af1af.zip |
The cstring datatype can now be copied, passed around, etc. The typlen
value '-2' is used to indicate a variable-width type whose width is
computed as strlen(datum)+1. Everything that looks at typlen is updated
except for array support, which Joe Conway is working on; at the moment
it wouldn't work to try to create an array of cstring.
Diffstat (limited to 'src/backend/commands')
-rw-r--r-- | src/backend/commands/analyze.c | 24 | ||||
-rw-r--r-- | src/backend/commands/copy.c | 15 | ||||
-rw-r--r-- | src/backend/commands/tablecmds.c | 6 |
3 files changed, 34 insertions, 11 deletions
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c index 5dafb1a42ad..c7dbe44f780 100644 --- a/src/backend/commands/analyze.c +++ b/src/backend/commands/analyze.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.42 2002/08/11 00:08:48 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.43 2002/08/24 15:00:46 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -860,6 +860,8 @@ compute_minimal_stats(VacAttrStats *stats, double total_width = 0; bool is_varlena = (!stats->attr->attbyval && stats->attr->attlen == -1); + bool is_varwidth = (!stats->attr->attbyval && + stats->attr->attlen < 0); FmgrInfo f_cmpeq; typedef struct { @@ -905,7 +907,7 @@ compute_minimal_stats(VacAttrStats *stats, nonnull_cnt++; /* - * If it's a varlena field, add up widths for average width + * If it's a variable-width field, add up widths for average width * calculation. Note that if the value is toasted, we use the * toasted width. We don't bother with this calculation if it's a * fixed-width type. @@ -928,6 +930,11 @@ compute_minimal_stats(VacAttrStats *stats, } value = PointerGetDatum(PG_DETOAST_DATUM(value)); } + else if (is_varwidth) + { + /* must be cstring */ + total_width += strlen(DatumGetCString(value)) + 1; + } /* * See if the value matches anything we're already tracking. @@ -984,7 +991,7 @@ compute_minimal_stats(VacAttrStats *stats, stats->stats_valid = true; /* Do the simple null-frac and width stats */ stats->stanullfrac = (double) null_cnt / (double) numrows; - if (is_varlena) + if (is_varwidth) stats->stawidth = total_width / (double) nonnull_cnt; else stats->stawidth = stats->attrtype->typlen; @@ -1157,6 +1164,8 @@ compute_scalar_stats(VacAttrStats *stats, double total_width = 0; bool is_varlena = (!stats->attr->attbyval && stats->attr->attlen == -1); + bool is_varwidth = (!stats->attr->attbyval && + stats->attr->attlen < 0); double corr_xysum; RegProcedure cmpFn; SortFunctionKind cmpFnKind; @@ -1196,7 +1205,7 @@ compute_scalar_stats(VacAttrStats *stats, nonnull_cnt++; /* - * If it's a varlena field, add up widths for average width + * If it's a variable-width field, add up widths for average width * calculation. Note that if the value is toasted, we use the * toasted width. We don't bother with this calculation if it's a * fixed-width type. @@ -1219,6 +1228,11 @@ compute_scalar_stats(VacAttrStats *stats, } value = PointerGetDatum(PG_DETOAST_DATUM(value)); } + else if (is_varwidth) + { + /* must be cstring */ + total_width += strlen(DatumGetCString(value)) + 1; + } /* Add it to the list to be sorted */ values[values_cnt].value = value; @@ -1311,7 +1325,7 @@ compute_scalar_stats(VacAttrStats *stats, stats->stats_valid = true; /* Do the simple null-frac and width stats */ stats->stanullfrac = (double) null_cnt / (double) numrows; - if (is_varlena) + if (is_varwidth) stats->stawidth = total_width / (double) nonnull_cnt; else stats->stawidth = stats->attrtype->typlen; diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index e0bbe7560bb..c0b40c6e143 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.166 2002/08/22 00:01:42 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.167 2002/08/24 15:00:46 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -567,6 +567,8 @@ CopyTo(Relation rel, List *attnumlist, bool binary, bool oids, elog(ERROR, "COPY: couldn't lookup info for type %u", attr[attnum-1]->atttypid); fmgr_info(out_func_oid, &out_functions[attnum-1]); + if (binary && attr[attnum-1]->attlen == -2) + elog(ERROR, "COPY BINARY: cstring not supported"); } if (binary) @@ -820,9 +822,16 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids, fmgr_info(in_func_oid, &in_functions[i]); elements[i] = GetTypeElement(attr[i]->atttypid); - /* if column not specified, use default value if one exists */ - if (!intMember(i + 1, attnumlist)) + if (intMember(i + 1, attnumlist)) { + /* attribute is to be copied */ + if (binary && attr[i]->attlen == -2) + elog(ERROR, "COPY BINARY: cstring not supported"); + } + else + { + /* attribute is NOT to be copied */ + /* use default value if one exists */ defexprs[num_defaults] = build_column_default(rel, i + 1); if (defexprs[num_defaults] != NULL) { diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index ee2df73f21e..94c687721b0 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.32 2002/08/22 14:23:36 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.33 2002/08/24 15:00:46 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -3504,8 +3504,8 @@ needs_toast_table(Relation rel) for (i = 0; i < tupdesc->natts; i++) { - data_length = att_align(data_length, att[i]->attlen, att[i]->attalign); - if (att[i]->attlen >= 0) + data_length = att_align(data_length, att[i]->attalign); + if (att[i]->attlen > 0) { /* Fixed-length types are never toastable */ data_length += att[i]->attlen; |