From 5c197d8023b565e1c3e6a0eefc07e95601b003b2 Mon Sep 17 00:00:00 2001 From: Dmitry Simonenko Date: Thu, 20 Aug 2020 15:14:33 +0300 Subject: [PATCH] Check CREATE INDEX with transaction per chunk using dist hypertable Issue: #836 --- src/process_utility.c | 6 ++++++ tsl/test/expected/dist_hypertable-11.out | 25 ++++++++++++++++++++++++ tsl/test/expected/dist_hypertable-12.out | 25 ++++++++++++++++++++++++ tsl/test/sql/dist_hypertable.sql.in | 21 ++++++++++++++++++++ 4 files changed, 77 insertions(+) diff --git a/src/process_utility.c b/src/process_utility.c index 3bb0d5cb06d..3dc8460cc2c 100644 --- a/src/process_utility.c +++ b/src/process_utility.c @@ -1991,6 +1991,12 @@ process_index_start(ProcessUtilityArgs *args) errmsg( "cannot use timescaledb.transaction_per_chunk with UNIQUE or PRIMARY KEY"))); + if (info.extended_options.multitransaction && hypertable_is_distributed(ht)) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg( + "cannot use timescaledb.transaction_per_chunk with distributed hypetable"))); + ts_indexing_verify_index(ht->space, stmt); if (info.extended_options.multitransaction) diff --git a/tsl/test/expected/dist_hypertable-11.out b/tsl/test/expected/dist_hypertable-11.out index 93c4b650b36..81bec4ae64c 100644 --- a/tsl/test/expected/dist_hypertable-11.out +++ b/tsl/test/expected/dist_hypertable-11.out @@ -4544,3 +4544,28 @@ SELECT * FROM _timescaledb_catalog.hypertable_id_seq; 24 | 23 | t (1 row) +-- Test creating index with transaction per chunk on a distributed hypertable +-- +DROP TABLE disttable; +CREATE TABLE disttable( + time timestamptz NOT NULL, + device int, + value float +); +SELECT * FROM create_distributed_hypertable('disttable', 'time', 'device', 3); + hypertable_id | schema_name | table_name | created +---------------+-------------+------------+--------- + 25 | public | disttable | t +(1 row) + +INSERT INTO disttable VALUES + ('2017-01-01 06:01', 1, 1.2), + ('2017-01-01 09:11', 3, 4.3), + ('2017-01-01 08:01', 1, 7.3), + ('2017-01-02 08:01', 2, 0.23), + ('2018-07-02 08:01', 87, 0.0), + ('2018-07-01 06:01', 13, 3.1), + ('2018-07-01 09:11', 90, 10303.12), + ('2018-07-01 08:01', 29, 64); +CREATE INDEX disttable_time_device_idx ON disttable (time, device) WITH (timescaledb.transaction_per_chunk); +ERROR: cannot use timescaledb.transaction_per_chunk with distributed hypetable diff --git a/tsl/test/expected/dist_hypertable-12.out b/tsl/test/expected/dist_hypertable-12.out index b4803adce87..d1aaf7432f3 100644 --- a/tsl/test/expected/dist_hypertable-12.out +++ b/tsl/test/expected/dist_hypertable-12.out @@ -4524,3 +4524,28 @@ SELECT * FROM _timescaledb_catalog.hypertable_id_seq; 24 | 23 | t (1 row) +-- Test creating index with transaction per chunk on a distributed hypertable +-- +DROP TABLE disttable; +CREATE TABLE disttable( + time timestamptz NOT NULL, + device int, + value float +); +SELECT * FROM create_distributed_hypertable('disttable', 'time', 'device', 3); + hypertable_id | schema_name | table_name | created +---------------+-------------+------------+--------- + 25 | public | disttable | t +(1 row) + +INSERT INTO disttable VALUES + ('2017-01-01 06:01', 1, 1.2), + ('2017-01-01 09:11', 3, 4.3), + ('2017-01-01 08:01', 1, 7.3), + ('2017-01-02 08:01', 2, 0.23), + ('2018-07-02 08:01', 87, 0.0), + ('2018-07-01 06:01', 13, 3.1), + ('2018-07-01 09:11', 90, 10303.12), + ('2018-07-01 08:01', 29, 64); +CREATE INDEX disttable_time_device_idx ON disttable (time, device) WITH (timescaledb.transaction_per_chunk); +ERROR: cannot use timescaledb.transaction_per_chunk with distributed hypetable diff --git a/tsl/test/sql/dist_hypertable.sql.in b/tsl/test/sql/dist_hypertable.sql.in index bd631a607ad..abf25831180 100644 --- a/tsl/test/sql/dist_hypertable.sql.in +++ b/tsl/test/sql/dist_hypertable.sql.in @@ -1446,3 +1446,24 @@ SELECT * FROM _timescaledb_catalog.hypertable_id_seq; SELECT * FROM create_distributed_hypertable('whatever', 'timestamp', 'user_id', if_not_exists => true, chunk_time_interval => INTERVAL '1 day'); SELECT * FROM _timescaledb_catalog.hypertable_id_seq; + +-- Test creating index with transaction per chunk on a distributed hypertable +-- +DROP TABLE disttable; + +CREATE TABLE disttable( + time timestamptz NOT NULL, + device int, + value float +); +SELECT * FROM create_distributed_hypertable('disttable', 'time', 'device', 3); +INSERT INTO disttable VALUES + ('2017-01-01 06:01', 1, 1.2), + ('2017-01-01 09:11', 3, 4.3), + ('2017-01-01 08:01', 1, 7.3), + ('2017-01-02 08:01', 2, 0.23), + ('2018-07-02 08:01', 87, 0.0), + ('2018-07-01 06:01', 13, 3.1), + ('2018-07-01 09:11', 90, 10303.12), + ('2018-07-01 08:01', 29, 64); +CREATE INDEX disttable_time_device_idx ON disttable (time, device) WITH (timescaledb.transaction_per_chunk);