index 0ab5712c7106cbe876cd0d029bc4a068dead4f25..8d03e609a389d913094d6d0a39cc5c0b43cb278e 100644 (file)
@@ -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)
{