Skip to content

Commit d9a85fd

Browse files
committed
Split chunk_utils_internal.sql tests for readability
1 parent 059ac06 commit d9a85fd

File tree

2 files changed

+23
-188
lines changed

2 files changed

+23
-188
lines changed

tsl/test/expected/chunk_utils_internal.out

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,13 @@ SELECT indexname, tablename FROM pg_indexes WHERE indexname = 'hyper_constr_mid_
11381138
(1 row)
11391139

11401140
DROP INDEX hyper_constr_mid_idx;
1141+
\i include/chunk_utils_internal_orderedappend.sql
1142+
-- This file and its contents are licensed under the Timescale License.
1143+
-- Please see the included NOTICE for copyright information and
1144+
-- LICENSE-TIMESCALE for a copy of the license.
1145+
-- TESTS for hypertable_osm_range_update_function
1146+
-- orderedappend (needs hypertable_osm_range_update to update catalog range)
1147+
-- (so that ordered append will work with OSM chunks)
11411148
-- TEST for hypertable_osm_range_update function
11421149
-- test range of dimension slice for osm chunk for different datatypes
11431150
CREATE TABLE osm_int2(time int2 NOT NULL);
@@ -1171,7 +1178,7 @@ SELECT table_name FROM create_hypertable('osm_date','time');
11711178
(1 row)
11721179

11731180
SELECT table_name FROM create_hypertable('osm_ts','time');
1174-
WARNING: column type "timestamp without time zone" used for "time" does not follow best practices
1181+
psql:include/chunk_utils_internal_orderedappend.sql:21: WARNING: column type "timestamp without time zone" used for "time" does not follow best practices
11751182
table_name
11761183
------------
11771184
osm_ts
@@ -1252,9 +1259,9 @@ WHERE c.hypertable_id = :htid AND cc.chunk_id = c.id AND ds.id = cc.dimension_sl
12521259
\set ON_ERROR_STOP 0
12531260
-- both range_start and range_end must be NULL, or non-NULL
12541261
SELECT _timescaledb_functions.hypertable_osm_range_update('test_multicon', NULL, '2020-01-04 01:00'::timestamptz);
1255-
ERROR: range_start and range_end parameters must be both NULL or both non-NULL
1262+
psql:include/chunk_utils_internal_orderedappend.sql:58: ERROR: range_start and range_end parameters must be both NULL or both non-NULL
12561263
SELECT _timescaledb_functions.hypertable_osm_range_update('test_multicon', NULL, NULL);
1257-
ERROR: could not determine polymorphic type because input has type unknown
1264+
psql:include/chunk_utils_internal_orderedappend.sql:59: ERROR: could not determine polymorphic type because input has type unknown
12581265
SELECT _timescaledb_functions.hypertable_osm_range_update('test_multicon');
12591266
hypertable_osm_range_update
12601267
-----------------------------
@@ -1306,7 +1313,7 @@ WHERE c.hypertable_id = :htid AND cc.chunk_id = c.id AND ds.id = cc.dimension_sl
13061313
-- attempt to update overlapping range, should fail
13071314
\set ON_ERROR_STOP 0
13081315
SELECT _timescaledb_functions.hypertable_osm_range_update('test_chunkapp', '2020-01-02 01:00'::timestamptz, '2020-01-04 01:00');
1309-
ERROR: attempting to set overlapping range for tiered chunk of public.test_chunkapp
1316+
psql:include/chunk_utils_internal_orderedappend.sql:86: ERROR: attempting to set overlapping range for tiered chunk of public.test_chunkapp
13101317
\set ON_ERROR_STOP 1
13111318
-- update actual range of OSM chunk, should work
13121319
SELECT _timescaledb_functions.hypertable_osm_range_update('test_chunkapp', '2020-01-03 00:00'::timestamptz, '2020-01-04 00:00');
@@ -1354,7 +1361,7 @@ SELECT ts_setup_osm_hook();
13541361

13551362
\set ON_ERROR_STOP 0
13561363
INSERT INTO test_chunkapp VALUES ('2020-01-03 02:00'::timestamptz, 3);
1357-
ERROR: Cannot insert into tiered chunk range of public.test_chunkapp - attempt to create new chunk with range [Fri Jan 03 00:00:00 2020 PST Sat Jan 04 00:00:00 2020 PST] failed
1364+
psql:include/chunk_utils_internal_orderedappend.sql:100: ERROR: Cannot insert into tiered chunk range of public.test_chunkapp - attempt to create new chunk with range [Fri Jan 03 00:00:00 2020 PST Sat Jan 04 00:00:00 2020 PST] failed
13581365
\set ON_ERROR_STOP 1
13591366
SELECT ts_undo_osm_hook();
13601367
ts_undo_osm_hook
@@ -1468,9 +1475,9 @@ SELECT * FROM test_chunkapp WHERE time < '2023-01-01' ORDER BY 1;
14681475
\set ON_ERROR_STOP 0
14691476
-- test adding constraint directly on OSM chunk is blocked
14701477
ALTER TABLE test_chunkapp_fdw_child ADD CHECK (a > 0); -- non-dimensional
1471-
ERROR: operation not supported on OSM chunk tables
1478+
psql:include/chunk_utils_internal_orderedappend.sql:127: ERROR: operation not supported on OSM chunk tables
14721479
ALTER TABLE test_chunkapp_fdw_child ADD CHECK (time > '1600-01-01'::timestamptz); -- dimensional
1473-
ERROR: operation not supported on OSM chunk tables
1480+
psql:include/chunk_utils_internal_orderedappend.sql:128: ERROR: operation not supported on OSM chunk tables
14741481
-- but on hypertable, it is allowed
14751482
ALTER TABLE test_chunkapp ADD CHECK (a > 0);
14761483
\d+ test_chunkapp_fdw_child
@@ -1496,9 +1503,9 @@ SELECT create_hypertable('test2', 'time');
14961503

14971504
INSERT INTO test2 VALUES ('2020-01-01'::timestamptz, 1);
14981505
ALTER TABLE test2 SET (timescaledb.compress);
1499-
WARNING: there was some uncertainty picking the default segment by for the hypertable: You do not have any indexes on columns that can be used for segment_by and thus we are not using segment_by for compression. Please make sure you are not missing any indexes
1500-
NOTICE: default segment by for hypertable "test2" is set to ""
1501-
NOTICE: default order by for hypertable "test2" is set to ""time" DESC"
1506+
psql:include/chunk_utils_internal_orderedappend.sql:138: WARNING: there was some uncertainty picking the default segment by for the hypertable: You do not have any indexes on columns that can be used for segment_by and thus we are not using segment_by for compression. Please make sure you are not missing any indexes
1507+
psql:include/chunk_utils_internal_orderedappend.sql:138: NOTICE: default segment by for hypertable "test2" is set to ""
1508+
psql:include/chunk_utils_internal_orderedappend.sql:138: NOTICE: default order by for hypertable "test2" is set to ""time" DESC"
15021509
SELECT compress_chunk(show_chunks('test2'));
15031510
compress_chunk
15041511
------------------------------------------
@@ -1511,13 +1518,13 @@ FROM _timescaledb_catalog.hypertable ht, _timescaledb_catalog.hypertable cht
15111518
WHERE ht.table_name = 'test2' and cht.id = ht.compressed_hypertable_id \gset
15121519
\set ON_ERROR_STOP 0
15131520
SELECT _timescaledb_functions.hypertable_osm_range_update(:'COMPRESSION_TBLNM'::regclass, '2020-01-01'::timestamptz);
1514-
ERROR: could not find time dimension for hypertable _timescaledb_internal._compressed_hypertable_18
1521+
psql:include/chunk_utils_internal_orderedappend.sql:145: ERROR: could not find time dimension for hypertable _timescaledb_internal._compressed_hypertable_18
15151522
\set ON_ERROR_STOP 1
15161523
-- test wrong/incompatible data types with hypertable time dimension
15171524
-- update range of int2 with int4
15181525
\set ON_ERROR_STOP 0
15191526
SELECT _timescaledb_functions.hypertable_osm_range_update('osm_int2', range_start => 65540::int4, range_end => 100000::int4);
1520-
ERROR: invalid time argument type "integer"
1527+
psql:include/chunk_utils_internal_orderedappend.sql:151: ERROR: invalid time argument type "integer"
15211528
-- update range of int8 with int4
15221529
SELECT _timescaledb_functions.hypertable_osm_range_update('osm_int8', 120, 150);
15231530
hypertable_osm_range_update
@@ -1534,7 +1541,7 @@ SELECT _timescaledb_functions.hypertable_osm_range_update('osm_tstz', '2020-01-0
15341541

15351542
-- udpate range of timestamp with bigint
15361543
SELECT _timescaledb_functions.hypertable_osm_range_update('osm_tstz', 9223372036854771806, 9223372036854775406);
1537-
ERROR: invalid time argument type "bigint"
1544+
psql:include/chunk_utils_internal_orderedappend.sql:157: ERROR: invalid time argument type "bigint"
15381545
\set ON_ERROR_STOP 1
15391546
-- test dimension slice tuple visibility
15401547
\c :TEST_DBNAME :ROLE_SUPERUSER
@@ -1557,9 +1564,9 @@ ROLLBACK;
15571564
-- should show 0 10 as range
15581565
\set ON_ERROR_STOP 0
15591566
INSERT INTO osm_slice_update VALUES (1);
1560-
ERROR: Cannot insert into tiered chunk range of public.osm_slice_update - attempt to create new chunk with range [0 10] failed
1567+
psql:include/chunk_utils_internal_orderedappend.sql:178: ERROR: Cannot insert into tiered chunk range of public.osm_slice_update - attempt to create new chunk with range [0 10] failed
15611568
INSERT INTO osm_slice_update VALUES (1);
1562-
ERROR: Cannot insert into tiered chunk range of public.osm_slice_update - attempt to create new chunk with range [0 10] failed
1569+
psql:include/chunk_utils_internal_orderedappend.sql:179: ERROR: Cannot insert into tiered chunk range of public.osm_slice_update - attempt to create new chunk with range [0 10] failed
15631570
\set ON_ERROR_STOP 1
15641571
-- clean up databases created
15651572
\c :TEST_DBNAME :ROLE_SUPERUSER

tsl/test/sql/chunk_utils_internal.sql

Lines changed: 1 addition & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -649,179 +649,7 @@ CREATE INDEX hyper_constr_mid_idx ON hyper_constr(mid, time) WITH (timescaledb.t
649649
SELECT indexname, tablename FROM pg_indexes WHERE indexname = 'hyper_constr_mid_idx';
650650
DROP INDEX hyper_constr_mid_idx;
651651

652-
-- TEST for hypertable_osm_range_update function
653-
-- test range of dimension slice for osm chunk for different datatypes
654-
CREATE TABLE osm_int2(time int2 NOT NULL);
655-
CREATE TABLE osm_int4(time int4 NOT NULL);
656-
CREATE TABLE osm_int8(time int8 NOT NULL);
657-
CREATE TABLE osm_date(time date NOT NULL);
658-
CREATE TABLE osm_ts(time timestamp NOT NULL);
659-
CREATE TABLE osm_tstz(time timestamptz NOT NULL);
660-
661-
SELECT table_name FROM create_hypertable('osm_int2','time',chunk_time_interval:=1000);
662-
SELECT table_name FROM create_hypertable('osm_int4','time',chunk_time_interval:=1000);
663-
SELECT table_name FROM create_hypertable('osm_int8','time',chunk_time_interval:=1000);
664-
SELECT table_name FROM create_hypertable('osm_date','time');
665-
SELECT table_name FROM create_hypertable('osm_ts','time');
666-
SELECT table_name FROM create_hypertable('osm_tstz','time');
667-
668-
CREATE FOREIGN TABLE osm_int2_fdw_child(time int2 NOT NULL) SERVER s3_server;
669-
CREATE FOREIGN TABLE osm_int4_fdw_child(time int4 NOT NULL) SERVER s3_server;
670-
CREATE FOREIGN TABLE osm_int8_fdw_child(time int8 NOT NULL) SERVER s3_server;
671-
CREATE FOREIGN TABLE osm_date_fdw_child(time date NOT NULL) SERVER s3_server;
672-
CREATE FOREIGN TABLE osm_ts_fdw_child(time timestamp NOT NULL) SERVER s3_server;
673-
CREATE FOREIGN TABLE osm_tstz_fdw_child(time timestamptz NOT NULL) SERVER s3_server;
674-
675-
SELECT dt, _timescaledb_functions.attach_osm_table_chunk('osm_' || dt, 'osm_' || dt || '_fdw_child') FROM unnest('{int2,int4,int8,date,ts,tstz}'::text[]) u(dt);
676-
677-
SELECT ht.table_name, ds.*
678-
FROM _timescaledb_catalog.dimension_slice ds
679-
INNER JOIN _timescaledb_catalog.dimension d ON d.id=ds.dimension_id
680-
INNER JOIN _timescaledb_catalog.hypertable ht on ht.id=d.hypertable_id
681-
WHERE ht.table_name LIKE 'osm%'
682-
ORDER BY 2,3;
683-
-- test that correct slice is found and updated for table with multiple chunk constraints
684-
CREATE TABLE test_multicon(time timestamptz not null unique, a int);
685-
SELECT hypertable_id as htid FROM create_hypertable('test_multicon', 'time', chunk_time_interval => interval '1 day') \gset
686-
insert into test_multicon values ('2020-01-02 01:00'::timestamptz, 1);
687-
SELECT c.id, c.hypertable_id, c.schema_name, c.table_name, c.compressed_chunk_id, c.dropped, c.status, c.osm_chunk,
688-
cc.chunk_id, cc.dimension_slice_id, cc.constraint_name, cc.hypertable_constraint_name FROM
689-
_timescaledb_catalog.chunk c, _timescaledb_catalog.chunk_constraint cc WHERE c.hypertable_id = :htid
690-
AND c.id = cc.chunk_id;
691-
\c :TEST_DBNAME :ROLE_SUPERUSER ;
692-
UPDATE _timescaledb_catalog.chunk SET osm_chunk = true WHERE hypertable_id = :htid;
693-
\c :TEST_DBNAME :ROLE_4;
694-
SELECT _timescaledb_functions.hypertable_osm_range_update('test_multicon', '2020-01-02 01:00'::timestamptz, '2020-01-04 01:00');
695-
-- view udpated range
696-
SELECT cc.chunk_id, c.table_name, c.status, c.osm_chunk, cc.dimension_slice_id, ds.range_start, ds.range_end
697-
FROM _timescaledb_catalog.chunk c, _timescaledb_catalog.chunk_constraint cc, _timescaledb_catalog.dimension_slice ds
698-
WHERE c.hypertable_id = :htid AND cc.chunk_id = c.id AND ds.id = cc.dimension_slice_id;
699-
-- check that range was reset to default - infinity
700-
\set ON_ERROR_STOP 0
701-
-- both range_start and range_end must be NULL, or non-NULL
702-
SELECT _timescaledb_functions.hypertable_osm_range_update('test_multicon', NULL, '2020-01-04 01:00'::timestamptz);
703-
SELECT _timescaledb_functions.hypertable_osm_range_update('test_multicon', NULL, NULL);
704-
SELECT _timescaledb_functions.hypertable_osm_range_update('test_multicon');
705-
\set ON_ERROR_STOP 1
706-
SELECT _timescaledb_functions.hypertable_osm_range_update('test_multicon', NULL::timestamptz, NULL);
707-
SELECT cc.chunk_id, c.table_name, c.status, c.osm_chunk, cc.dimension_slice_id, ds.range_start, ds.range_end
708-
FROM _timescaledb_catalog.chunk c, _timescaledb_catalog.chunk_constraint cc, _timescaledb_catalog.dimension_slice ds
709-
WHERE c.hypertable_id = :htid AND cc.chunk_id = c.id AND ds.id = cc.dimension_slice_id ORDER BY cc.chunk_id;
710-
711-
-- TEST for orderedappend that depends on hypertable_osm_range_update functionality
712-
-- test further with ordered append
713-
\c postgres_fdw_db :ROLE_4;
714-
CREATE TABLE test_chunkapp_fdw (time timestamptz NOT NULL, a int);
715-
INSERT INTO test_chunkapp_fdw (time, a) VALUES ('2020-01-03 02:00'::timestamptz, 3);
716-
717-
\c :TEST_DBNAME :ROLE_4
718-
CREATE TABLE test_chunkapp(time timestamptz NOT NULL, a int);
719-
SELECT hypertable_id as htid FROM create_hypertable('test_chunkapp', 'time', chunk_time_interval => interval '1day') \gset
720-
INSERT INTO test_chunkapp (time, a) VALUES ('2020-01-01 01:00'::timestamptz, 1), ('2020-01-02 01:00'::timestamptz, 2);
721-
722-
CREATE FOREIGN TABLE test_chunkapp_fdw_child(time timestamptz NOT NULL, a int) SERVER s3_server OPTIONS (schema_name 'public', table_name 'test_chunkapp_fdw');;
723-
SELECT _timescaledb_functions.attach_osm_table_chunk('test_chunkapp','test_chunkapp_fdw_child');
724-
-- view range before update
725-
SELECT cc.chunk_id, c.table_name, c.status, c.osm_chunk, cc.dimension_slice_id, ds.range_start, ds.range_end
726-
FROM _timescaledb_catalog.chunk c, _timescaledb_catalog.chunk_constraint cc, _timescaledb_catalog.dimension_slice ds
727-
WHERE c.hypertable_id = :htid AND cc.chunk_id = c.id AND ds.id = cc.dimension_slice_id ORDER BY cc.chunk_id;
728-
-- attempt to update overlapping range, should fail
729-
\set ON_ERROR_STOP 0
730-
SELECT _timescaledb_functions.hypertable_osm_range_update('test_chunkapp', '2020-01-02 01:00'::timestamptz, '2020-01-04 01:00');
731-
\set ON_ERROR_STOP 1
732-
-- update actual range of OSM chunk, should work
733-
SELECT _timescaledb_functions.hypertable_osm_range_update('test_chunkapp', '2020-01-03 00:00'::timestamptz, '2020-01-04 00:00');
734-
-- view udpated range
735-
SELECT cc.chunk_id, c.table_name, c.status, c.osm_chunk, cc.dimension_slice_id, ds.range_start, ds.range_end
736-
FROM _timescaledb_catalog.chunk c, _timescaledb_catalog.chunk_constraint cc, _timescaledb_catalog.dimension_slice ds
737-
WHERE c.hypertable_id = :htid AND cc.chunk_id = c.id AND ds.id = cc.dimension_slice_id ORDER BY cc.chunk_id;
738-
-- ordered append should be possible as ranges do not overlap
739-
EXPLAIN SELECT * FROM test_chunkapp ORDER BY 1;
740-
SELECT * FROM test_chunkapp ORDER BY 1;
741-
-- but, insert should not be possible
742-
SELECT ts_setup_osm_hook();
743-
\set ON_ERROR_STOP 0
744-
INSERT INTO test_chunkapp VALUES ('2020-01-03 02:00'::timestamptz, 3);
745-
\set ON_ERROR_STOP 1
746-
SELECT ts_undo_osm_hook();
747-
-- reset range to infinity
748-
SELECT _timescaledb_functions.hypertable_osm_range_update('test_chunkapp',empty:=false);
749-
-- ordered append not possible because range is invalid and empty was not specified
750-
EXPLAIN SELECT * FROM test_chunkapp ORDER BY 1;
751-
SELECT * FROM test_chunkapp ORDER BY 1;
752-
SELECT cc.chunk_id, c.table_name, c.status, c.osm_chunk, cc.dimension_slice_id, ds.range_start, ds.range_end
753-
FROM _timescaledb_catalog.chunk c, _timescaledb_catalog.chunk_constraint cc, _timescaledb_catalog.dimension_slice ds
754-
WHERE c.hypertable_id = :htid AND cc.chunk_id = c.id AND ds.id = cc.dimension_slice_id ORDER BY cc.chunk_id;
755-
-- but also, OSM chunk should be included in the scan, since range is invalid and chunk is not empty
756-
EXPLAIN SELECT * FROM test_chunkapp WHERE time < '2023-01-01' ORDER BY 1;
757-
SELECT * FROM test_chunkapp WHERE time < '2023-01-01' ORDER BY 1;
758-
-- now set empty to true, should ordered append
759-
\c postgres_fdw_db :ROLE_4;
760-
DELETE FROM test_chunkapp_fdw;
761-
\c :TEST_DBNAME :ROLE_4;
762-
SELECT _timescaledb_functions.hypertable_osm_range_update('test_chunkapp', NULL::timestamptz, NULL, empty => true);
763-
EXPLAIN SELECT * FROM test_chunkapp ORDER BY 1;
764-
SELECT * FROM test_chunkapp ORDER BY 1;
765-
-- should exclude the OSM chunk this time since it is empty
766-
EXPLAIN SELECT * FROM test_chunkapp WHERE time < '2023-01-01' ORDER BY 1;
767-
SELECT * FROM test_chunkapp WHERE time < '2023-01-01' ORDER BY 1;
768-
769-
\set ON_ERROR_STOP 0
770-
-- test adding constraint directly on OSM chunk is blocked
771-
ALTER TABLE test_chunkapp_fdw_child ADD CHECK (a > 0); -- non-dimensional
772-
ALTER TABLE test_chunkapp_fdw_child ADD CHECK (time > '1600-01-01'::timestamptz); -- dimensional
773-
-- but on hypertable, it is allowed
774-
ALTER TABLE test_chunkapp ADD CHECK (a > 0);
775-
\d+ test_chunkapp_fdw_child
776-
\set ON_ERROR_STOP 1
777-
778-
-- test error is triggered when time dimension not found
779-
CREATE TABLE test2(time timestamptz not null, a int);
780-
SELECT create_hypertable('test2', 'time');
781-
INSERT INTO test2 VALUES ('2020-01-01'::timestamptz, 1);
782-
ALTER TABLE test2 SET (timescaledb.compress);
783-
SELECT compress_chunk(show_chunks('test2'));
784-
-- find internal compression table, call API function on it
785-
SELECT format('%I.%I', cht.schema_name, cht.table_name) AS "COMPRESSION_TBLNM"
786-
FROM _timescaledb_catalog.hypertable ht, _timescaledb_catalog.hypertable cht
787-
WHERE ht.table_name = 'test2' and cht.id = ht.compressed_hypertable_id \gset
788-
\set ON_ERROR_STOP 0
789-
SELECT _timescaledb_functions.hypertable_osm_range_update(:'COMPRESSION_TBLNM'::regclass, '2020-01-01'::timestamptz);
790-
\set ON_ERROR_STOP 1
791-
792-
-- test wrong/incompatible data types with hypertable time dimension
793-
-- update range of int2 with int4
794-
\set ON_ERROR_STOP 0
795-
SELECT _timescaledb_functions.hypertable_osm_range_update('osm_int2', range_start => 65540::int4, range_end => 100000::int4);
796-
-- update range of int8 with int4
797-
SELECT _timescaledb_functions.hypertable_osm_range_update('osm_int8', 120, 150);
798-
-- update range of timestamptz with date
799-
SELECT _timescaledb_functions.hypertable_osm_range_update('osm_tstz', '2020-01-01'::date, '2020-01-03'::date);
800-
-- udpate range of timestamp with bigint
801-
SELECT _timescaledb_functions.hypertable_osm_range_update('osm_tstz', 9223372036854771806, 9223372036854775406);
802-
\set ON_ERROR_STOP 1
803-
804-
-- test dimension slice tuple visibility
805-
\c :TEST_DBNAME :ROLE_SUPERUSER
806-
CREATE TABLE osm_slice_update(time int not null);
807-
SELECT hypertable_id AS ht_id FROM create_hypertable('osm_slice_update', 'time', chunk_time_interval => 10) \gset
808-
809-
INSERT INTO osm_slice_update VALUES (1);
810-
UPDATE _timescaledb_catalog.hypertable SET status = 3 WHERE id = :ht_id;
811-
UPDATE _timescaledb_catalog.chunk SET osm_chunk = true WHERE hypertable_id = :ht_id;
812-
813-
\c
814-
BEGIN;
815-
SELECT _timescaledb_functions.hypertable_osm_range_update('osm_slice_update',40,50);
816-
ROLLBACK;
817-
818-
\c
819-
-- new session should not be affected by previous rolled back transaction
820-
-- should show 0 10 as range
821-
\set ON_ERROR_STOP 0
822-
INSERT INTO osm_slice_update VALUES (1);
823-
INSERT INTO osm_slice_update VALUES (1);
824-
\set ON_ERROR_STOP 1
652+
\i include/chunk_utils_internal_orderedappend.sql
825653

826654
-- clean up databases created
827655
\c :TEST_DBNAME :ROLE_SUPERUSER

0 commit comments

Comments
 (0)