diff --git a/.unreleased/PR_6209 b/.unreleased/PR_6209 new file mode 100644 index 00000000000..d31ead1c4de --- /dev/null +++ b/.unreleased/PR_6209 @@ -0,0 +1 @@ +Fixes: #6209 Allow enabling compression on hypertable with unique expression index diff --git a/tsl/src/compression/create.c b/tsl/src/compression/create.c index 0e741516151..ad1f59c2cce 100644 --- a/tsl/src/compression/create.c +++ b/tsl/src/compression/create.c @@ -956,6 +956,8 @@ validate_existing_indexes(Hypertable *ht, CompressColInfo *colinfo, Bitmapset *i for (int i = 0; i < index->indnkeyatts; i++) { int attno = index->indkey.values[i]; + if (attno == 0) + continue; /* skip check for expression column */ Form_hypertable_compression col_def = get_col_info_for_attnum(ht, colinfo, attno); Ensure(col_def, "missing column definition for unique index"); if (col_def->segmentby_column_index < 1 && col_def->orderby_column_index < 1) diff --git a/tsl/test/expected/compression_ddl.out b/tsl/test/expected/compression_ddl.out index ac9a0d6041e..21254de876c 100644 --- a/tsl/test/expected/compression_ddl.out +++ b/tsl/test/expected/compression_ddl.out @@ -2392,3 +2392,20 @@ EXPLAIN (COSTS OFF) SELECT * FROM space_part ORDER BY time; -> Seq Scan on _hyper_36_135_chunk (35 rows) +-- test creation of unique expression index does not interfere with enabling compression +-- github issue 6205 +create table mytab (col1 varchar(100) not null, col2 integer not null, +value double precision not null default 0, arrival_ts timestamptz not null, departure_ts timestamptz not null +default current_timestamp); +select create_hypertable('mytab', 'departure_ts'); +WARNING: column type "character varying" used for "col1" does not follow best practices + create_hypertable +--------------------- + (38,public,mytab,t) +(1 row) + +create unique index myidx_unique ON +mytab (lower(col1::text), col2, departure_ts, arrival_ts); +alter table mytab set (timescaledb.compress); +WARNING: column "col2" should be used for segmenting or ordering +WARNING: column "arrival_ts" should be used for segmenting or ordering diff --git a/tsl/test/sql/compression_ddl.sql b/tsl/test/sql/compression_ddl.sql index 789b0a4aa07..e0ed32583a8 100644 --- a/tsl/test/sql/compression_ddl.sql +++ b/tsl/test/sql/compression_ddl.sql @@ -965,3 +965,14 @@ EXPLAIN (COSTS OFF) SELECT * FROM space_part ORDER BY time; INSERT INTO space_part VALUES ('2022-01-01 00:02', 1, 1, 1); EXPLAIN (COSTS OFF) SELECT * FROM space_part ORDER BY time; + +-- test creation of unique expression index does not interfere with enabling compression +-- github issue 6205 +create table mytab (col1 varchar(100) not null, col2 integer not null, +value double precision not null default 0, arrival_ts timestamptz not null, departure_ts timestamptz not null +default current_timestamp); + +select create_hypertable('mytab', 'departure_ts'); +create unique index myidx_unique ON +mytab (lower(col1::text), col2, departure_ts, arrival_ts); +alter table mytab set (timescaledb.compress);