From bd3a070369b3ac2c0be113a05ffec220982f8f54 Mon Sep 17 00:00:00 2001 From: Onder Kalaci Date: Fri, 24 Jun 2022 11:24:57 +0200 Subject: [PATCH] Fixes a bug that prevents upgrades when there COMPRESSION and DEFAULT columns --- .../distributed/deparser/citus_ruleutils.c | 16 +++++----- src/test/regress/expected/pg14.out | 29 +++++++++++++++++++ src/test/regress/sql/pg14.sql | 24 +++++++++++++++ 3 files changed, 61 insertions(+), 8 deletions(-) diff --git a/src/backend/distributed/deparser/citus_ruleutils.c b/src/backend/distributed/deparser/citus_ruleutils.c index d3434d775..0cc3c1e0e 100644 --- a/src/backend/distributed/deparser/citus_ruleutils.c +++ b/src/backend/distributed/deparser/citus_ruleutils.c @@ -377,6 +377,14 @@ pg_get_tableschemadef_string(Oid tableRelationId, IncludeSequenceDefaults atttypmod); appendStringInfoString(&buffer, attributeTypeName); +#if PG_VERSION_NUM >= PG_VERSION_14 + if (CompressionMethodIsValid(attributeForm->attcompression)) + { + appendStringInfo(&buffer, " COMPRESSION %s", + GetCompressionMethodName(attributeForm->attcompression)); + } +#endif + /* if this column has a default value, append the default value */ if (attributeForm->atthasdef) { @@ -448,14 +456,6 @@ pg_get_tableschemadef_string(Oid tableRelationId, IncludeSequenceDefaults appendStringInfoString(&buffer, " NOT NULL"); } -#if PG_VERSION_NUM >= PG_VERSION_14 - if (CompressionMethodIsValid(attributeForm->attcompression)) - { - appendStringInfo(&buffer, " COMPRESSION %s", - GetCompressionMethodName(attributeForm->attcompression)); - } -#endif - if (attributeForm->attcollation != InvalidOid && attributeForm->attcollation != DEFAULT_COLLATION_OID) { diff --git a/src/test/regress/expected/pg14.out b/src/test/regress/expected/pg14.out index c5c60fd70..c19982eb6 100644 --- a/src/test/regress/expected/pg14.out +++ b/src/test/regress/expected/pg14.out @@ -1376,6 +1376,35 @@ SELECT create_distributed_table('ctlt1', 'a'); (1 row) CREATE TABLE ctlt_all_2 (LIKE ctlt1 INCLUDING ALL); +CREATE TABLE compression_and_defaults ( + data text COMPRESSION lz4 DEFAULT '"{}"'::text COLLATE "C" NOT NULL PRIMARY KEY, + rev text +) +WITH ( + autovacuum_vacuum_scale_factor='0.01', + fillfactor='75' +); +SELECT create_distributed_table('compression_and_defaults', 'data', colocate_with:='none'); + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + +CREATE TABLE compression_and_generated_col ( + data text COMPRESSION lz4 GENERATED ALWAYS AS (rev || '{]') STORED COLLATE "C" NOT NULL, + rev text +) +WITH ( + autovacuum_vacuum_scale_factor='0.01', + fillfactor='75' +); +SELECT create_distributed_table('compression_and_generated_col', 'rev', colocate_with:='none'); + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + +DROP TABLE compression_and_defaults, compression_and_generated_col; -- cleanup set client_min_messages to error; drop extension postgres_fdw cascade; diff --git a/src/test/regress/sql/pg14.sql b/src/test/regress/sql/pg14.sql index 2c400efca..436be6631 100644 --- a/src/test/regress/sql/pg14.sql +++ b/src/test/regress/sql/pg14.sql @@ -713,6 +713,30 @@ CREATE STATISTICS ctlt1_expr_stat ON (a || b) FROM ctlt1; CREATE TABLE ctlt_all (LIKE ctlt1 INCLUDING ALL); SELECT create_distributed_table('ctlt1', 'a'); CREATE TABLE ctlt_all_2 (LIKE ctlt1 INCLUDING ALL); + +CREATE TABLE compression_and_defaults ( + data text COMPRESSION lz4 DEFAULT '"{}"'::text COLLATE "C" NOT NULL PRIMARY KEY, + rev text +) +WITH ( + autovacuum_vacuum_scale_factor='0.01', + fillfactor='75' +); + +SELECT create_distributed_table('compression_and_defaults', 'data', colocate_with:='none'); + +CREATE TABLE compression_and_generated_col ( + data text COMPRESSION lz4 GENERATED ALWAYS AS (rev || '{]') STORED COLLATE "C" NOT NULL, + rev text +) +WITH ( + autovacuum_vacuum_scale_factor='0.01', + fillfactor='75' +); +SELECT create_distributed_table('compression_and_generated_col', 'rev', colocate_with:='none'); + +DROP TABLE compression_and_defaults, compression_and_generated_col; + -- cleanup set client_min_messages to error; drop extension postgres_fdw cascade;