timescaledb/test/expected/create_chunks.out

131 lines
10 KiB
Plaintext

\ir include/create_single_db.sql
SET client_min_messages = WARNING;
DROP DATABASE IF EXISTS single;
SET client_min_messages = NOTICE;
CREATE DATABASE single;
\c single
CREATE EXTENSION IF NOT EXISTS timescaledb;
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);
create_hypertable
-------------------
(1 row)
SELECT * FROM _timescaledb_catalog.hypertable;
id | schema_name | table_name | associated_schema_name | associated_table_prefix | time_column_name | time_column_type | chunk_time_interval
----+-------------+------------+------------------------+-------------------------+------------------+------------------+---------------------
1 | public | chunk_test | _timescaledb_internal | _hyper_1 | time | bigint | 10
(1 row)
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);
set_chunk_time_interval
-------------------------
(1 row)
INSERT INTO chunk_test VALUES(23, 3, 'dev3');
SELECT * FROM chunk_test order by time, metric, device_id;
time | metric | device_id
------+--------+-----------
1 | 1 | dev1
2 | 2 | dev2
23 | 3 | dev3
45 | 2 | dev2
46 | 2 | dev2
(5 rows)
SELECT * FROM _timescaledb_catalog.chunk;
id | partition_id | start_time | end_time | schema_name | table_name
----+--------------+------------+----------+-----------------------+------------------
1 | 1 | 0 | 9 | _timescaledb_internal | _hyper_1_1_chunk
2 | 2 | 0 | 9 | _timescaledb_internal | _hyper_1_2_chunk
3 | 2 | 40 | 49 | _timescaledb_internal | _hyper_1_3_chunk
4 | 1 | 10 | 39 | _timescaledb_internal | _hyper_1_4_chunk
(4 rows)
SELECT * FROM _timescaledb_catalog.hypertable;
id | schema_name | table_name | associated_schema_name | associated_table_prefix | time_column_name | time_column_type | chunk_time_interval
----+-------------+------------+------------------------+-------------------------+------------------+------------------+---------------------
1 | public | chunk_test | _timescaledb_internal | _hyper_1 | time | bigint | 40
(1 row)
SELECT * FROM ONLY chunk_test;
time | metric | device_id
------+--------+-----------
(0 rows)
SELECT * FROM _timescaledb_catalog.chunk c
LEFT JOIN _timescaledb_catalog.partition p ON (p.id = c.partition_id)
LEFT JOIN _timescaledb_catalog.partition_epoch pe ON (pe.id = p.epoch_id)
LEFT JOIN _timescaledb_catalog.hypertable h ON (pe.hypertable_id = h.id)
WHERE h.schema_name = 'public' AND h.table_name = 'chunk_test'
ORDER BY c.id;
id | partition_id | start_time | end_time | schema_name | table_name | id | epoch_id | keyspace_start | keyspace_end | tablespace | id | hypertable_id | start_time | end_time | num_partitions | partitioning_func_schema | partitioning_func | partitioning_mod | partitioning_column | id | schema_name | table_name | associated_schema_name | associated_table_prefix | time_column_name | time_column_type | chunk_time_interval
----+--------------+------------+----------+-----------------------+------------------+----+----------+----------------+--------------+------------+----+---------------+------------+----------+----------------+--------------------------+-----------------------+------------------+---------------------+----+-------------+------------+------------------------+-------------------------+------------------+------------------+---------------------
1 | 1 | 0 | 9 | _timescaledb_internal | _hyper_1_1_chunk | 1 | 1 | 0 | 16383 | | 1 | 1 | | | 2 | _timescaledb_internal | get_partition_for_key | 32768 | device_id | 1 | public | chunk_test | _timescaledb_internal | _hyper_1 | time | bigint | 40
2 | 2 | 0 | 9 | _timescaledb_internal | _hyper_1_2_chunk | 2 | 1 | 16384 | 32767 | | 1 | 1 | | | 2 | _timescaledb_internal | get_partition_for_key | 32768 | device_id | 1 | public | chunk_test | _timescaledb_internal | _hyper_1 | time | bigint | 40
3 | 2 | 40 | 49 | _timescaledb_internal | _hyper_1_3_chunk | 2 | 1 | 16384 | 32767 | | 1 | 1 | | | 2 | _timescaledb_internal | get_partition_for_key | 32768 | device_id | 1 | public | chunk_test | _timescaledb_internal | _hyper_1 | time | bigint | 40
4 | 1 | 10 | 39 | _timescaledb_internal | _hyper_1_4_chunk | 1 | 1 | 0 | 16383 | | 1 | 1 | | | 2 | _timescaledb_internal | get_partition_for_key | 32768 | device_id | 1 | public | chunk_test | _timescaledb_internal | _hyper_1 | time | bigint | 40
(4 rows)
-- 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);
create_hypertable
-------------------
(1 row)
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;
id | hypertable_id | schema_name | table_name | chunk_id | dimension_slice_id | id | dimension_id | range_start | range_end | id | hypertable_id | column_name | column_type | aligned | num_slices | partitioning_func_schema | partitioning_func | interval_length | id | schema_name | table_name | associated_schema_name | associated_table_prefix | num_dimensions
----+---------------+-----------------------+------------------+----------+--------------------+----+--------------+-------------+-----------+----+---------------+-------------+-------------+---------+------------+--------------------------+-------------------+-----------------+----+-------------+------------------+------------------------+-------------------------+----------------
5 | 2 | _timescaledb_internal | _hyper_2_5_chunk | 5 | 9 | 9 | 3 | 0 | 10 | 3 | 2 | time | bigint | t | | | | 10 | 2 | public | chunk_align_test | _timescaledb_internal | _hyper_2 | 2
(1 row)
SELECT * FROM set_chunk_time_interval('chunk_align_test', 40::bigint);
set_chunk_time_interval
-------------------------
(1 row)
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;
id | hypertable_id | schema_name | table_name | chunk_id | dimension_slice_id | id | dimension_id | range_start | range_end | id | hypertable_id | column_name | column_type | aligned | num_slices | partitioning_func_schema | partitioning_func | interval_length | id | schema_name | table_name | associated_schema_name | associated_table_prefix | num_dimensions
----+---------------+-----------------------+------------------+----------+--------------------+----+--------------+-------------+-----------+----+---------------+-------------+-------------+---------+------------+--------------------------+-------------------+-----------------+----+-------------+------------------+------------------------+-------------------------+----------------
5 | 2 | _timescaledb_internal | _hyper_2_5_chunk | 5 | 9 | 9 | 3 | 0 | 10 | 3 | 2 | time | bigint | t | | | | 40 | 2 | public | chunk_align_test | _timescaledb_internal | _hyper_2 | 2
6 | 2 | _timescaledb_internal | _hyper_2_6_chunk | 6 | 9 | 9 | 3 | 0 | 10 | 3 | 2 | time | bigint | t | | | | 40 | 2 | public | chunk_align_test | _timescaledb_internal | _hyper_2 | 2
7 | 2 | _timescaledb_internal | _hyper_2_7_chunk | 7 | 13 | 13 | 3 | 40 | 80 | 3 | 2 | time | bigint | t | | | | 40 | 2 | public | chunk_align_test | _timescaledb_internal | _hyper_2 | 2
(3 rows)