mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-17 02:53:51 +08:00
It is not an error for range_end of a new chunk to be equal to range_start of an existing chunk because range_end is exclusive. Fix logic not to throw an error in that case.
82 lines
3.6 KiB
SQL
82 lines
3.6 KiB
SQL
\ir include/create_single_db.sql
|
|
|
|
CREATE TABLE chunk_test(
|
|
time BIGINT,
|
|
metric INTEGER,
|
|
device_id TEXT
|
|
);
|
|
|
|
-- Test chunk closing/creation
|
|
SELECT * FROM create_hypertable('chunk_test', 'time', 'device_id', 2, chunk_time_interval => 10);
|
|
SELECT * FROM _timescaledb_catalog.hypertable;
|
|
|
|
INSERT INTO chunk_test VALUES (1, 1, 'dev1'),
|
|
(2, 2, 'dev2'),
|
|
(45, 2, 'dev2'),
|
|
(46, 2, 'dev2');
|
|
|
|
SELECT * FROM set_chunk_time_interval('chunk_test', 40::bigint);
|
|
|
|
INSERT INTO chunk_test VALUES(23, 3, 'dev3');
|
|
|
|
SELECT * FROM chunk_test order by time, metric, device_id;
|
|
SELECT * FROM _timescaledb_catalog.chunk;
|
|
SELECT * FROM _timescaledb_catalog.hypertable;
|
|
|
|
SELECT * FROM ONLY chunk_test;
|
|
SELECT * FROM _timescaledb_catalog.chunk c
|
|
LEFT JOIN _timescaledb_catalog.chunk_constraint cc ON (c.id = cc.chunk_id)
|
|
LEFT JOIN _timescaledb_catalog.dimension_slice ds ON (ds.id = cc.dimension_slice_id)
|
|
LEFT JOIN _timescaledb_catalog.dimension d ON (d.id = ds.dimension_id)
|
|
LEFT JOIN _timescaledb_catalog.hypertable h ON (d.hypertable_id = h.id)
|
|
WHERE h.schema_name = 'public' AND h.table_name = 'chunk_test'
|
|
ORDER BY c.id, d.id;
|
|
|
|
|
|
-- Test chunk aligning between partitions
|
|
CREATE TABLE chunk_align_test(
|
|
time BIGINT,
|
|
metric INTEGER,
|
|
device_id TEXT
|
|
);
|
|
SELECT * FROM create_hypertable('chunk_align_test', 'time', 'device_id', 2, chunk_time_interval => 10);
|
|
|
|
INSERT INTO chunk_align_test VALUES (1, 1, 'dev1'); -- this should create a 10 wide chunk
|
|
|
|
SELECT * FROM _timescaledb_catalog.chunk c
|
|
LEFT JOIN _timescaledb_catalog.chunk_constraint cc ON (c.id = cc.chunk_id)
|
|
LEFT JOIN _timescaledb_catalog.dimension_slice ds ON (ds.id = cc.dimension_slice_id)
|
|
LEFT JOIN _timescaledb_catalog.dimension d ON (d.id = ds.dimension_id)
|
|
LEFT JOIN _timescaledb_catalog.hypertable h ON (d.hypertable_id = h.id)
|
|
WHERE h.schema_name = 'public' AND h.table_name = 'chunk_align_test'
|
|
AND d.column_name = 'time'
|
|
ORDER BY c.id, d.id;
|
|
|
|
SELECT * FROM set_chunk_time_interval('chunk_align_test', 40::bigint);
|
|
INSERT INTO chunk_align_test VALUES (5, 1, 'dev2'); -- this should still create a 10 wide chunk
|
|
INSERT INTO chunk_align_test VALUES (45, 1, 'dev2'); -- this should create a 40 wide chunk
|
|
|
|
SELECT * FROM _timescaledb_catalog.chunk c
|
|
LEFT JOIN _timescaledb_catalog.chunk_constraint cc ON (c.id = cc.chunk_id)
|
|
LEFT JOIN _timescaledb_catalog.dimension_slice ds ON (ds.id = cc.dimension_slice_id)
|
|
LEFT JOIN _timescaledb_catalog.dimension d ON (d.id = ds.dimension_id)
|
|
LEFT JOIN _timescaledb_catalog.hypertable h ON (d.hypertable_id = h.id)
|
|
WHERE h.schema_name = 'public' AND h.table_name = 'chunk_align_test'
|
|
AND d.column_name = 'time'
|
|
ORDER BY c.id, d.id;
|
|
|
|
--check the cut-to-size with aligned dimensions code
|
|
INSERT INTO chunk_align_test VALUES (35, 1, 'dev1');
|
|
INSERT INTO chunk_align_test VALUES (35, 1, 'dev2');
|
|
INSERT INTO chunk_align_test VALUES (81, 1, 'dev1');
|
|
INSERT INTO chunk_align_test VALUES (81, 1, 'dev2');
|
|
SELECT * FROM _timescaledb_catalog.chunk c
|
|
LEFT JOIN _timescaledb_catalog.chunk_constraint cc ON (c.id = cc.chunk_id)
|
|
LEFT JOIN _timescaledb_catalog.dimension_slice ds ON (ds.id = cc.dimension_slice_id)
|
|
LEFT JOIN _timescaledb_catalog.dimension d ON (d.id = ds.dimension_id)
|
|
LEFT JOIN _timescaledb_catalog.hypertable h ON (d.hypertable_id = h.id)
|
|
WHERE h.schema_name = 'public' AND h.table_name = 'chunk_align_test'
|
|
AND d.column_name = 'time'
|
|
ORDER BY c.id, d.id;
|
|
|