From 23b3f8d7a6c6f9e5549fcf18cbf70937f02bcc57 Mon Sep 17 00:00:00 2001 From: Ante Kresic Date: Thu, 20 Apr 2023 12:54:28 +0200 Subject: [PATCH] Block unique idx creation on compressed hypertable This block was removed by accident, in order to support this we need to ensure the uniqueness in the compressed data which is something we should do in the future thus removing this block. --- src/process_utility.c | 12 ++++++++++++ tsl/test/expected/compression_ddl.out | 7 +++++++ tsl/test/sql/compression_ddl.sql | 6 ++++++ 3 files changed, 25 insertions(+) diff --git a/src/process_utility.c b/src/process_utility.c index 4d979ee2b..be4bb4f72 100644 --- a/src/process_utility.c +++ b/src/process_utility.c @@ -2711,6 +2711,18 @@ process_index_start(ProcessUtilityArgs *args) /* Make the RangeVar for the underlying materialization hypertable */ stmt->relation = makeRangeVar(NameStr(ht->fd.schema_name), NameStr(ht->fd.table_name), -1); } + else if (TS_HYPERTABLE_HAS_COMPRESSION_ENABLED(ht)) + { + /* unique indexes are not allowed on compressed hypertables*/ + if (stmt->unique || stmt->primary || stmt->isconstraint) + { + ts_cache_release(hcache); + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("operation not supported on hypertables that have compression " + "enabled"))); + } + } ts_hypertable_permissions_check_by_id(ht->fd.id); add_hypertable_to_process_args(args, ht); diff --git a/tsl/test/expected/compression_ddl.out b/tsl/test/expected/compression_ddl.out index c5712da5a..49c9e2ab7 100644 --- a/tsl/test/expected/compression_ddl.out +++ b/tsl/test/expected/compression_ddl.out @@ -62,6 +62,13 @@ DROP INDEX new_index; ALTER TABLE test1 SET (fillfactor=100); ALTER TABLE test1 RESET (fillfactor); ALTER TABLE test1 ALTER COLUMN b SET STATISTICS 10; +-- make sure we cannot create constraints or unique indexes on compressed hypertables +\set ON_ERROR_STOP 0 +ALTER TABLE test1 ADD CONSTRAINT c1 UNIQUE(time,i); +ERROR: operation not supported on hypertables that have compression enabled +CREATE UNIQUE INDEX unique_index ON test1(time,i); +ERROR: operation not supported on hypertables that have compression enabled +\set ON_ERROR_STOP 1 --test adding boolean columns with default and not null CREATE TABLE records (time timestamp NOT NULL); SELECT create_hypertable('records', 'time'); diff --git a/tsl/test/sql/compression_ddl.sql b/tsl/test/sql/compression_ddl.sql index 1a4cd382b..8038973ea 100644 --- a/tsl/test/sql/compression_ddl.sql +++ b/tsl/test/sql/compression_ddl.sql @@ -42,6 +42,12 @@ ALTER TABLE test1 SET (fillfactor=100); ALTER TABLE test1 RESET (fillfactor); ALTER TABLE test1 ALTER COLUMN b SET STATISTICS 10; +-- make sure we cannot create constraints or unique indexes on compressed hypertables +\set ON_ERROR_STOP 0 +ALTER TABLE test1 ADD CONSTRAINT c1 UNIQUE(time,i); +CREATE UNIQUE INDEX unique_index ON test1(time,i); +\set ON_ERROR_STOP 1 + --test adding boolean columns with default and not null CREATE TABLE records (time timestamp NOT NULL); SELECT create_hypertable('records', 'time');