Skip to content

Commit

Permalink
Skip expression columns when verifying index for compression
Browse files Browse the repository at this point in the history
Fixes #6205
  • Loading branch information
konskov committed Oct 18, 2023
1 parent 5f5f519 commit 2634bc4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tsl/src/compression/create.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions tsl/test/expected/compression_ddl.out
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions tsl/test/sql/compression_ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 2634bc4

Please sign in to comment.