4040#include "catalog/pg_am.h"
4141#include "catalog/pg_authid.h"
4242#include "catalog/pg_collation.h"
43+ #include "catalog/pg_compression.h"
4344#include "catalog/pg_constraint.h"
4445#include "catalog/pg_constraint_fn.h"
4546#include "catalog/pg_depend.h"
@@ -3623,6 +3624,66 @@ AlterTypeNamespaceInternal(Oid typeOid, Oid nspOid,
36233624return oldNspOid ;
36243625}
36253626
3627+
3628+ /*
3629+ * Execute ALTER TYPE SET COMPRESSED <cm> [WITH (<option>, ...)]
3630+ */
3631+ static void
3632+ AlterTypeDefaultCompression (Oid typeid ,ColumnCompression * compression )
3633+ {
3634+ Oid cmoid ;
3635+ Type oldtup = typeidType (typeid );
3636+ Form_pg_type oldtype = (Form_pg_type )GETSTRUCT (oldtup );
3637+
3638+ cmoid = compression -> methodName
3639+ ?get_compression_method_oid (compression -> methodName , false)
3640+ :InvalidOid ;
3641+
3642+ if (oldtype -> typdefaultcm != cmoid )
3643+ {
3644+ Relation typrel ;
3645+ HeapTuple newtup ;
3646+ Datum values [Natts_pg_type ];
3647+ bool nulls [Natts_pg_type ];
3648+ bool replace [Natts_pg_type ];
3649+
3650+ typrel = heap_open (TypeRelationId ,RowExclusiveLock );
3651+
3652+ memset (replace ,0 ,sizeof (replace ));
3653+
3654+ values [Anum_pg_type_typdefaultcm - 1 ]= ObjectIdGetDatum (cmoid );
3655+ nulls [Anum_pg_type_typdefaultcm - 1 ]= false;
3656+ replace [Anum_pg_type_typdefaultcm - 1 ]= true;
3657+
3658+ newtup = heap_modify_tuple (oldtup ,RelationGetDescr (typrel ),
3659+ values ,nulls ,replace );
3660+
3661+ CatalogTupleUpdate (typrel ,& newtup -> t_self ,newtup );
3662+
3663+ heap_freetuple (newtup );
3664+
3665+ heap_close (typrel ,RowExclusiveLock );
3666+
3667+ if (OidIsValid (oldtype -> typdefaultcm ))
3668+ deleteDependencyRecordsForClass (TypeRelationId ,typeid ,0 ,
3669+ CompressionMethodRelationId ,
3670+ DEPENDENCY_NORMAL );
3671+
3672+ if (OidIsValid (cmoid ))
3673+ {
3674+ ObjectAddress myself ,
3675+ referenced ;
3676+ ObjectAddressSet (myself ,TypeRelationId ,typeid );
3677+ ObjectAddressSet (referenced ,CompressionMethodRelationId ,cmoid );
3678+ recordDependencyOn (& myself ,& referenced ,DEPENDENCY_NORMAL );
3679+ }
3680+
3681+ InvokeObjectPostAlterHook (TypeRelationId ,typeid ,0 );
3682+ }
3683+
3684+ ReleaseSysCache (oldtup );
3685+ }
3686+
36263687/*
36273688 * Execute ALTER TYPE <typeName> <command>, ...
36283689 */
@@ -3643,6 +3704,10 @@ AlterType(AlterTypeStmt *stmt)
36433704
36443705switch (cmd -> cmdtype )
36453706{
3707+ case AT_AlterTypeCompression :
3708+ AlterTypeDefaultCompression (typeid ,
3709+ (ColumnCompression * )cmd -> def );
3710+ break ;
36463711default :
36473712elog (ERROR ,"unknown ALTER TYPE command %d" ,cmd -> cmdtype );
36483713}