Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1llzsj-0003dB-Re for pgsql-hackers@arkaria.postgresql.org; Wed, 26 May 2021 20:11:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1llzsi-0000Rn-Ne for pgsql-hackers@arkaria.postgresql.org; Wed, 26 May 2021 20:11:56 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1llzsi-0000JD-1e for pgsql-hackers@lists.postgresql.org; Wed, 26 May 2021 20:11:56 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1llzsd-0002YU-Ob for pgsql-hackers@postgresql.org; Wed, 26 May 2021 20:11:55 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 14QKBk631618251; Wed, 26 May 2021 16:11:46 -0400 From: Tom Lane To: Robert Haas cc: Michael Paquier , Justin Pryzby , Andres Freund , pgsql-hackers@postgresql.org, Dilip Kumar Subject: Re: Move pg_attribute.attcompression to earlier in struct for reduced size? In-reply-to: <1556957.1622057488@sss.pgh.pa.us> References: <20210517204803.iyk5wwvwgtjcmc5w@alap3.anarazel.de> <2854987.1621285592@sss.pgh.pa.us> <20210517212857.qyk4fxykfbxhmxof@alap3.anarazel.de> <3962395.1621609263@sss.pgh.pa.us> <626613.1621787110@sss.pgh.pa.us> <20210526013347.GG3676@telsasoft.com> <1505124.1622042026@sss.pgh.pa.us> <1556957.1622057488@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Wed, 26 May 2021 15:31:28 -0400" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <1618221.1622059867.0@sss.pgh.pa.us> Date: Wed, 26 May 2021 16:11:46 -0400 Message-ID: <1618250.1622059906@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1618221.1622059867.1@sss.pgh.pa.us> I wrote: > I think this is about ready to commit now (though I didn't yet nuke > GetDefaultToastCompression). Here's a bundled-up final version, in case anybody would prefer to review it that way. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="change-attcompression-definition-1.patch"; charset="us-ascii" Content-ID: <1618221.1622059867.2@sss.pgh.pa.us> Content-Description: change-attcompression-definition-1.patch Content-Transfer-Encoding: quoted-printable diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml index b26b872a06..16493209c6 100644 --- a/doc/src/sgml/catalogs.sgml +++ b/doc/src/sgml/catalogs.sgml @@ -1261,10 +1261,14 @@ attcompression char - The current compression method of the column. If it is an invalid - compression method ('\0') then column data will= not - be compressed. Otherwise, 'p' =3D pglz compres= sion or - 'l' =3D LZ4 compress= ion. + The current compression method of the column. Typically this is + '\0' to specify use of the current default sett= ing + (see ). Otherwis= e, + 'p' selects pglz compression, while + 'l' selects LZ4 + compression. However, this field is ignored + whenever attstorage does not allow + compression. = diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index 7e32b0686c..9f7f42c4aa 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -8239,13 +8239,14 @@ COPY postgres_log FROM '/full/path/to/logfile.csv'= WITH csv; This variable sets the default TOAST - compression method for columns of newly-created tables. The - CREATE TABLE statement can override this defau= lt - by specifying the COMPRESSION column option. - - The supported compression methods are pglz and= , - if PostgreSQL was compiled with - --with-lz4, lz4. + compression method for values of compressible columns. + (This can be overridden for individual columns by setting + the COMPRESSION column option in + CREATE TABLE or + ALTER TABLE.) + The supported compression methods are pglz and + (if PostgreSQL was compiled with + ) lz4. The default is pglz. diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 3a21129021..08b07f561e 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -26253,10 +26253,10 @@ postgres=3D# SELECT * FROM pg_walfile_name_offse= t(pg_stop_backup()); pg_column_compression pg_column_compression ( "any" ) - integer + text - Shows the compression algorithm that was used to compress a + Shows the compression algorithm that was used to compress an individual variable-length value. Returns NULL if the value is not compressed. diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_ta= ble.sgml index 1431d2649b..939d3fe273 100644 --- a/doc/src/sgml/ref/alter_table.sgml +++ b/doc/src/sgml/ref/alter_table.sgml @@ -104,7 +104,6 @@ WITH ( MODULUS numeri= c_literal, REM GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY [ ( sequence= _options ) ] | UNIQUE index_parameters = | PRIMARY KEY index_parameters | - COMPRESSION compression_method | REFERENCES reftable [ ( = refcolumn ) ] [ MATCH FULL = | MATCH PARTIAL | MATCH SIMPLE ] [ ON DELETE referential_action ] [ ON UPDATE referential_action= ] } [ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIAT= E ] @@ -391,24 +390,27 @@ WITH ( MODULUS nume= ric_literal, REM - This sets the compression method to be used for data inserted into = a column. - + This form sets the compression method for a column, determining how + values inserted in future will be compressed (if the storage mode + permits compression at all). This does not cause the table to be rewritten, so existing data may= still be compressed with other compression methods. If the table is rewr= itten with VACUUM FULL or CLUSTER, or re= stored - with pg_restore, then all tuples are rew= ritten - with the configured compression methods. - - Also, note that when data is inserted from another relation (for ex= ample, - by INSERT ... SELECT), tuples from the source da= ta are - not necessarily detoasted, and any previously compressed data is re= tained - with its existing compression method, rather than recompressing wit= h the - compression methods of the target columns. - + with pg_restore, then all values are rew= ritten + with the configured compression method. + However, when data is inserted from another relation (for example, + by INSERT ... SELECT), values from the source ta= ble are + not necessarily detoasted, so any previously compressed data may re= tain + its existing compression method, rather than being recompressed wit= h the + compression method of the target column. The supported compression methods are pglz and lz4. - lz4 is available only if --with-lz4 - was used when building PostgreSQL. + (lz4 is available only if diff --git a/doc/src/sgml/ref/create_table.sgml b/doc/src/sgml/ref/create_= table.sgml index a8c5e4028a..c6d0a35e50 100644 --- a/doc/src/sgml/ref/create_table.sgml +++ b/doc/src/sgml/ref/create_table.sgml @@ -22,7 +22,7 @@ PostgreSQL documentation CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF = NOT EXISTS ] table_name ( [ - { column_name data_type [ COLLATE coll= ation ] [ COMPRESSION compression_method ] [ column_constraint [ ... ] ] + { column_name data_type [ COMPRESSION = compression_method ] [ COLLATE collation ] [ column_constraint [ ... ] ] | table_constraint | LIKE source_table [ like_op= tion ... ] } [, ... ] @@ -293,17 +293,22 @@ WITH ( MODULUS nume= ric_literal, REM The COMPRESSION clause sets the compression meth= od - for a column. Compression is supported only for variable-width dat= a - types, and is used only for columns whose storage type is main or - extended. (See for information o= n - column storage types.) Setting this property for a partitioned tabl= e + for the column. Compression is supported only for variable-width d= ata + types, and is used only when the column's storage mode + is main or extended. + (See for information on + column storage modes.) Setting this property for a partitioned tabl= e has no direct effect, because such tables have no storage of their = own, - but the configured value is inherited by newly-created partitions. + but the configured value will be inherited by newly-created partiti= ons. The supported compression methods are pglz and - lz4. lz4 is available only i= f - --with-lz4 was used when building - PostgreSQL. The default - is pglz. + lz4. (lz4 is available only = if + was used when building + PostgreSQL.) In addition, + compression_method + can be default to explicitly specify the default + behavior, which is to consult the + setting at the ti= me of + data insertion to determine the method to use. diff --git a/doc/src/sgml/ref/pg_dump.sgml b/doc/src/sgml/ref/pg_dump.sgml index 67c2cbbec6..5ddadc11f2 100644 --- a/doc/src/sgml/ref/pg_dump.sgml +++ b/doc/src/sgml/ref/pg_dump.sgml @@ -975,8 +975,8 @@ PostgreSQL documentation Do not output commands to set TOAST compressio= n methods. - With this option, all objects will be created using whichever - compression method is the default during restore. + With this option, all columns will be restored with the default + compression setting. diff --git a/doc/src/sgml/ref/pg_dumpall.sgml b/doc/src/sgml/ref/pg_dumpal= l.sgml index 805c47d5c1..ddffbf85ed 100644 --- a/doc/src/sgml/ref/pg_dumpall.sgml +++ b/doc/src/sgml/ref/pg_dumpall.sgml @@ -464,12 +464,12 @@ PostgreSQL documentation Do not output commands to set TOAST compressio= n methods. - With this option, all objects will be created using whichever - compression method is the default during restore. + With this option, all columns will be restored with the default + compression setting. - = + diff --git a/doc/src/sgml/storage.sgml b/doc/src/sgml/storage.sgml index bfccda77af..7136bbe7a3 100644 --- a/doc/src/sgml/storage.sgml +++ b/doc/src/sgml/storage.sgml @@ -376,6 +376,16 @@ but the varlena header does not tell whether it has o= ccurred — the content of the TOAST pointer tells that, instead. = + +The compression technique used for either in-line or out-of-line compress= ed +data can be selected for each column by setting +the COMPRESSION column option in CREATE +TABLE or ALTER TABLE. The default for colum= ns +with no explicit setting is to consult the + parameter at the time d= ata is +inserted. + + As mentioned, there are multiple types of TOAST pointe= r datums. The oldest and most common type is a pointer to out-of-line data stored i= n @@ -392,13 +402,6 @@ useful for avoiding copying and redundant processing = of large data values. Further details appear in . = - -The compression technique used for either in-line or out-of-line compress= ed -data can be selected using the COMPRESSION option on a= per-column -basis when creating a table. The default for columns with no explicit set= ting -is taken from the value of . - - Out-of-Line, On-Disk TOAST Storage = diff --git a/src/backend/access/brin/brin_tuple.c b/src/backend/access/bri= n/brin_tuple.c index ee05372f79..09e563b1f0 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 =3D=3D atttype->type_id && - CompressionMethodIsValid(att->attcompression)) + if (att->atttypid =3D=3D atttype->type_id) compression =3D att->attcompression; else - compression =3D GetDefaultToastCompression(); + compression =3D InvalidCompressionMethod; = cvalue =3D toast_compress_datum(value, compression); = diff --git a/src/backend/access/common/indextuple.c b/src/backend/access/c= ommon/indextuple.c index 5212560411..8df882da7a 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 =3D=3D TYPSTORAGE_MAIN)) { Datum cvalue; - char compression =3D 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 =3D GetDefaultToastCompression(); - - cvalue =3D toast_compress_datum(untoasted_values[i], compression); + cvalue =3D toast_compress_datum(untoasted_values[i], + att->attcompression); = if (DatumGetPointer(cvalue) !=3D NULL) { diff --git a/src/backend/access/common/toast_internals.c b/src/backend/acc= ess/common/toast_internals.c index 8d2a9964c3..c7b9ade574 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 =3D VARSIZE_ANY_EXHDR(DatumGetPointer(value)); = + /* If the compression method is not valid, use the current default */ + if (!CompressionMethodIsValid(cmethod)) + cmethod =3D default_toast_compression; + /* * Call appropriate compression routine for the compression method. */ diff --git a/src/backend/access/common/tupdesc.c b/src/backend/access/comm= on/tupdesc.c index affbc509bd..4c63bd4dc6 100644 --- a/src/backend/access/common/tupdesc.c +++ b/src/backend/access/common/tupdesc.c @@ -642,10 +642,7 @@ TupleDescInitEntry(TupleDesc desc, att->attbyval =3D typeForm->typbyval; att->attalign =3D typeForm->typalign; att->attstorage =3D typeForm->typstorage; - if (IsStorageCompressible(typeForm->typstorage)) - att->attcompression =3D GetDefaultToastCompression(); - else - att->attcompression =3D InvalidCompressionMethod; + att->attcompression =3D InvalidCompressionMethod; att->attcollation =3D typeForm->typcollation; = ReleaseSysCache(tuple); @@ -711,7 +708,7 @@ TupleDescInitBuiltinEntry(TupleDesc desc, att->attbyval =3D false; att->attalign =3D TYPALIGN_INT; att->attstorage =3D TYPSTORAGE_EXTENDED; - att->attcompression =3D GetDefaultToastCompression(); + att->attcompression =3D InvalidCompressionMethod; att->attcollation =3D DEFAULT_COLLATION_OID; break; = diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access= /heap/heapam_handler.c index 8e6e8d5169..e2cd79ec54 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 =3D (struct varlena *) DatumGetPointer(values[i]); cmid =3D toast_get_compression_id(new_value); @@ -2495,7 +2495,7 @@ reform_and_rewrite_tuple(HeapTuple tuple, if (cmid =3D=3D 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 =3D '\0'; /* keep compiler quiet */ } = + /* figure out what the target method is */ + targetmethod =3D TupleDescAttr(newTupDesc, i)->attcompression; + if (!CompressionMethodIsValid(targetmethod)) + targetmethod =3D default_toast_compression; + /* if compression method doesn't match then detoast the value */ - if (TupleDescAttr(newTupDesc, i)->attcompression !=3D cmethod) + if (targetmethod !=3D cmethod) { values[i] =3D PointerGetDatum(detoast_attr(new_value)); values_free[i] =3D true; diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/boo= tstrap.c index 62abd008cc..94ab5ca095 100644 --- a/src/backend/bootstrap/bootstrap.c +++ b/src/backend/bootstrap/bootstrap.c @@ -701,6 +701,7 @@ DefineAttr(char *name, char *type, int attnum, int nul= lness) attrtypes[attnum]->attbyval =3D Ap->am_typ.typbyval; attrtypes[attnum]->attalign =3D Ap->am_typ.typalign; attrtypes[attnum]->attstorage =3D Ap->am_typ.typstorage; + attrtypes[attnum]->attcompression =3D InvalidCompressionMethod; attrtypes[attnum]->attcollation =3D Ap->am_typ.typcollation; /* if an array type, assume 1-dimensional attribute */ if (Ap->am_typ.typelem !=3D InvalidOid && Ap->am_typ.typlen < 0) @@ -715,6 +716,7 @@ DefineAttr(char *name, char *type, int attnum, int nul= lness) attrtypes[attnum]->attbyval =3D TypInfo[typeoid].byval; attrtypes[attnum]->attalign =3D TypInfo[typeoid].align; attrtypes[attnum]->attstorage =3D TypInfo[typeoid].storage; + attrtypes[attnum]->attcompression =3D InvalidCompressionMethod; attrtypes[attnum]->attcollation =3D TypInfo[typeoid].collation; /* if an array type, assume 1-dimensional attribute */ if (TypInfo[typeoid].elem !=3D InvalidOid && @@ -724,11 +726,6 @@ DefineAttr(char *name, char *type, int attnum, int nu= llness) attrtypes[attnum]->attndims =3D 0; } = - if (IsStorageCompressible(attrtypes[attnum]->attstorage)) - attrtypes[attnum]->attcompression =3D GetDefaultToastCompression(); - else - attrtypes[attnum]->attcompression =3D InvalidCompressionMethod; - /* * If a system catalog column is collation-aware, force it to use C * collation, so that its behavior is independent of the database's diff --git a/src/backend/catalog/genbki.pl b/src/backend/catalog/genbki.pl index 112b3affdf..f893ae4f45 100644 --- a/src/backend/catalog/genbki.pl +++ b/src/backend/catalog/genbki.pl @@ -899,9 +899,7 @@ sub morph_row_for_pgattr $row->{attbyval} =3D $type->{typbyval}; $row->{attalign} =3D $type->{typalign}; $row->{attstorage} =3D $type->{typstorage}; - - $row->{attcompression} =3D - $type->{typstorage} ne 'p' && $type->{typstorage} ne 'e' ? 'p' : '\0'; + $row->{attcompression} =3D '\0'; = # set attndims if it's an array type $row->{attndims} =3D $type->{typcategory} eq 'A' ? '1' : '0'; diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 3dfe2e8a56..afa830d924 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -1719,8 +1719,6 @@ RemoveAttributeById(Oid relid, AttrNumber attnum) /* Unset this so no one tries to look up the generation expression */ attStruct->attgenerated =3D '\0'; = - attStruct->attcompression =3D InvalidCompressionMethod; - /* * Change the column name to something that isn't likely to conflict */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/table= cmds.c index 11e91c4ad3..e14039e971 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -601,7 +601,7 @@ static void refuseDupeIndexAttach(Relation parentIdx, = Relation partIdx, Relation partitionTbl); static List *GetParentedForeignKeyRefs(Relation partition); static void ATDetachCheckNoForeignKeyRefs(Relation partition); -static char GetAttributeCompression(Form_pg_attribute att, char *compress= ion); +static char GetAttributeCompression(Oid atttypid, char *compression); = = /* ---------------------------------------------------------------- @@ -897,17 +897,9 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ow= nerId, if (colDef->generated) attr->attgenerated =3D colDef->generated; = - /* - * lookup attribute's compression method and store it in the - * attr->attcompression. - */ - if (relkind =3D=3D RELKIND_RELATION || - relkind =3D=3D RELKIND_PARTITIONED_TABLE || - relkind =3D=3D RELKIND_MATVIEW) - attr->attcompression =3D - GetAttributeCompression(attr, colDef->compression); - else - attr->attcompression =3D InvalidCompressionMethod; + if (colDef->compression) + attr->attcompression =3D GetAttributeCompression(attr->atttypid, + colDef->compression); } = /* @@ -6602,13 +6594,8 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *ta= b, Relation rel, attribute.attbyval =3D tform->typbyval; attribute.attalign =3D tform->typalign; attribute.attstorage =3D tform->typstorage; - /* do not set compression in views etc */ - if (rel->rd_rel->relkind =3D=3D RELKIND_RELATION || - rel->rd_rel->relkind =3D=3D RELKIND_PARTITIONED_TABLE) - attribute.attcompression =3D GetAttributeCompression(&attribute, - colDef->compression); - else - attribute.attcompression =3D InvalidCompressionMethod; + attribute.attcompression =3D GetAttributeCompression(typeOid, + colDef->compression); attribute.attnotnull =3D colDef->is_not_null; attribute.atthasdef =3D false; attribute.atthasmissing =3D false; @@ -7995,23 +7982,24 @@ ATExecSetOptions(Relation rel, const char *colName= , Node *options, /* * Helper function for ATExecSetStorage and ATExecSetCompression * - * Set the attcompression and/or attstorage for the respective index attr= ibute - * if the respective input values are valid. + * Set the attstorage and/or attcompression fields for index columns + * associated with the specified table column. */ static void SetIndexStorageProperties(Relation rel, Relation attrelation, - AttrNumber attnum, char newcompression, - char newstorage, LOCKMODE lockmode) + AttrNumber attnum, + bool setstorage, char newstorage, + bool setcompression, char newcompression, + LOCKMODE lockmode) { - HeapTuple tuple; ListCell *lc; - Form_pg_attribute attrtuple; = foreach(lc, RelationGetIndexList(rel)) { Oid indexoid =3D lfirst_oid(lc); Relation indrel; AttrNumber indattnum =3D 0; + HeapTuple tuple; = indrel =3D index_open(indexoid, lockmode); = @@ -8034,14 +8022,14 @@ SetIndexStorageProperties(Relation rel, Relation a= ttrelation, = if (HeapTupleIsValid(tuple)) { - attrtuple =3D (Form_pg_attribute) GETSTRUCT(tuple); - - if (CompressionMethodIsValid(newcompression)) - attrtuple->attcompression =3D newcompression; + Form_pg_attribute attrtuple =3D (Form_pg_attribute) GETSTRUCT(tuple); = - if (newstorage !=3D '\0') + if (setstorage) attrtuple->attstorage =3D newstorage; = + if (setcompression) + attrtuple->attcompression =3D newcompression; + CatalogTupleUpdate(attrelation, &tuple->t_self, tuple); = InvokeObjectPostAlterHook(RelationRelationId, @@ -8134,8 +8122,9 @@ ATExecSetStorage(Relation rel, const char *colName, = Node *newValue, LOCKMODE loc * matching behavior of index.c ConstructTupleDescriptor()). */ SetIndexStorageProperties(rel, attrelation, attnum, - InvalidCompressionMethod, - newstorage, lockmode); + true, newstorage, + false, 0, + lockmode); = table_close(attrelation, RowExclusiveLock); = @@ -12299,23 +12288,7 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Rela= tion rel, attTup->attbyval =3D tform->typbyval; attTup->attalign =3D tform->typalign; attTup->attstorage =3D tform->typstorage; - - /* Setup attribute compression */ - if (rel->rd_rel->relkind =3D=3D RELKIND_RELATION || - rel->rd_rel->relkind =3D=3D RELKIND_PARTITIONED_TABLE) - { - /* - * No compression for plain/external storage, otherwise, default - * compression method if it is not already set, refer comments atop - * attcompression parameter in pg_attribute.h. - */ - if (!IsStorageCompressible(tform->typstorage)) - attTup->attcompression =3D InvalidCompressionMethod; - else if (!CompressionMethodIsValid(attTup->attcompression)) - attTup->attcompression =3D GetDefaultToastCompression(); - } - else - attTup->attcompression =3D InvalidCompressionMethod; + attTup->attcompression =3D InvalidCompressionMethod; = ReleaseSysCache(typeTuple); = @@ -15613,7 +15586,6 @@ ATExecSetCompression(AlteredTableInfo *tab, Form_pg_attribute atttableform; AttrNumber attnum; char *compression; - char typstorage; char cmethod; ObjectAddress address; = @@ -15638,17 +15610,11 @@ ATExecSetCompression(AlteredTableInfo *tab, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot alter system column \"%s\"", column))); = - typstorage =3D get_typstorage(atttableform->atttypid); - - /* prevent from setting compression methods for uncompressible type */ - if (!IsStorageCompressible(typstorage)) - ereport(ERROR, - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("column data type %s does not support compression", - format_type_be(atttableform->atttypid)))); - - /* get the attribute compression method. */ - cmethod =3D GetAttributeCompression(atttableform, compression); + /* + * Check that column type is compressible, then get the attribute + * compression method code + */ + cmethod =3D GetAttributeCompression(atttableform->atttypid, compression)= ; = /* update pg_attribute entry */ atttableform->attcompression =3D cmethod; @@ -15662,7 +15628,10 @@ ATExecSetCompression(AlteredTableInfo *tab, * Apply the change to indexes as well (only for simple index columns, * matching behavior of index.c ConstructTupleDescriptor()). */ - SetIndexStorageProperties(rel, attrel, attnum, cmethod, '\0', lockmode); + SetIndexStorageProperties(rel, attrel, attnum, + false, 0, + true, cmethod, + lockmode); = heap_freetuple(tuple); = @@ -18612,29 +18581,26 @@ ATDetachCheckNoForeignKeyRefs(Relation partition= ) * resolve column compression specification to compression method. */ static char -GetAttributeCompression(Form_pg_attribute att, char *compression) +GetAttributeCompression(Oid atttypid, char *compression) { - char typstorage =3D get_typstorage(att->atttypid); + char typstorage; char cmethod; = + if (compression =3D=3D NULL || strcmp(compression, "default") =3D=3D 0) + return InvalidCompressionMethod; + /* - * No compression for plain/external storage, refer comments atop - * attcompression parameter in pg_attribute.h + * To specify a nondefault method, the column data type must be + * compressible. Note this says nothing about whether the column's + * attstorage setting permits compression; we intentionally allow + * attstorage and attcompression to be independent. */ + typstorage =3D get_typstorage(atttypid); if (!IsStorageCompressible(typstorage)) - { - if (compression =3D=3D NULL) - return InvalidCompressionMethod; - ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("column data type %s does not support compression", - format_type_be(att->atttypid)))); - } - - /* fallback to default compression if it's not specified */ - if (compression =3D=3D NULL) - return GetDefaultToastCompression(); + format_type_be(atttypid)))); = cmethod =3D CompressionNameToMethod(compression); if (!CompressionMethodIsValid(cmethod)) diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index aaf1a51f68..9ee90e3f13 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -561,6 +561,7 @@ static Node *makeRecursiveViewSelect(char *relname, Li= st *aliases, Node *query); = %type TableConstraint TableLikeClause %type TableLikeOptionList TableLikeOption +%type column_compression opt_column_compression %type ColQualList %type ColConstraint ColConstraintElem ConstraintAttr %type key_actions key_delete key_match key_update key_action @@ -609,7 +610,6 @@ static Node *makeRecursiveViewSelect(char *relname, Li= st *aliases, Node *query); %type hash_partbound %type hash_partbound_elem = -%type optColumnCompression = /* * Non-keyword token types. These are hard-wired into the "flex" lexer. @@ -2302,6 +2302,15 @@ alter_table_cmd: n->def =3D (Node *) makeString($6); $$ =3D (Node *)n; } + /* ALTER TABLE ALTER [COLUMN] SET COMPRESSION */ + | ALTER opt_column ColId SET column_compression + { + AlterTableCmd *n =3D makeNode(AlterTableCmd); + n->subtype =3D AT_SetCompression; + n->name =3D $3; + n->def =3D (Node *) makeString($5); + $$ =3D (Node *)n; + } /* ALTER TABLE ALTER [COLUMN] ADD GENERATED ... AS ID= ENTITY ... */ | ALTER opt_column ColId ADD_P GENERATED generated_when AS IDENTITY_P = OptParenthesizedSeqOptList { @@ -2346,15 +2355,6 @@ alter_table_cmd: n->missing_ok =3D true; $$ =3D (Node *)n; } - /* ALTER TABLE ALTER [COLUMN] SET (COMPRESSION ) = */ - | ALTER opt_column ColId SET optColumnCompression - { - AlterTableCmd *n =3D makeNode(AlterTableCmd); - n->subtype =3D AT_SetCompression; - n->name =3D $3; - n->def =3D (Node *) makeString($5); - $$ =3D (Node *)n; - } /* ALTER TABLE DROP [COLUMN] IF EXISTS [RESTRICT|CASC= ADE] */ | DROP opt_column IF_P EXISTS ColId opt_drop_behavior { @@ -3462,7 +3462,7 @@ TypedTableElement: | TableConstraint { $$ =3D $1; } ; = -columnDef: ColId Typename optColumnCompression create_generic_options Col= QualList +columnDef: ColId Typename opt_column_compression create_generic_options C= olQualList { ColumnDef *n =3D makeNode(ColumnDef); n->colname =3D $1; @@ -3522,13 +3522,15 @@ columnOptions: ColId ColQualList } ; = -optColumnCompression: - COMPRESSION name - { - $$ =3D $2; - } - | /*EMPTY*/ { $$ =3D NULL; } - ; +column_compression: + COMPRESSION ColId { $$ =3D $2; } + | COMPRESSION DEFAULT { $$ =3D pstrdup("default"); } + ; + +opt_column_compression: + column_compression { $$ =3D $1; } + | /*EMPTY*/ { $$ =3D NULL; } + ; = ColQualList: ColQualList ColConstraint { $$ =3D lappend($1, $2); } diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index ee731044b6..87bc688704 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -4651,13 +4651,13 @@ static struct config_enum ConfigureNamesEnum[] =3D = { {"default_toast_compression", PGC_USERSET, CLIENT_CONN_STATEMENT, - gettext_noop("Sets the default compression for new columns."), - NULL, - GUC_IS_NAME + gettext_noop("Sets the default compression method for compressible val= ues."), + NULL }, &default_toast_compression, TOAST_PGLZ_COMPRESSION, - default_toast_compression_options, NULL, NULL + default_toast_compression_options, + NULL, NULL, NULL }, = { diff --git a/src/bin/pg_dump/pg_backup.h b/src/bin/pg_dump/pg_backup.h index fc054af5ba..3c1cd858a8 100644 --- a/src/bin/pg_dump/pg_backup.h +++ b/src/bin/pg_dump/pg_backup.h @@ -208,8 +208,6 @@ typedef struct Archive = /* other important stuff */ char *searchpath; /* search_path to set during restore */ - char *default_toast_compression; /* default TOAST compression to - * set during restore */ char *use_role; /* Issue SET ROLE to this */ = /* error handling */ diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_bac= kup_archiver.c index 86de26a4bf..6b046e7734 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -86,7 +86,6 @@ static void _selectTableAccessMethod(ArchiveHandle *AH, = const char *tableam); static void processEncodingEntry(ArchiveHandle *AH, TocEntry *te); static void processStdStringsEntry(ArchiveHandle *AH, TocEntry *te); static void processSearchPathEntry(ArchiveHandle *AH, TocEntry *te); -static void processToastCompressionEntry(ArchiveHandle *AH, TocEntry *te)= ; static int _tocEntryRequired(TocEntry *te, teSection curSection, ArchiveH= andle *AH); static RestorePass _tocEntryRestorePass(TocEntry *te); static bool _tocEntryIsACL(TocEntry *te); @@ -2638,8 +2637,6 @@ ReadToc(ArchiveHandle *AH) processStdStringsEntry(AH, te); else if (strcmp(te->desc, "SEARCHPATH") =3D=3D 0) processSearchPathEntry(AH, te); - else if (strcmp(te->desc, "TOASTCOMPRESSION") =3D=3D 0) - processToastCompressionEntry(AH, te); } } = @@ -2697,29 +2694,6 @@ processSearchPathEntry(ArchiveHandle *AH, TocEntry = *te) AH->public.searchpath =3D pg_strdup(te->defn); } = -static void -processToastCompressionEntry(ArchiveHandle *AH, TocEntry *te) -{ - /* te->defn should have the form SET default_toast_compression =3D 'x'; = */ - char *defn =3D pg_strdup(te->defn); - char *ptr1; - char *ptr2 =3D NULL; - - ptr1 =3D strchr(defn, '\''); - if (ptr1) - ptr2 =3D strchr(++ptr1, '\''); - if (ptr2) - { - *ptr2 =3D '\0'; - AH->public.default_toast_compression =3D pg_strdup(ptr1); - } - else - fatal("invalid TOASTCOMPRESSION item: %s", - te->defn); - - free(defn); -} - static void StrictNamesCheck(RestoreOptions *ropt) { @@ -2779,8 +2753,7 @@ _tocEntryRequired(TocEntry *te, teSection curSection= , ArchiveHandle *AH) /* These items are treated specially */ if (strcmp(te->desc, "ENCODING") =3D=3D 0 || strcmp(te->desc, "STDSTRINGS") =3D=3D 0 || - strcmp(te->desc, "SEARCHPATH") =3D=3D 0 || - strcmp(te->desc, "TOASTCOMPRESSION") =3D=3D 0) + strcmp(te->desc, "SEARCHPATH") =3D=3D 0) return REQ_SPECIAL; = /* @@ -3103,11 +3076,6 @@ _doSetFixedOutputState(ArchiveHandle *AH) if (AH->public.searchpath) ahprintf(AH, "%s", AH->public.searchpath); = - /* Select the dump-time default_toast_compression */ - if (AH->public.default_toast_compression) - ahprintf(AH, "SET default_toast_compression =3D '%s';\n", - AH->public.default_toast_compression); - /* Make sure function checking is disabled */ ahprintf(AH, "SET check_function_bodies =3D false;\n"); = diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 339c393718..e9a86ed512 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -276,7 +276,6 @@ static void dumpDatabaseConfig(Archive *AH, PQExpBuffe= r outbuf, static void dumpEncoding(Archive *AH); static void dumpStdStrings(Archive *AH); static void dumpSearchPath(Archive *AH); -static void dumpToastCompression(Archive *AH); static void binary_upgrade_set_type_oids_by_type_oid(Archive *fout, PQExpBuffer upgrade_buffer, Oid pg_type_oid, @@ -925,13 +924,11 @@ main(int argc, char **argv) */ = /* - * First the special entries for ENCODING, STDSTRINGS, SEARCHPATH and - * TOASTCOMPRESSION. + * First the special entries for ENCODING, STDSTRINGS, and SEARCHPATH. */ dumpEncoding(fout); dumpStdStrings(fout); dumpSearchPath(fout); - dumpToastCompression(fout); = /* The database items are always next, unless we don't want them at all = */ if (dopt.outputCreateDB) @@ -3398,58 +3395,6 @@ dumpSearchPath(Archive *AH) destroyPQExpBuffer(path); } = -/* - * dumpToastCompression: save the dump-time default TOAST compression in = the - * archive - */ -static void -dumpToastCompression(Archive *AH) -{ - char *toast_compression; - PQExpBuffer qry; - - if (AH->dopt->no_toast_compression) - { - /* we don't intend to dump the info, so no need to fetch it either */ - return; - } - - if (AH->remoteVersion < 140000) - { - /* pre-v14, the only method was pglz */ - toast_compression =3D pg_strdup("pglz"); - } - else - { - PGresult *res; - - res =3D ExecuteSqlQueryForSingleRow(AH, "SHOW default_toast_compression= "); - toast_compression =3D pg_strdup(PQgetvalue(res, 0, 0)); - PQclear(res); - } - - qry =3D createPQExpBuffer(); - appendPQExpBufferStr(qry, "SET default_toast_compression =3D "); - appendStringLiteralAH(qry, toast_compression, AH); - appendPQExpBufferStr(qry, ";\n"); - - pg_log_info("saving default_toast_compression =3D %s", toast_compression= ); - - ArchiveEntry(AH, nilCatalogId, createDumpId(), - ARCHIVE_OPTS(.tag =3D "TOASTCOMPRESSION", - .description =3D "TOASTCOMPRESSION", - .section =3D SECTION_PRE_DATA, - .createStmt =3D qry->data)); - - /* - * Also save it in AH->default_toast_compression, in case we're doing - * plain text dump. - */ - AH->default_toast_compression =3D toast_compression; - - destroyPQExpBuffer(qry); -} - = /* * getBlobs: @@ -16421,7 +16366,7 @@ dumpTableSchema(Archive *fout, const TableInfo *tb= info) tbinfo->attfdwoptions[j]); = /* - * Dump per-column compression, if different from default. + * Dump per-column compression, if it's been set. */ if (!dopt->no_toast_compression) { @@ -16440,9 +16385,7 @@ dumpTableSchema(Archive *fout, const TableInfo *tb= info) break; } = - if (cmname !=3D NULL && - (fout->default_toast_compression =3D=3D NULL || - strcmp(cmname, fout->default_toast_compression) !=3D 0)) + if (cmname !=3D NULL) appendPQExpBuffer(q, "ALTER %sTABLE ONLY %s ALTER COLUMN %s SET COMP= RESSION %s;\n", foreign, qualrelname, fmtId(tbinfo->attnames[j]), diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 3e39fdb545..e461bcefb9 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -2055,7 +2055,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, ",\n a.attstorage"); attstorage_col =3D cols++; = - /* compression info */ + /* compression info, if relevant to relkind */ if (pset.sversion >=3D 140000 && !pset.hide_compression && (tableinfo.relkind =3D=3D RELKIND_RELATION || diff --git a/src/include/access/toast_compression.h b/src/include/access/t= oast_compression.h index 9e2c1cbe1a..4d5ca57dfb 100644 --- a/src/include/access/toast_compression.h +++ b/src/include/access/toast_compression.h @@ -23,16 +23,16 @@ extern int default_toast_compression; = /* - * Built-in compression method-id. The toast compression header will sto= re + * Built-in compression method ID. The toast compression header will sto= re * this in the first 2 bits of the raw length. These built-in compressio= n - * method-id are directly mapped to the built-in compression methods. + * method IDs are directly mapped to the built-in compression methods. * * Don't use these values for anything other than understanding the meani= ng * of the raw bits from a varlena; in particular, if the goal is to ident= ify * a compression method, use the constants TOAST_PGLZ_COMPRESSION, etc. * below. We might someday support more than 4 compression methods, but * we can never have more than 4 values in this enum, because there are - * only 2 bits available in the places where this is used. + * only 2 bits available in the places where this is stored. */ typedef enum ToastCompressionId { @@ -42,8 +42,9 @@ typedef enum ToastCompressionId } ToastCompressionId; = /* - * Built-in compression methods. pg_attribute will store this in the - * attcompression column. + * Built-in compression methods. pg_attribute will store these in the + * attcompression column. In attcompression, InvalidCompressionMethod + * denotes the default behavior. */ #define TOAST_PGLZ_COMPRESSION 'p' #define TOAST_LZ4_COMPRESSION 'l' @@ -51,19 +52,10 @@ typedef enum ToastCompressionId = #define CompressionMethodIsValid(cm) ((cm) !=3D InvalidCompressionMethod= ) = +/* Test whether a storage mode allows compression to be applied */ #define IsStorageCompressible(storage) ((storage) !=3D TYPSTORAGE_PLAIN &= & \ (storage) !=3D TYPSTORAGE_EXTERNAL) = -/* - * GetDefaultToastCompression -- get the default toast compression method - * - * This exists to hide the use of the default_toast_compression GUC varia= ble. - */ -static inline char -GetDefaultToastCompression(void) -{ - return (char) default_toast_compression; -} = /* pglz compression/decompression routines */ extern struct varlena *pglz_compress_datum(const struct varlena *value); diff --git a/src/include/catalog/pg_attribute.h b/src/include/catalog/pg_a= ttribute.h index 1e26016214..603392fe81 100644 --- a/src/include/catalog/pg_attribute.h +++ b/src/include/catalog/pg_attribute.h @@ -126,8 +126,12 @@ CATALOG(pg_attribute,1249,AttributeRelationId) BKI_BO= OTSTRAP BKI_ROWTYPE_OID(75, char attstorage; = /* - * Compression method. Must be InvalidCompressionMethod if and only if - * typstorage is 'plain' or 'external'. + * attcompression sets the current compression method of the attribute. + * Typically this is InvalidCompressionMethod ('\0') to specify use of t= he + * current default setting (see default_toast_compression). Otherwise, + * 'p' selects pglz compression, while 'l' selects LZ4 compression. + * However, this field is ignored whenever attstorage does not allow + * compression. */ char attcompression BKI_DEFAULT('\0'); = diff --git a/src/test/regress/expected/compression.out b/src/test/regress/= expected/compression.out index 61e97cb33c..5c645e4650 100644 --- a/src/test/regress/expected/compression.out +++ b/src/test/regress/expected/compression.out @@ -53,7 +53,7 @@ SELECT * INTO cmmove1 FROM cmdata; Table "public.cmmove1" Column | Type | Collation | Nullable | Default | Storage | Compression = | Stats target | Description = --------+------+-----------+----------+---------+----------+-------------= +--------------+------------- - f1 | text | | | | extended | pglz = | | = + f1 | text | | | | extended | = | | = = SELECT pg_column_compression(f1) FROM cmmove1; pg_column_compression = @@ -146,7 +146,7 @@ ALTER TABLE cmdata2 ALTER COLUMN f1 TYPE varchar; Table "public.cmdata2" Column | Type | Collation | Nullable | Default | Storage |= Compression | Stats target | Description = --------+-------------------+-----------+----------+---------+----------+= -------------+--------------+------------- - f1 | character varying | | | | extended |= pglz | | = + f1 | character varying | | | | extended |= | | = = ALTER TABLE cmdata2 ALTER COLUMN f1 TYPE int USING f1::integer; \d+ cmdata2 @@ -158,6 +158,7 @@ ALTER TABLE cmdata2 ALTER COLUMN f1 TYPE int USING f1:= :integer; --changing column storage should not impact the compression method --but the data should not be compressed ALTER TABLE cmdata2 ALTER COLUMN f1 TYPE varchar; +ALTER TABLE cmdata2 ALTER COLUMN f1 SET COMPRESSION pglz; \d+ cmdata2 Table "public.cmdata2" Column | Type | Collation | Nullable | Default | Storage |= Compression | Stats target | Description = @@ -179,12 +180,12 @@ SELECT pg_column_compression(f1) FROM cmdata2; (1 row) = -- test compression with materialized view -CREATE MATERIALIZED VIEW mv(x) AS SELECT * FROM cmdata1; -\d+ mv - Materialized view "public.mv" +CREATE MATERIALIZED VIEW compressmv(x) AS SELECT * FROM cmdata1; +\d+ compressmv + Materialized view "public.compressmv" Column | Type | Collation | Nullable | Default | Storage | Compression = | Stats target | Description = --------+------+-----------+----------+---------+----------+-------------= +--------------+------------- - x | text | | | | extended | pglz = | | = + x | text | | | | extended | = | | = View definition: SELECT cmdata1.f1 AS x FROM cmdata1; @@ -196,7 +197,7 @@ SELECT pg_column_compression(f1) FROM cmdata1; lz4 (2 rows) = -SELECT pg_column_compression(x) FROM mv; +SELECT pg_column_compression(x) FROM compressmv; pg_column_compression = ----------------------- lz4 @@ -222,7 +223,7 @@ SELECT pg_column_compression(f1) FROM cmpart2; pglz (1 row) = --- test compression with inheritence, error +-- test compression with inheritance, error CREATE TABLE cminh() INHERITS(cmdata, cmdata1); NOTICE: merging multiple inherited definitions of column "f1" ERROR: column "f1" has a compression method conflict @@ -239,14 +240,6 @@ SET default_toast_compression =3D 'I do not exist com= pression'; ERROR: invalid value for parameter "default_toast_compression": "I do no= t exist compression" HINT: Available values: pglz, lz4. SET default_toast_compression =3D 'lz4'; -DROP TABLE cmdata2; -CREATE TABLE cmdata2 (f1 text); -\d+ cmdata2 - Table "public.cmdata2" - Column | Type | Collation | Nullable | Default | Storage | Compression = | Stats target | Description = ---------+------+-----------+----------+---------+----------+-------------= +--------------+------------- - f1 | text | | | | extended | lz4 = | | = - SET default_toast_compression =3D 'pglz'; -- test alter compression method ALTER TABLE cmdata ALTER COLUMN f1 SET COMPRESSION lz4; @@ -266,10 +259,17 @@ SELECT pg_column_compression(f1) FROM cmdata; lz4 (2 rows) = --- test alter compression method for the materialized view -ALTER MATERIALIZED VIEW mv ALTER COLUMN x SET COMPRESSION lz4; -\d+ mv - Materialized view "public.mv" +ALTER TABLE cmdata2 ALTER COLUMN f1 SET COMPRESSION default; +\d+ cmdata2 + Table "public.cmdata2" + Column | Type | Collation | Nullable | Default | Storage | = Compression | Stats target | Description = +--------+-------------------+-----------+----------+---------+---------+-= ------------+--------------+------------- + f1 | character varying | | | | plain | = | | = + +-- test alter compression method for materialized views +ALTER MATERIALIZED VIEW compressmv ALTER COLUMN x SET COMPRESSION lz4; +\d+ compressmv + Materialized view "public.compressmv" Column | Type | Collation | Nullable | Default | Storage | Compression = | Stats target | Description = --------+------+-----------+----------+---------+----------+-------------= +--------------+------------- x | text | | | | extended | lz4 = | | = @@ -277,7 +277,7 @@ View definition: SELECT cmdata1.f1 AS x FROM cmdata1; = --- test alter compression method for the partitioned table +-- test alter compression method for partitioned tables ALTER TABLE cmpart1 ALTER COLUMN f1 SET COMPRESSION pglz; ALTER TABLE cmpart2 ALTER COLUMN f1 SET COMPRESSION lz4; -- new data should be compressed with the current compression method diff --git a/src/test/regress/expected/compression_1.out b/src/test/regres= s/expected/compression_1.out index d03d6255ae..aac96037fc 100644 --- a/src/test/regress/expected/compression_1.out +++ b/src/test/regress/expected/compression_1.out @@ -50,7 +50,7 @@ SELECT * INTO cmmove1 FROM cmdata; Table "public.cmmove1" Column | Type | Collation | Nullable | Default | Storage | Compression = | Stats target | Description = --------+------+-----------+----------+---------+----------+-------------= +--------------+------------- - f1 | text | | | | extended | pglz = | | = + f1 | text | | | | extended | = | | = = SELECT pg_column_compression(f1) FROM cmmove1; pg_column_compression = @@ -144,7 +144,7 @@ ALTER TABLE cmdata2 ALTER COLUMN f1 TYPE varchar; Table "public.cmdata2" Column | Type | Collation | Nullable | Default | Storage |= Compression | Stats target | Description = --------+-------------------+-----------+----------+---------+----------+= -------------+--------------+------------- - f1 | character varying | | | | extended |= pglz | | = + f1 | character varying | | | | extended |= | | = = ALTER TABLE cmdata2 ALTER COLUMN f1 TYPE int USING f1::integer; \d+ cmdata2 @@ -156,6 +156,7 @@ ALTER TABLE cmdata2 ALTER COLUMN f1 TYPE int USING f1:= :integer; --changing column storage should not impact the compression method --but the data should not be compressed ALTER TABLE cmdata2 ALTER COLUMN f1 TYPE varchar; +ALTER TABLE cmdata2 ALTER COLUMN f1 SET COMPRESSION pglz; \d+ cmdata2 Table "public.cmdata2" Column | Type | Collation | Nullable | Default | Storage |= Compression | Stats target | Description = @@ -177,18 +178,18 @@ SELECT pg_column_compression(f1) FROM cmdata2; (1 row) = -- test compression with materialized view -CREATE MATERIALIZED VIEW mv(x) AS SELECT * FROM cmdata1; +CREATE MATERIALIZED VIEW compressmv(x) AS SELECT * FROM cmdata1; ERROR: relation "cmdata1" does not exist -LINE 1: CREATE MATERIALIZED VIEW mv(x) AS SELECT * FROM cmdata1; - ^ -\d+ mv +LINE 1: ...TE MATERIALIZED VIEW compressmv(x) AS SELECT * FROM cmdata1; + ^ +\d+ compressmv SELECT pg_column_compression(f1) FROM cmdata1; ERROR: relation "cmdata1" does not exist LINE 1: SELECT pg_column_compression(f1) FROM cmdata1; ^ -SELECT pg_column_compression(x) FROM mv; -ERROR: relation "mv" does not exist -LINE 1: SELECT pg_column_compression(x) FROM mv; +SELECT pg_column_compression(x) FROM compressmv; +ERROR: relation "compressmv" does not exist +LINE 1: SELECT pg_column_compression(x) FROM compressmv; ^ -- test compression with partition CREATE TABLE cmpart(f1 text COMPRESSION lz4) PARTITION BY HASH(f1); @@ -217,7 +218,7 @@ SELECT pg_column_compression(f1) FROM cmpart2; ----------------------- (0 rows) = --- test compression with inheritence, error +-- test compression with inheritance, error CREATE TABLE cminh() INHERITS(cmdata, cmdata1); ERROR: relation "cmdata1" does not exist CREATE TABLE cminh(f1 TEXT COMPRESSION lz4) INHERITS(cmdata); @@ -234,14 +235,6 @@ HINT: Available values: pglz. SET default_toast_compression =3D 'lz4'; ERROR: invalid value for parameter "default_toast_compression": "lz4" HINT: Available values: pglz. -DROP TABLE cmdata2; -CREATE TABLE cmdata2 (f1 text); -\d+ cmdata2 - Table "public.cmdata2" - Column | Type | Collation | Nullable | Default | Storage | Compression = | Stats target | Description = ---------+------+-----------+----------+---------+----------+-------------= +--------------+------------- - f1 | text | | | | extended | pglz = | | = - SET default_toast_compression =3D 'pglz'; -- test alter compression method ALTER TABLE cmdata ALTER COLUMN f1 SET COMPRESSION lz4; @@ -264,11 +257,18 @@ SELECT pg_column_compression(f1) FROM cmdata; pglz (2 rows) = --- test alter compression method for the materialized view -ALTER MATERIALIZED VIEW mv ALTER COLUMN x SET COMPRESSION lz4; -ERROR: relation "mv" does not exist -\d+ mv --- test alter compression method for the partitioned table +ALTER TABLE cmdata2 ALTER COLUMN f1 SET COMPRESSION default; +\d+ cmdata2 + Table "public.cmdata2" + Column | Type | Collation | Nullable | Default | Storage | = Compression | Stats target | Description = +--------+-------------------+-----------+----------+---------+---------+-= ------------+--------------+------------- + f1 | character varying | | | | plain | = | | = + +-- test alter compression method for materialized views +ALTER MATERIALIZED VIEW compressmv ALTER COLUMN x SET COMPRESSION lz4; +ERROR: relation "compressmv" does not exist +\d+ compressmv +-- test alter compression method for partitioned tables ALTER TABLE cmpart1 ALTER COLUMN f1 SET COMPRESSION pglz; ERROR: relation "cmpart1" does not exist ALTER TABLE cmpart2 ALTER COLUMN f1 SET COMPRESSION lz4; diff --git a/src/test/regress/sql/compression.sql b/src/test/regress/sql/c= ompression.sql index 76d1776d83..35557c1f7d 100644 --- a/src/test/regress/sql/compression.sql +++ b/src/test/regress/sql/compression.sql @@ -69,6 +69,7 @@ ALTER TABLE cmdata2 ALTER COLUMN f1 TYPE int USING f1::i= nteger; --changing column storage should not impact the compression method --but the data should not be compressed ALTER TABLE cmdata2 ALTER COLUMN f1 TYPE varchar; +ALTER TABLE cmdata2 ALTER COLUMN f1 SET COMPRESSION pglz; \d+ cmdata2 ALTER TABLE cmdata2 ALTER COLUMN f1 SET STORAGE plain; \d+ cmdata2 @@ -76,10 +77,10 @@ INSERT INTO cmdata2 VALUES (repeat('123456789', 800)); SELECT pg_column_compression(f1) FROM cmdata2; = -- test compression with materialized view -CREATE MATERIALIZED VIEW mv(x) AS SELECT * FROM cmdata1; -\d+ mv +CREATE MATERIALIZED VIEW compressmv(x) AS SELECT * FROM cmdata1; +\d+ compressmv SELECT pg_column_compression(f1) FROM cmdata1; -SELECT pg_column_compression(x) FROM mv; +SELECT pg_column_compression(x) FROM compressmv; = -- test compression with partition CREATE TABLE cmpart(f1 text COMPRESSION lz4) PARTITION BY HASH(f1); @@ -92,7 +93,7 @@ INSERT INTO cmpart VALUES (repeat('123456789', 4004)); SELECT pg_column_compression(f1) FROM cmpart1; SELECT pg_column_compression(f1) FROM cmpart2; = --- test compression with inheritence, error +-- test compression with inheritance, error CREATE TABLE cminh() INHERITS(cmdata, cmdata1); CREATE TABLE cminh(f1 TEXT COMPRESSION lz4) INHERITS(cmdata); = @@ -100,9 +101,6 @@ CREATE TABLE cminh(f1 TEXT COMPRESSION lz4) INHERITS(c= mdata); SET default_toast_compression =3D ''; SET default_toast_compression =3D 'I do not exist compression'; SET default_toast_compression =3D 'lz4'; -DROP TABLE cmdata2; -CREATE TABLE cmdata2 (f1 text); -\d+ cmdata2 SET default_toast_compression =3D 'pglz'; = -- test alter compression method @@ -111,11 +109,14 @@ INSERT INTO cmdata VALUES (repeat('123456789', 4004)= ); \d+ cmdata SELECT pg_column_compression(f1) FROM cmdata; = --- test alter compression method for the materialized view -ALTER MATERIALIZED VIEW mv ALTER COLUMN x SET COMPRESSION lz4; -\d+ mv +ALTER TABLE cmdata2 ALTER COLUMN f1 SET COMPRESSION default; +\d+ cmdata2 + +-- test alter compression method for materialized views +ALTER MATERIALIZED VIEW compressmv ALTER COLUMN x SET COMPRESSION lz4; +\d+ compressmv = --- test alter compression method for the partitioned table +-- test alter compression method for partitioned tables ALTER TABLE cmpart1 ALTER COLUMN f1 SET COMPRESSION pglz; ALTER TABLE cmpart2 ALTER COLUMN f1 SET COMPRESSION lz4; = ------- =_aaaaaaaaaa0--