summaryrefslogtreecommitdiff
path: root/src/backend/access
diff options
context:
space:
mode:
authorTom Lane2007-02-27 23:48:10 +0000
committerTom Lane2007-02-27 23:48:10 +0000
commit234a02b2a888cacc4c09363cc1411ae4eac9bb51 (patch)
tree4aadb74b5d7bbcfc3cdae9c8703eac168d6108ae /src/backend/access
parent0459b591fc90b197ed31923b170c658cc30758d5 (diff)
Replace direct assignments to VARATT_SIZEP(x) with SET_VARSIZE(x, len).
Get rid of VARATT_SIZE and VARATT_DATA, which were simply redundant with VARSIZE and VARDATA, and as a consequence almost no code was using the longer names. Rename the length fields of struct varlena and various derived structures to catch anyplace that was accessing them directly; and clean up various places so caught. In itself this patch doesn't change any behavior at all, but it is necessary infrastructure if we hope to play any games with the representation of varlena headers. Greg Stark and Tom Lane
Diffstat (limited to 'src/backend/access')
-rw-r--r--src/backend/access/common/heaptuple.c6
-rw-r--r--src/backend/access/common/indextuple.c4
-rw-r--r--src/backend/access/common/reloptions.c16
-rw-r--r--src/backend/access/heap/tuptoaster.c73
4 files changed, 50 insertions, 49 deletions
diff --git a/src/backend/access/common/heaptuple.c b/src/backend/access/common/heaptuple.c
index 470f48777de..0c83262c3b8 100644
--- a/src/backend/access/common/heaptuple.c
+++ b/src/backend/access/common/heaptuple.c
@@ -16,7 +16,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/common/heaptuple.c,v 1.115 2007/02/09 03:35:33 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/common/heaptuple.c,v 1.116 2007/02/27 23:48:06 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -162,7 +162,7 @@ heap_fill_tuple(TupleDesc tupleDesc,
*infomask |= HEAP_HASEXTERNAL;
if (VARATT_IS_COMPRESSED(values[i]))
*infomask |= HEAP_HASCOMPRESSED;
- data_length = VARATT_SIZE(DatumGetPointer(values[i]));
+ data_length = VARSIZE(DatumGetPointer(values[i]));
memcpy(data, DatumGetPointer(values[i]), data_length);
}
else if (att[i]->attlen == -2)
@@ -261,7 +261,7 @@ DataFill(char *data,
*infomask |= HEAP_HASEXTERNAL;
if (VARATT_IS_COMPRESSED(values[i]))
*infomask |= HEAP_HASCOMPRESSED;
- data_length = VARATT_SIZE(DatumGetPointer(values[i]));
+ data_length = VARSIZE(DatumGetPointer(values[i]));
memcpy(data, DatumGetPointer(values[i]), data_length);
}
else if (att[i]->attlen == -2)
diff --git a/src/backend/access/common/indextuple.c b/src/backend/access/common/indextuple.c
index f2a14240ecb..c83e34834ca 100644
--- a/src/backend/access/common/indextuple.c
+++ b/src/backend/access/common/indextuple.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/common/indextuple.c,v 1.80 2007/01/05 22:19:21 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/access/common/indextuple.c,v 1.81 2007/02/27 23:48:06 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -84,7 +84,7 @@ index_form_tuple(TupleDesc tupleDescriptor,
* If value is above size target, and is of a compressible datatype,
* try to compress it in-line.
*/
- if (VARATT_SIZE(untoasted_values[i]) > TOAST_INDEX_TARGET &&
+ if (VARSIZE(untoasted_values[i]) > TOAST_INDEX_TARGET &&
!VARATT_IS_EXTENDED(untoasted_values[i]) &&
(att->attstorage == 'x' || att->attstorage == 'm'))
{
diff --git a/src/backend/access/common/reloptions.c b/src/backend/access/common/reloptions.c
index 98cbce6761b..4adf4666e77 100644
--- a/src/backend/access/common/reloptions.c
+++ b/src/backend/access/common/reloptions.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/common/reloptions.c,v 1.3 2007/01/05 22:19:21 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/access/common/reloptions.c,v 1.4 2007/02/27 23:48:06 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -72,8 +72,8 @@ transformRelOptions(Datum oldOptions, List *defList,
for (i = 0; i < noldoptions; i++)
{
text *oldoption = DatumGetTextP(oldoptions[i]);
- char *text_str = (char *) VARATT_DATA(oldoption);
- int text_len = VARATT_SIZE(oldoption) - VARHDRSZ;
+ char *text_str = VARDATA(oldoption);
+ int text_len = VARSIZE(oldoption) - VARHDRSZ;
/* Search for a match in defList */
foreach(cell, defList)
@@ -131,8 +131,8 @@ transformRelOptions(Datum oldOptions, List *defList,
len = VARHDRSZ + strlen(def->defname) + 1 + strlen(value);
/* +1 leaves room for sprintf's trailing null */
t = (text *) palloc(len + 1);
- VARATT_SIZEP(t) = len;
- sprintf((char *) VARATT_DATA(t), "%s=%s", def->defname, value);
+ SET_VARSIZE(t, len);
+ sprintf(VARDATA(t), "%s=%s", def->defname, value);
astate = accumArrayResult(astate, PointerGetDatum(t),
false, TEXTOID,
@@ -188,8 +188,8 @@ parseRelOptions(Datum options, int numkeywords, const char *const * keywords,
for (i = 0; i < noptions; i++)
{
text *optiontext = DatumGetTextP(optiondatums[i]);
- char *text_str = (char *) VARATT_DATA(optiontext);
- int text_len = VARATT_SIZE(optiontext) - VARHDRSZ;
+ char *text_str = VARDATA(optiontext);
+ int text_len = VARSIZE(optiontext) - VARHDRSZ;
int j;
/* Search for a match in keywords */
@@ -267,7 +267,7 @@ default_reloptions(Datum reloptions, bool validate,
}
result = (StdRdOptions *) palloc(sizeof(StdRdOptions));
- VARATT_SIZEP(result) = sizeof(StdRdOptions);
+ SET_VARSIZE(result, sizeof(StdRdOptions));
result->fillfactor = fillfactor;
diff --git a/src/backend/access/heap/tuptoaster.c b/src/backend/access/heap/tuptoaster.c
index 6fde18104a3..b1eb8aea4d3 100644
--- a/src/backend/access/heap/tuptoaster.c
+++ b/src/backend/access/heap/tuptoaster.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.70 2007/02/04 20:00:37 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.71 2007/02/27 23:48:07 tgl Exp $
*
*
* INTERFACE ROUTINES
@@ -104,8 +104,8 @@ heap_tuple_untoast_attr(varattrib *attr)
tmp = (PGLZ_Header *) toast_fetch_datum(attr);
result = (varattrib *) palloc(PGLZ_RAW_SIZE(tmp) + VARHDRSZ);
- VARATT_SIZEP(result) = PGLZ_RAW_SIZE(tmp) + VARHDRSZ;
- pglz_decompress(tmp, VARATT_DATA(result));
+ SET_VARSIZE(result, PGLZ_RAW_SIZE(tmp) + VARHDRSZ);
+ pglz_decompress(tmp, VARDATA(result));
pfree(tmp);
}
else
@@ -124,8 +124,8 @@ heap_tuple_untoast_attr(varattrib *attr)
PGLZ_Header *tmp = (PGLZ_Header *) attr;
result = (varattrib *) palloc(PGLZ_RAW_SIZE(tmp) + VARHDRSZ);
- VARATT_SIZEP(result) = PGLZ_RAW_SIZE(tmp) + VARHDRSZ;
- pglz_decompress(tmp, VARATT_DATA(result));
+ SET_VARSIZE(result, PGLZ_RAW_SIZE(tmp) + VARHDRSZ);
+ pglz_decompress(tmp, VARDATA(result));
}
else
@@ -162,8 +162,8 @@ heap_tuple_untoast_attr_slice(varattrib *attr, int32 sliceoffset, int32 slicelen
tmp = (PGLZ_Header *) attr; /* compressed in main tuple */
preslice = (varattrib *) palloc(PGLZ_RAW_SIZE(tmp) + VARHDRSZ);
- VARATT_SIZEP(preslice) = PGLZ_RAW_SIZE(tmp) + VARHDRSZ;
- pglz_decompress(tmp, VARATT_DATA(preslice));
+ SET_VARSIZE(preslice, PGLZ_RAW_SIZE(tmp) + VARHDRSZ);
+ pglz_decompress(tmp, VARDATA(preslice));
if (tmp != (PGLZ_Header *) attr)
pfree(tmp);
@@ -193,7 +193,7 @@ heap_tuple_untoast_attr_slice(varattrib *attr, int32 sliceoffset, int32 slicelen
slicelength = attrsize - sliceoffset;
result = (varattrib *) palloc(slicelength + VARHDRSZ);
- VARATT_SIZEP(result) = slicelength + VARHDRSZ;
+ SET_VARSIZE(result, slicelength + VARHDRSZ);
memcpy(VARDATA(result), VARDATA(preslice) + sliceoffset, slicelength);
@@ -435,7 +435,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup, bool us
* tuple.
*/
toast_action[i] = 'p';
- toast_sizes[i] = VARATT_SIZE(toast_values[i]);
+ toast_sizes[i] = VARSIZE(toast_values[i]);
continue;
}
}
@@ -486,7 +486,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup, bool us
/*
* Remember the size of this attribute
*/
- toast_sizes[i] = VARATT_SIZE(new_value);
+ toast_sizes[i] = VARSIZE(new_value);
}
else
{
@@ -564,7 +564,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup, bool us
pfree(DatumGetPointer(old_value));
toast_values[i] = new_value;
toast_free[i] = true;
- toast_sizes[i] = VARATT_SIZE(toast_values[i]);
+ toast_sizes[i] = VARSIZE(toast_values[i]);
need_change = true;
need_free = true;
}
@@ -623,7 +623,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup, bool us
pfree(DatumGetPointer(old_value));
toast_free[i] = true;
- toast_sizes[i] = VARATT_SIZE(toast_values[i]);
+ toast_sizes[i] = VARSIZE(toast_values[i]);
need_change = true;
need_free = true;
@@ -676,7 +676,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup, bool us
pfree(DatumGetPointer(old_value));
toast_values[i] = new_value;
toast_free[i] = true;
- toast_sizes[i] = VARATT_SIZE(toast_values[i]);
+ toast_sizes[i] = VARSIZE(toast_values[i]);
need_change = true;
need_free = true;
}
@@ -734,7 +734,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup, bool us
pfree(DatumGetPointer(old_value));
toast_free[i] = true;
- toast_sizes[i] = VARATT_SIZE(toast_values[i]);
+ toast_sizes[i] = VARSIZE(toast_values[i]);
need_change = true;
need_free = true;
@@ -949,15 +949,15 @@ Datum
toast_compress_datum(Datum value)
{
varattrib *tmp;
- int32 valsize = VARATT_SIZE(value) - VARHDRSZ;
+ int32 valsize = VARSIZE(value) - VARHDRSZ;
tmp = (varattrib *) palloc(PGLZ_MAX_OUTPUT(valsize));
- if (pglz_compress(VARATT_DATA(value), valsize,
+ if (pglz_compress(VARDATA(value), valsize,
(PGLZ_Header *) tmp, PGLZ_strategy_default) &&
- VARATT_SIZE(tmp) < VARATT_SIZE(value))
+ VARSIZE(tmp) < VARSIZE(value))
{
/* successful compression */
- VARATT_SIZEP(tmp) |= VARATT_FLAG_COMPRESSED;
+ VARATT_SIZEP_DEPRECATED(tmp) |= VARATT_FLAG_COMPRESSED;
return PointerGetDatum(tmp);
}
else
@@ -1010,18 +1010,19 @@ toast_save_datum(Relation rel, Datum value, bool use_wal)
*/
result = (varattrib *) palloc(sizeof(varattrib));
- result->va_header = sizeof(varattrib) | VARATT_FLAG_EXTERNAL;
+ SET_VARSIZE(result, sizeof(varattrib));
+ VARATT_SIZEP_DEPRECATED(result) |= VARATT_FLAG_EXTERNAL;
if (VARATT_IS_COMPRESSED(value))
{
- result->va_header |= VARATT_FLAG_COMPRESSED;
+ VARATT_SIZEP_DEPRECATED(result) |= VARATT_FLAG_COMPRESSED;
result->va_content.va_external.va_rawsize =
((varattrib *) value)->va_content.va_compressed.va_rawsize;
}
else
- result->va_content.va_external.va_rawsize = VARATT_SIZE(value);
+ result->va_content.va_external.va_rawsize = VARSIZE(value);
result->va_content.va_external.va_extsize =
- VARATT_SIZE(value) - VARHDRSZ;
+ VARSIZE(value) - VARHDRSZ;
result->va_content.va_external.va_valueid =
GetNewOidWithIndex(toastrel, toastidx);
result->va_content.va_external.va_toastrelid =
@@ -1039,8 +1040,8 @@ toast_save_datum(Relation rel, Datum value, bool use_wal)
/*
* Get the data to process
*/
- data_p = VARATT_DATA(value);
- data_todo = VARATT_SIZE(value) - VARHDRSZ;
+ data_p = VARDATA(value);
+ data_todo = VARSIZE(value) - VARHDRSZ;
/*
* Split up the item into chunks
@@ -1056,8 +1057,8 @@ toast_save_datum(Relation rel, Datum value, bool use_wal)
* Build a tuple and store it
*/
t_values[1] = Int32GetDatum(chunk_seq++);
- VARATT_SIZEP(&chunk_data) = chunk_size + VARHDRSZ;
- memcpy(VARATT_DATA(&chunk_data), data_p, chunk_size);
+ SET_VARSIZE(&chunk_data, chunk_size + VARHDRSZ);
+ memcpy(VARDATA(&chunk_data), data_p, chunk_size);
toasttup = heap_form_tuple(toasttupDesc, t_values, t_isnull);
if (!HeapTupleIsValid(toasttup))
elog(ERROR, "failed to build TOAST tuple");
@@ -1184,9 +1185,9 @@ toast_fetch_datum(varattrib *attr)
numchunks = ((ressize - 1) / TOAST_MAX_CHUNK_SIZE) + 1;
result = (varattrib *) palloc(ressize + VARHDRSZ);
- VARATT_SIZEP(result) = ressize + VARHDRSZ;
+ SET_VARSIZE(result, ressize + VARHDRSZ);
if (VARATT_IS_COMPRESSED(attr))
- VARATT_SIZEP(result) |= VARATT_FLAG_COMPRESSED;
+ VARATT_SIZEP_DEPRECATED(result) |= VARATT_FLAG_COMPRESSED;
/*
* Open the toast relation and its index
@@ -1224,7 +1225,7 @@ toast_fetch_datum(varattrib *attr)
Assert(!isnull);
chunk = DatumGetPointer(fastgetattr(ttup, 3, toasttupDesc, &isnull));
Assert(!isnull);
- chunksize = VARATT_SIZE(chunk) - VARHDRSZ;
+ chunksize = VARSIZE(chunk) - VARHDRSZ;
/*
* Some checks on the data we've found
@@ -1255,8 +1256,8 @@ toast_fetch_datum(varattrib *attr)
/*
* Copy the data into proper place in our result
*/
- memcpy(((char *) VARATT_DATA(result)) + residx * TOAST_MAX_CHUNK_SIZE,
- VARATT_DATA(chunk),
+ memcpy(VARDATA(result) + residx * TOAST_MAX_CHUNK_SIZE,
+ VARDATA(chunk),
chunksize);
nextidx++;
@@ -1326,10 +1327,10 @@ toast_fetch_datum_slice(varattrib *attr, int32 sliceoffset, int32 length)
length = attrsize - sliceoffset;
result = (varattrib *) palloc(length + VARHDRSZ);
- VARATT_SIZEP(result) = length + VARHDRSZ;
+ SET_VARSIZE(result, length + VARHDRSZ);
if (VARATT_IS_COMPRESSED(attr))
- VARATT_SIZEP(result) |= VARATT_FLAG_COMPRESSED;
+ VARATT_SIZEP_DEPRECATED(result) |= VARATT_FLAG_COMPRESSED;
if (length == 0)
return result; /* Can save a lot of work at this point! */
@@ -1399,7 +1400,7 @@ toast_fetch_datum_slice(varattrib *attr, int32 sliceoffset, int32 length)
Assert(!isnull);
chunk = DatumGetPointer(fastgetattr(ttup, 3, toasttupDesc, &isnull));
Assert(!isnull);
- chunksize = VARATT_SIZE(chunk) - VARHDRSZ;
+ chunksize = VARSIZE(chunk) - VARHDRSZ;
/*
* Some checks on the data we've found
@@ -1433,9 +1434,9 @@ toast_fetch_datum_slice(varattrib *attr, int32 sliceoffset, int32 length)
if (residx == endchunk)
chcpyend = endoffset;
- memcpy(((char *) VARATT_DATA(result)) +
+ memcpy(VARDATA(result) +
(residx * TOAST_MAX_CHUNK_SIZE - sliceoffset) + chcpystrt,
- VARATT_DATA(chunk) + chcpystrt,
+ VARDATA(chunk) + chcpystrt,
(chcpyend - chcpystrt) + 1);
nextidx++;