summaryrefslogtreecommitdiff
path: root/src/backend/access
diff options
context:
space:
mode:
authorTom Lane2021-05-27 17:24:24 +0000
committerTom Lane2021-05-27 17:24:27 +0000
commite6241d8e030fbd2746b3ea3f44e728224298f35b (patch)
treee4bfc50561023459635cb9faf0873fee1e891013 /src/backend/access
parenta717e5c771610cf8607f2423ab3ab6b5d30f44ea (diff)
Rethink definition of pg_attribute.attcompression.
Redefine '\0' (InvalidCompressionMethod) as meaning "if we need to compress, use the current setting of default_toast_compression". This allows '\0' to be a suitable default choice regardless of datatype, greatly simplifying code paths that initialize tupledescs and the like. It seems like a more user-friendly approach as well, because now the default compression choice doesn't migrate into table definitions, meaning that changing default_toast_compression is usually sufficient to flip an installation's behavior; one needn't tediously issue per-column ALTER SET COMPRESSION commands. Along the way, fix a few minor bugs and documentation issues with the per-column-compression feature. Adopt more robust APIs for SetIndexStorageProperties and GetAttributeCompression. Bump catversion because typical contents of attcompression will now be different. We could get away without doing that, but it seems better to ensure v14 installations all agree on this. (We already forced initdb for beta2, anyway.) Discussion: https://postgr.es/m/626613.1621787110@sss.pgh.pa.us
Diffstat (limited to 'src/backend/access')
-rw-r--r--src/backend/access/brin/brin_tuple.c5
-rw-r--r--src/backend/access/common/indextuple.c13
-rw-r--r--src/backend/access/common/toast_internals.c6
-rw-r--r--src/backend/access/common/tupdesc.c7
-rw-r--r--src/backend/access/heap/heapam_handler.c12
5 files changed, 19 insertions, 24 deletions
diff --git a/src/backend/access/brin/brin_tuple.c b/src/backend/access/brin/brin_tuple.c
index ee05372f795..09e563b1f08 100644
--- a/src/backend/access/brin/brin_tuple.c
+++ b/src/backend/access/brin/brin_tuple.c
@@ -232,11 +232,10 @@ brin_form_tuple(BrinDesc *brdesc, BlockNumber blkno, BrinMemTuple *tuple,
* same compression method. Otherwise we have to use the
* default method.
*/
- if (att->atttypid == atttype->type_id &&
- CompressionMethodIsValid(att->attcompression))
+ if (att->atttypid == atttype->type_id)
compression = att->attcompression;
else
- compression = GetDefaultToastCompression();
+ compression = InvalidCompressionMethod;
cvalue = toast_compress_datum(value, compression);
diff --git a/src/backend/access/common/indextuple.c b/src/backend/access/common/indextuple.c
index 52125604113..8df882da7a7 100644
--- a/src/backend/access/common/indextuple.c
+++ b/src/backend/access/common/indextuple.c
@@ -104,18 +104,9 @@ index_form_tuple(TupleDesc tupleDescriptor,
att->attstorage == TYPSTORAGE_MAIN))
{
Datum cvalue;
- char compression = att->attcompression;
- /*
- * If the compression method is not valid, use the default. We
- * don't expect this to happen for regular index columns, which
- * inherit the setting from the corresponding table column, but we
- * do expect it to happen whenever an expression is indexed.
- */
- if (!CompressionMethodIsValid(compression))
- compression = GetDefaultToastCompression();
-
- cvalue = toast_compress_datum(untoasted_values[i], compression);
+ cvalue = toast_compress_datum(untoasted_values[i],
+ att->attcompression);
if (DatumGetPointer(cvalue) != NULL)
{
diff --git a/src/backend/access/common/toast_internals.c b/src/backend/access/common/toast_internals.c
index 8d2a9964c3f..c7b9ade5742 100644
--- a/src/backend/access/common/toast_internals.c
+++ b/src/backend/access/common/toast_internals.c
@@ -53,10 +53,12 @@ toast_compress_datum(Datum value, char cmethod)
Assert(!VARATT_IS_EXTERNAL(DatumGetPointer(value)));
Assert(!VARATT_IS_COMPRESSED(DatumGetPointer(value)));
- Assert(CompressionMethodIsValid(cmethod));
-
valsize = VARSIZE_ANY_EXHDR(DatumGetPointer(value));
+ /* If the compression method is not valid, use the current default */
+ if (!CompressionMethodIsValid(cmethod))
+ cmethod = default_toast_compression;
+
/*
* Call appropriate compression routine for the compression method.
*/
diff --git a/src/backend/access/common/tupdesc.c b/src/backend/access/common/tupdesc.c
index affbc509bdc..4c63bd4dc64 100644
--- a/src/backend/access/common/tupdesc.c
+++ b/src/backend/access/common/tupdesc.c
@@ -642,10 +642,7 @@ TupleDescInitEntry(TupleDesc desc,
att->attbyval = typeForm->typbyval;
att->attalign = typeForm->typalign;
att->attstorage = typeForm->typstorage;
- if (IsStorageCompressible(typeForm->typstorage))
- att->attcompression = GetDefaultToastCompression();
- else
- att->attcompression = InvalidCompressionMethod;
+ att->attcompression = InvalidCompressionMethod;
att->attcollation = typeForm->typcollation;
ReleaseSysCache(tuple);
@@ -711,7 +708,7 @@ TupleDescInitBuiltinEntry(TupleDesc desc,
att->attbyval = false;
att->attalign = TYPALIGN_INT;
att->attstorage = TYPSTORAGE_EXTENDED;
- att->attcompression = GetDefaultToastCompression();
+ att->attcompression = InvalidCompressionMethod;
att->attcollation = DEFAULT_COLLATION_OID;
break;
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index 8e6e8d51698..e2cd79ec546 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -2483,10 +2483,10 @@ reform_and_rewrite_tuple(HeapTuple tuple,
* perform the compression here; we just need to decompress. That
* will trigger recompression later on.
*/
-
struct varlena *new_value;
ToastCompressionId cmid;
char cmethod;
+ char targetmethod;
new_value = (struct varlena *) DatumGetPointer(values[i]);
cmid = toast_get_compression_id(new_value);
@@ -2495,7 +2495,7 @@ reform_and_rewrite_tuple(HeapTuple tuple,
if (cmid == TOAST_INVALID_COMPRESSION_ID)
continue;
- /* convert compression id to compression method */
+ /* convert existing compression id to compression method */
switch (cmid)
{
case TOAST_PGLZ_COMPRESSION_ID:
@@ -2506,10 +2506,16 @@ reform_and_rewrite_tuple(HeapTuple tuple,
break;
default:
elog(ERROR, "invalid compression method id %d", cmid);
+ cmethod = '\0'; /* keep compiler quiet */
}
+ /* figure out what the target method is */
+ targetmethod = TupleDescAttr(newTupDesc, i)->attcompression;
+ if (!CompressionMethodIsValid(targetmethod))
+ targetmethod = default_toast_compression;
+
/* if compression method doesn't match then detoast the value */
- if (TupleDescAttr(newTupDesc, i)->attcompression != cmethod)
+ if (targetmethod != cmethod)
{
values[i] = PointerGetDatum(detoast_attr(new_value));
values_free[i] = true;