From 5db1fd7823a1a12e2bdad98abc8e102fd71ffbda Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Thu, 25 Mar 2021 19:55:32 -0400 Subject: Fix interaction of TOAST compression with expression indexes. Before, trying to compress a value for insertion into an expression index would crash. Dilip Kumar, with some editing by me. Report by Jaime Casanova. Discussion: http://postgr.es/m/CAJKUy5gcs0zGOp6JXU2mMVdthYhuQpFk=S3V8DOKT=LZC1L36Q@mail.gmail.com --- src/backend/access/common/indextuple.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/backend/access/common/indextuple.c') diff --git a/src/backend/access/common/indextuple.c b/src/backend/access/common/indextuple.c index 1f6b7b77d4e..ae932691af8 100644 --- a/src/backend/access/common/indextuple.c +++ b/src/backend/access/common/indextuple.c @@ -103,8 +103,19 @@ index_form_tuple(TupleDesc tupleDescriptor, (att->attstorage == TYPSTORAGE_EXTENDED || att->attstorage == TYPSTORAGE_MAIN)) { - Datum cvalue = toast_compress_datum(untoasted_values[i], - att->attcompression); + 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); if (DatumGetPointer(cvalue) != NULL) { -- cgit v1.2.3