From 33d5d11821a153b20c2b5e9084c68db10e39b2bb Mon Sep 17 00:00:00 2001 From: Dmitry Simonenko Date: Fri, 21 Aug 2020 12:17:48 +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 539e5df6217..398b0e950aa 100644 --- a/tsl/test/expected/dist_hypertable-11.out +++ b/tsl/test/expected/dist_hypertable-11.out @@ -4565,3 +4565,28 @@ SELECT * FROM create_distributed_hypertable('dist_hypertable_1', 'time', 'device migrate_data => TRUE); ERROR: cannot migrate data for distributed hypertable \set ON_ERROR_STOP 1 +-- 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 9416f284cbd..b98b455a5c3 100644 --- a/tsl/test/expected/dist_hypertable-12.out +++ b/tsl/test/expected/dist_hypertable-12.out @@ -4545,3 +4545,28 @@ SELECT * FROM create_distributed_hypertable('dist_hypertable_1', 'time', 'device migrate_data => TRUE); ERROR: cannot migrate data for distributed hypertable \set ON_ERROR_STOP 1 +-- 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 ec4ba765693..209582c29a5 100644 --- a/tsl/test/sql/dist_hypertable.sql.in +++ b/tsl/test/sql/dist_hypertable.sql.in @@ -1470,3 +1470,24 @@ SELECT * FROM create_distributed_hypertable('dist_hypertable_1', 'time', 'device SELECT * FROM create_distributed_hypertable('dist_hypertable_1', 'time', 'device', 3, migrate_data => TRUE); \set ON_ERROR_STOP 1 + +-- 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);