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/utils/sort/tuplesort.c | |
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/utils/sort/tuplesort.c')
-rw-r--r-- | src/backend/utils/sort/tuplesort.c | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/src/backend/utils/sort/tuplesort.c b/src/backend/utils/sort/tuplesort.c index a7a387e6752..53ea0fa75b7 100644 --- a/src/backend/utils/sort/tuplesort.c +++ b/src/backend/utils/sort/tuplesort.c @@ -78,7 +78,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/sort/tuplesort.c,v 1.25 2002/08/12 00:36:12 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/sort/tuplesort.c,v 1.26 2002/08/24 15:00:46 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -92,6 +92,7 @@ #include "catalog/pg_amproc.h" #include "catalog/pg_operator.h" #include "miscadmin.h" +#include "utils/datum.h" #include "utils/fmgroids.h" #include "utils/logtape.h" #include "utils/lsyscache.h" @@ -607,16 +608,14 @@ tuplesort_putdatum(Tuplesortstate *state, Datum val, bool isNull) } else { - int datalen = state->datumTypeLen; - int tuplelen; + Size datalen; + Size tuplelen; char *newVal; - if (datalen == -1) /* variable length type? */ - datalen = VARSIZE((struct varlena *) DatumGetPointer(val)); + datalen = datumGetSize(val, false, state->datumTypeLen); tuplelen = datalen + MAXALIGN(sizeof(DatumTuple)); - newVal = (char *) palloc(tuplelen); - tuple = (DatumTuple *) newVal; - newVal += MAXALIGN(sizeof(DatumTuple)); + tuple = (DatumTuple *) palloc(tuplelen); + newVal = ((char *) tuple) + MAXALIGN(sizeof(DatumTuple)); memcpy(newVal, DatumGetPointer(val), datalen); tuple->val = PointerGetDatum(newVal); tuple->isNull = false; @@ -959,14 +958,7 @@ tuplesort_getdatum(Tuplesortstate *state, bool forward, } else { - int datalen = state->datumTypeLen; - char *newVal; - - if (datalen == -1) /* variable length type? */ - datalen = VARSIZE((struct varlena *) DatumGetPointer(tuple->val)); - newVal = (char *) palloc(datalen); - memcpy(newVal, DatumGetPointer(tuple->val), datalen); - *val = PointerGetDatum(newVal); + *val = datumCopy(tuple->val, false, state->datumTypeLen); *isNull = false; } @@ -1959,10 +1951,9 @@ writetup_datum(Tuplesortstate *state, int tapenum, void *tup) tuplen = sizeof(DatumTuple); else { - int datalen = state->datumTypeLen; + Size datalen; - if (datalen == -1) /* variable length type? */ - datalen = VARSIZE((struct varlena *) DatumGetPointer(tuple->val)); + datalen = datumGetSize(tuple->val, false, state->datumTypeLen); tuplen = datalen + MAXALIGN(sizeof(DatumTuple)); } |