diff --git a/tsl/test/expected/chunk_utils_internal.out b/tsl/test/expected/chunk_utils_internal.out index df2c7c30a7d..78c4af96bef 100644 --- a/tsl/test/expected/chunk_utils_internal.out +++ b/tsl/test/expected/chunk_utils_internal.out @@ -867,9 +867,20 @@ ORDER BY table_name; CREATE TABLE measure( id integer PRIMARY KEY, mname varchar(10)); INSERT INTO measure VALUES( 1, 'temp'); INSERT INTO measure VALUES( 2, 'osmtemp'); +CREATE TABLE devices( id integer PRIMARY KEY, devname varchar(10) ); +INSERT INTO devices VALUES( 111, 'dev1'); +INSERT INTO devices VALUES( 222, 'osmdev'); +CREATE TABLE devicesref( id integer PRIMARY KEY, devname varchar(10) ); +INSERT INTO devicesref VALUES( 44, 'devref'); +INSERT INTO devicesref VALUES( 55, 'osmdevref'); CREATE TABLE hyper_constr ( id integer, time bigint, temp float, mid integer + ,dev integer + ,devref integer ,PRIMARY KEY (id, time) ,FOREIGN KEY ( mid) REFERENCES measure(id) + ,FOREIGN KEY ( dev ) REFERENCES devices(id) ON DELETE CASCADE + ,FOREIGN KEY ( devref ) REFERENCES devicesref(id) ON DELETE +RESTRICT ,CHECK ( temp > 10) ); SELECT create_hypertable('hyper_constr', 'time', chunk_time_interval => 10); @@ -878,14 +889,14 @@ SELECT create_hypertable('hyper_constr', 'time', chunk_time_interval => 10); (7,public,hyper_constr,t) (1 row) -INSERT INTO hyper_constr VALUES( 10, 200, 22, 1); +INSERT INTO hyper_constr VALUES( 10, 200, 22, 1, 111, 44); \c postgres_fdw_db :ROLE_4 -CREATE TABLE fdw_hyper_constr(id integer, time bigint, temp float, mid integer); -INSERT INTO fdw_hyper_constr VALUES( 10, 100, 33, 2); +CREATE TABLE fdw_hyper_constr(id integer, time bigint, temp float, mid integer, dev integer, devref integer); +INSERT INTO fdw_hyper_constr VALUES( 10, 100, 33, 2, 222, 55); \c :TEST_DBNAME :ROLE_4 -- this is a stand-in for the OSM table CREATE FOREIGN TABLE child_hyper_constr -( id integer NOT NULL, time bigint NOT NULL, temp float, mid integer) +( id integer NOT NULL, time bigint NOT NULL, temp float, mid integer, dev integer, devref integer) SERVER s3_server OPTIONS ( schema_name 'public', table_name 'fdw_hyper_constr'); --check constraints are automatically added for the foreign table SELECT _timescaledb_functions.attach_osm_table_chunk('hyper_constr', 'child_hyper_constr'); @@ -913,10 +924,10 @@ ORDER BY table_name; (2 rows) SELECT * FROM hyper_constr order by time; - id | time | temp | mid -----+------+------+----- - 10 | 100 | 33 | 2 - 10 | 200 | 22 | 1 + id | time | temp | mid | dev | devref +----+------+------+-----+-----+-------- + 10 | 100 | 33 | 2 | 222 | 55 + 10 | 200 | 22 | 1 | 111 | 44 (2 rows) --verify the check constraint exists on the OSM chunk @@ -934,11 +945,35 @@ BEGIN; DELETE FROM measure where id = 1; ERROR: update or delete on table "measure" violates foreign key constraint "hyper_constr_mid_fkey" on table "hyper_constr" ROLLBACK; ---this touches osm chunk. should succeed silently without deleteing any data +\set ON_ERROR_STOP 1 +--this touches osm chunk. should succeed silently without deleting any data BEGIN; DELETE FROM measure where id = 2; +SELECT * FROM measure order by id; + id | mname +----+------- + 1 | temp +(1 row) + +ROLLBACK; +BEGIN; +DELETE FROM devices where id = 222; +SELECT * FROM devices order by id; + id | devname +-----+--------- + 111 | dev1 +(1 row) + +ROLLBACK; +BEGIN; +DELETE FROM devicesref where id = 55; +SELECT * FROM devicesref order by id; + id | devname +----+--------- + 44 | devref +(1 row) + ROLLBACK; -\set ON_ERROR_STOP 1 --TEST retention policy is applied on OSM chunk by calling registered callback CREATE OR REPLACE FUNCTION dummy_now_smallint() RETURNS BIGINT LANGUAGE SQL IMMUTABLE as 'SELECT 500::bigint' ; SELECT set_integer_now_func('hyper_constr', 'dummy_now_smallint'); @@ -1191,7 +1226,7 @@ _timescaledb_catalog.chunk c, _timescaledb_catalog.chunk_constraint cc WHERE c.h AND c.id = cc.chunk_id; id | hypertable_id | schema_name | table_name | compressed_chunk_id | dropped | status | osm_chunk | chunk_id | dimension_slice_id | constraint_name | hypertable_constraint_name ----+---------------+-----------------------+--------------------+---------------------+---------+--------+-----------+----------+--------------------+-----------------------------+---------------------------- - 25 | 15 | _timescaledb_internal | _hyper_15_25_chunk | | f | 0 | f | 25 | | 25_3_test_multicon_time_key | test_multicon_time_key + 25 | 15 | _timescaledb_internal | _hyper_15_25_chunk | | f | 0 | f | 25 | | 25_5_test_multicon_time_key | test_multicon_time_key 25 | 15 | _timescaledb_internal | _hyper_15_25_chunk | | f | 0 | f | 25 | 22 | constraint_22 | (2 rows) diff --git a/tsl/test/sql/chunk_utils_internal.sql b/tsl/test/sql/chunk_utils_internal.sql index ccd594d8456..b846e2bfa88 100644 --- a/tsl/test/sql/chunk_utils_internal.sql +++ b/tsl/test/sql/chunk_utils_internal.sql @@ -475,23 +475,36 @@ CREATE TABLE measure( id integer PRIMARY KEY, mname varchar(10)); INSERT INTO measure VALUES( 1, 'temp'); INSERT INTO measure VALUES( 2, 'osmtemp'); +CREATE TABLE devices( id integer PRIMARY KEY, devname varchar(10) ); +INSERT INTO devices VALUES( 111, 'dev1'); +INSERT INTO devices VALUES( 222, 'osmdev'); + +CREATE TABLE devicesref( id integer PRIMARY KEY, devname varchar(10) ); +INSERT INTO devicesref VALUES( 44, 'devref'); +INSERT INTO devicesref VALUES( 55, 'osmdevref'); + CREATE TABLE hyper_constr ( id integer, time bigint, temp float, mid integer + ,dev integer + ,devref integer ,PRIMARY KEY (id, time) ,FOREIGN KEY ( mid) REFERENCES measure(id) + ,FOREIGN KEY ( dev ) REFERENCES devices(id) ON DELETE CASCADE + ,FOREIGN KEY ( devref ) REFERENCES devicesref(id) ON DELETE +RESTRICT ,CHECK ( temp > 10) ); SELECT create_hypertable('hyper_constr', 'time', chunk_time_interval => 10); -INSERT INTO hyper_constr VALUES( 10, 200, 22, 1); +INSERT INTO hyper_constr VALUES( 10, 200, 22, 1, 111, 44); \c postgres_fdw_db :ROLE_4 -CREATE TABLE fdw_hyper_constr(id integer, time bigint, temp float, mid integer); -INSERT INTO fdw_hyper_constr VALUES( 10, 100, 33, 2); +CREATE TABLE fdw_hyper_constr(id integer, time bigint, temp float, mid integer, dev integer, devref integer); +INSERT INTO fdw_hyper_constr VALUES( 10, 100, 33, 2, 222, 55); \c :TEST_DBNAME :ROLE_4 -- this is a stand-in for the OSM table CREATE FOREIGN TABLE child_hyper_constr -( id integer NOT NULL, time bigint NOT NULL, temp float, mid integer) +( id integer NOT NULL, time bigint NOT NULL, temp float, mid integer, dev integer, devref integer) SERVER s3_server OPTIONS ( schema_name 'public', table_name 'fdw_hyper_constr'); --check constraints are automatically added for the foreign table @@ -517,12 +530,23 @@ where conrelid = 'child_hyper_constr'::regclass ORDER BY 1; BEGIN; DELETE FROM measure where id = 1; ROLLBACK; +\set ON_ERROR_STOP 1 ---this touches osm chunk. should succeed silently without deleteing any data +--this touches osm chunk. should succeed silently without deleting any data BEGIN; DELETE FROM measure where id = 2; +SELECT * FROM measure order by id; +ROLLBACK; + +BEGIN; +DELETE FROM devices where id = 222; +SELECT * FROM devices order by id; +ROLLBACK; + +BEGIN; +DELETE FROM devicesref where id = 55; +SELECT * FROM devicesref order by id; ROLLBACK; -\set ON_ERROR_STOP 1 --TEST retention policy is applied on OSM chunk by calling registered callback CREATE OR REPLACE FUNCTION dummy_now_smallint() RETURNS BIGINT LANGUAGE SQL IMMUTABLE as 'SELECT 500::bigint' ;