diff --git a/src/backend/access/brin/brin_tuple.c b/src/backend/access/brin/brin_tuple.c index 0ab5712c710..8d03e609a38 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) {