summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas Vondra2021-03-20 23:28:13 +0000
committerTomas Vondra2021-03-20 23:28:34 +0000
commit882b2cdc08c4100e273f24742e2118be98708a07 (patch)
tree3643b3c73aab83b744c410c699939ae76b94f350
parentaa25d1089ac00bbc3f97d2efe8f54c3d4beed5d1 (diff)
Use valid compression method in brin_form_tuple
When compressing the BRIN summary, we can't simply use the compression method from the indexed attribute. The summary may use a different data type, e.g. fixed-length attribute may have varlena summary, leading to compression failures. For the built-in BRIN opclasses this happens to work, because the summary uses the same data type as the attribute. When the data types match, we can inherit use the compression method specified for the attribute (it's copied into the index descriptor). Otherwise we don't have much choice and have to use the default one. Author: Tomas Vondra Reviewed-by: Justin Pryzby <[email protected]> Discussion: https://postgr.es/m/e0367f27-392c-321a-7411-a58e1a7e4817%40enterprisedb.com
-rw-r--r--src/backend/access/brin/brin_tuple.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/backend/access/brin/brin_tuple.c b/src/backend/access/brin/brin_tuple.c
index 0ab5712c71..8d03e609a3 100644
--- a/src/backend/access/brin/brin_tuple.c
+++ b/src/backend/access/brin/brin_tuple.c
@@ -213,10 +213,22 @@ brin_form_tuple(BrinDesc *brdesc, BlockNumber blkno, BrinMemTuple *tuple,
(atttype->typstorage == TYPSTORAGE_EXTENDED ||
atttype->typstorage == TYPSTORAGE_MAIN))
{
+ Datum cvalue;
+ char compression;
Form_pg_attribute att = TupleDescAttr(brdesc->bd_tupdesc,
keyno);
- Datum cvalue = toast_compress_datum(value,
- att->attcompression);
+
+ /*
+ * If the BRIN summary and indexed attribute use the same data
+ * type, we can use the same compression method. Otherwise we
+ * have to use the default method.
+ */
+ if (att->atttypid == atttype->type_id)
+ compression = att->attcompression;
+ else
+ compression = GetDefaultToastCompression();
+
+ cvalue = toast_compress_datum(value, compression);
if (DatumGetPointer(cvalue) != NULL)
{