timescaledb/test/expected/size_utils.out

204 lines
19 KiB
Plaintext

\ir include/insert_two_partitions.sql
\c single
CREATE TABLE PUBLIC."two_Partitions" (
"timeCustom" BIGINT NOT NULL,
device_id TEXT NOT NULL,
series_0 DOUBLE PRECISION NULL,
series_1 DOUBLE PRECISION NULL,
series_2 DOUBLE PRECISION NULL,
series_bool BOOLEAN NULL
);
CREATE INDEX ON PUBLIC."two_Partitions" (device_id, "timeCustom" DESC NULLS LAST) WHERE device_id IS NOT NULL;
CREATE INDEX ON PUBLIC."two_Partitions" ("timeCustom" DESC NULLS LAST, series_0) WHERE series_0 IS NOT NULL;
CREATE INDEX ON PUBLIC."two_Partitions" ("timeCustom" DESC NULLS LAST, series_1) WHERE series_1 IS NOT NULL;
CREATE INDEX ON PUBLIC."two_Partitions" ("timeCustom" DESC NULLS LAST, series_2) WHERE series_2 IS NOT NULL;
CREATE INDEX ON PUBLIC."two_Partitions" ("timeCustom" DESC NULLS LAST, series_bool) WHERE series_bool IS NOT NULL;
CREATE INDEX ON PUBLIC."two_Partitions" ("timeCustom" DESC NULLS LAST, device_id);
SELECT * FROM create_hypertable('"public"."two_Partitions"'::regclass, 'timeCustom'::name, 'device_id'::name, associated_schema_name=>'_timescaledb_internal'::text, number_partitions => 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'));
create_hypertable
-------------------
(1 row)
\set QUIET off
BEGIN;
BEGIN
\COPY public."two_Partitions" FROM 'data/ds1_dev1_1.tsv' NULL AS '';
COPY 7
COMMIT;
COMMIT
INSERT INTO public."two_Partitions"("timeCustom", device_id, series_0, series_1) VALUES
(1257987600000000000, 'dev1', 1.5, 1),
(1257987600000000000, 'dev1', 1.5, 2),
(1257894000000000000, 'dev2', 1.5, 1),
(1257894002000000000, 'dev1', 2.5, 3);
INSERT 0 4
INSERT INTO "two_Partitions"("timeCustom", device_id, series_0, series_1) VALUES
(1257894000000000000, 'dev2', 1.5, 2);
INSERT 0 1
\set QUIET on
SELECT * FROM hypertable_relation_size('"public"."two_Partitions"');
table_bytes | index_bytes | toast_bytes | total_bytes
-------------+-------------+-------------+-------------
32768 | 417792 | 32768 | 483328
(1 row)
SELECT * FROM hypertable_relation_size_pretty('"public"."two_Partitions"');
table_size | index_size | toast_size | total_size
------------+------------+------------+------------
32 kB | 408 kB | 32 kB | 472 kB
(1 row)
SELECT * FROM chunk_relation_size('"public"."two_Partitions"');
chunk_id | chunk_table | partitioning_columns | partitioning_column_types | partitioning_hash_functions | ranges | table_bytes | index_bytes | toast_bytes | total_bytes
----------+----------------------------------------+------------------------+---------------------------+-------------------------------------------------+-----------------------------------------------------------------------------------+-------------+-------------+-------------+-------------
1 | _timescaledb_internal._hyper_1_1_chunk | {timeCustom,device_id} | {bigint,text} | {NULL,_timescaledb_internal.get_partition_hash} | {"[1257892416000000000,1257895008000000000)","[1073741823,9223372036854775807)"} | 8192 | 114688 | 8192 | 131072
2 | _timescaledb_internal._hyper_1_2_chunk | {timeCustom,device_id} | {bigint,text} | {NULL,_timescaledb_internal.get_partition_hash} | {"[1257897600000000000,1257900192000000000)","[1073741823,9223372036854775807)"} | 8192 | 106496 | 8192 | 122880
3 | _timescaledb_internal._hyper_1_3_chunk | {timeCustom,device_id} | {bigint,text} | {NULL,_timescaledb_internal.get_partition_hash} | {"[1257985728000000000,1257988320000000000)","[1073741823,9223372036854775807)"} | 8192 | 98304 | 8192 | 114688
4 | _timescaledb_internal._hyper_1_4_chunk | {timeCustom,device_id} | {bigint,text} | {NULL,_timescaledb_internal.get_partition_hash} | {"[1257892416000000000,1257895008000000000)","[-9223372036854775808,1073741823)"} | 8192 | 98304 | 8192 | 114688
(4 rows)
SELECT * FROM chunk_relation_size_pretty('"public"."two_Partitions"');
chunk_id | chunk_table | partitioning_columns | partitioning_column_types | partitioning_hash_functions | ranges | table_size | index_size | toast_size | total_size
----------+----------------------------------------+------------------------+---------------------------+-------------------------------------------------+-------------------------------------------------------------------+------------+------------+------------+------------
1 | _timescaledb_internal._hyper_1_1_chunk | {timeCustom,device_id} | {bigint,text} | {NULL,_timescaledb_internal.get_partition_hash} | {"['1257892416000000000','1257895008000000000')","[1073741823,)"} | 8192 bytes | 112 kB | 8192 bytes | 128 kB
2 | _timescaledb_internal._hyper_1_2_chunk | {timeCustom,device_id} | {bigint,text} | {NULL,_timescaledb_internal.get_partition_hash} | {"['1257897600000000000','1257900192000000000')","[1073741823,)"} | 8192 bytes | 104 kB | 8192 bytes | 120 kB
3 | _timescaledb_internal._hyper_1_3_chunk | {timeCustom,device_id} | {bigint,text} | {NULL,_timescaledb_internal.get_partition_hash} | {"['1257985728000000000','1257988320000000000')","[1073741823,)"} | 8192 bytes | 96 kB | 8192 bytes | 112 kB
4 | _timescaledb_internal._hyper_1_4_chunk | {timeCustom,device_id} | {bigint,text} | {NULL,_timescaledb_internal.get_partition_hash} | {"['1257892416000000000','1257895008000000000')","[,1073741823)"} | 8192 bytes | 96 kB | 8192 bytes | 112 kB
(4 rows)
SELECT * FROM indexes_relation_size('"public"."two_Partitions"');
index_name | total_bytes
----------------------------------------------------+-------------
public."two_Partitions_device_id_timeCustom_idx" | 65536
public."two_Partitions_timeCustom_device_id_idx" | 65536
public."two_Partitions_timeCustom_idx" | 65536
public."two_Partitions_timeCustom_series_0_idx" | 65536
public."two_Partitions_timeCustom_series_1_idx" | 65536
public."two_Partitions_timeCustom_series_2_idx" | 40960
public."two_Partitions_timeCustom_series_bool_idx" | 49152
(7 rows)
SELECT * FROM indexes_relation_size_pretty('"public"."two_Partitions"');
index_name | total_size
----------------------------------------------------+------------
public."two_Partitions_device_id_timeCustom_idx" | 64 kB
public."two_Partitions_timeCustom_device_id_idx" | 64 kB
public."two_Partitions_timeCustom_idx" | 64 kB
public."two_Partitions_timeCustom_series_0_idx" | 64 kB
public."two_Partitions_timeCustom_series_1_idx" | 64 kB
public."two_Partitions_timeCustom_series_2_idx" | 40 kB
public."two_Partitions_timeCustom_series_bool_idx" | 48 kB
(7 rows)
CREATE TABLE timestamp_partitioned(time TIMESTAMP, value TEXT);
SELECT * FROM create_hypertable('timestamp_partitioned', 'time', 'value', 2);
NOTICE: adding not-null constraint to column "time"
create_hypertable
-------------------
(1 row)
INSERT INTO timestamp_partitioned VALUES('2004-10-19 10:23:54', '10');
INSERT INTO timestamp_partitioned VALUES('2004-12-19 10:23:54', '30');
SELECT * FROM chunk_relation_size('timestamp_partitioned');
chunk_id | chunk_table | partitioning_columns | partitioning_column_types | partitioning_hash_functions | ranges | table_bytes | index_bytes | toast_bytes | total_bytes
----------+----------------------------------------+----------------------+--------------------------------------+-------------------------------------------------+----------------------------------------------------------------------------+-------------+-------------+-------------+-------------
5 | _timescaledb_internal._hyper_2_5_chunk | {time,value} | {"timestamp without time zone",text} | {NULL,_timescaledb_internal.get_partition_hash} | {"[1096416000000000,1099008000000000)","[1073741823,9223372036854775807)"} | 8192 | 32768 | 8192 | 49152
6 | _timescaledb_internal._hyper_2_6_chunk | {time,value} | {"timestamp without time zone",text} | {NULL,_timescaledb_internal.get_partition_hash} | {"[1101600000000000,1104192000000000)","[1073741823,9223372036854775807)"} | 8192 | 32768 | 8192 | 49152
(2 rows)
SELECT * FROM chunk_relation_size_pretty('timestamp_partitioned');
chunk_id | chunk_table | partitioning_columns | partitioning_column_types | partitioning_hash_functions | ranges | table_size | index_size | toast_size | total_size
----------+----------------------------------------+----------------------+--------------------------------------+-------------------------------------------------+-------------------------------------------------------------------------------------+------------+------------+------------+------------
5 | _timescaledb_internal._hyper_2_5_chunk | {time,value} | {"timestamp without time zone",text} | {NULL,_timescaledb_internal.get_partition_hash} | {"['Tue Sep 28 17:00:00 2004 PDT','Thu Oct 28 17:00:00 2004 PDT')","[1073741823,)"} | 8192 bytes | 32 kB | 8192 bytes | 48 kB
6 | _timescaledb_internal._hyper_2_6_chunk | {time,value} | {"timestamp without time zone",text} | {NULL,_timescaledb_internal.get_partition_hash} | {"['Sat Nov 27 16:00:00 2004 PST','Mon Dec 27 16:00:00 2004 PST')","[1073741823,)"} | 8192 bytes | 32 kB | 8192 bytes | 48 kB
(2 rows)
CREATE TABLE timestamp_partitioned_2(time TIMESTAMP, value CHAR(9));
SELECT * FROM create_hypertable('timestamp_partitioned_2', 'time', 'value', 2);
NOTICE: adding not-null constraint to column "time"
create_hypertable
-------------------
(1 row)
INSERT INTO timestamp_partitioned_2 VALUES('2004-10-19 10:23:54', '10');
INSERT INTO timestamp_partitioned_2 VALUES('2004-12-19 10:23:54', '30');
SELECT * FROM chunk_relation_size('timestamp_partitioned_2');
chunk_id | chunk_table | partitioning_columns | partitioning_column_types | partitioning_hash_functions | ranges | table_bytes | index_bytes | toast_bytes | total_bytes
----------+----------------------------------------+----------------------+-------------------------------------------+-------------------------------------------------+----------------------------------------------------------------------------+-------------+-------------+-------------+-------------
7 | _timescaledb_internal._hyper_3_7_chunk | {time,value} | {"timestamp without time zone",character} | {NULL,_timescaledb_internal.get_partition_hash} | {"[1096416000000000,1099008000000000)","[1073741823,9223372036854775807)"} | 8192 | 32768 | | 40960
8 | _timescaledb_internal._hyper_3_8_chunk | {time,value} | {"timestamp without time zone",character} | {NULL,_timescaledb_internal.get_partition_hash} | {"[1101600000000000,1104192000000000)","[1073741823,9223372036854775807)"} | 8192 | 32768 | | 40960
(2 rows)
SELECT * FROM chunk_relation_size_pretty('timestamp_partitioned_2');
chunk_id | chunk_table | partitioning_columns | partitioning_column_types | partitioning_hash_functions | ranges | table_size | index_size | toast_size | total_size
----------+----------------------------------------+----------------------+-------------------------------------------+-------------------------------------------------+-------------------------------------------------------------------------------------+------------+------------+------------+------------
7 | _timescaledb_internal._hyper_3_7_chunk | {time,value} | {"timestamp without time zone",character} | {NULL,_timescaledb_internal.get_partition_hash} | {"['Tue Sep 28 17:00:00 2004 PDT','Thu Oct 28 17:00:00 2004 PDT')","[1073741823,)"} | 8192 bytes | 32 kB | | 40 kB
8 | _timescaledb_internal._hyper_3_8_chunk | {time,value} | {"timestamp without time zone",character} | {NULL,_timescaledb_internal.get_partition_hash} | {"['Sat Nov 27 16:00:00 2004 PST','Mon Dec 27 16:00:00 2004 PST')","[1073741823,)"} | 8192 bytes | 32 kB | | 40 kB
(2 rows)
CREATE TABLE toast_test(time TIMESTAMP, value TEXT);
-- Set storage type to EXTERNAL to prevent PostgreSQL from compressing my
-- easily compressable string and instead store it with TOAST
ALTER TABLE toast_test ALTER COLUMN value SET STORAGE EXTERNAL;
SELECT * FROM create_hypertable('toast_test', 'time');
NOTICE: adding not-null constraint to column "time"
create_hypertable
-------------------
(1 row)
INSERT INTO toast_test VALUES('2004-10-19 10:23:54', $$
this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k. this must be over 2k.
$$);
SELECT * FROM chunk_relation_size('toast_test');
chunk_id | chunk_table | partitioning_columns | partitioning_column_types | partitioning_hash_functions | ranges | table_bytes | index_bytes | toast_bytes | total_bytes
----------+----------------------------------------+----------------------+---------------------------------+-----------------------------+-----------------------------------------+-------------+-------------+-------------+-------------
9 | _timescaledb_internal._hyper_4_9_chunk | {time} | {"timestamp without time zone"} | {NULL} | {"[1096416000000000,1099008000000000)"} | 8192 | 16384 | 24576 | 49152
(1 row)
SELECT * FROM chunk_relation_size_pretty('toast_test');
chunk_id | chunk_table | partitioning_columns | partitioning_column_types | partitioning_hash_functions | ranges | table_size | index_size | toast_size | total_size
----------+----------------------------------------+----------------------+---------------------------------+-----------------------------+---------------------------------------------------------------------+------------+------------+------------+------------
9 | _timescaledb_internal._hyper_4_9_chunk | {time} | {"timestamp without time zone"} | {NULL} | {"['Tue Sep 28 17:00:00 2004 PDT','Thu Oct 28 17:00:00 2004 PDT')"} | 8192 bytes | 16 kB | 24 kB | 48 kB
(1 row)
CREATE TABLE approx_count(time TIMESTAMP, value int);
SELECT * FROM create_hypertable('approx_count', 'time');
NOTICE: adding not-null constraint to column "time"
create_hypertable
-------------------
(1 row)
INSERT INTO approx_count VALUES('2004-01-01 10:00:01', 1);
INSERT INTO approx_count VALUES('2004-01-01 10:00:02', 2);
INSERT INTO approx_count VALUES('2004-01-01 10:00:03', 3);
INSERT INTO approx_count VALUES('2004-01-01 10:00:04', 4);
INSERT INTO approx_count VALUES('2004-01-01 10:00:05', 5);
INSERT INTO approx_count VALUES('2004-01-01 10:00:06', 6);
INSERT INTO approx_count VALUES('2004-01-01 10:00:07', 7);
INSERT INTO approx_count VALUES('2004-01-01 10:00:08', 8);
INSERT INTO approx_count VALUES('2004-01-01 10:00:09', 9);
INSERT INTO approx_count VALUES('2004-01-01 10:00:10', 10);
ANALYZE approx_count;
SELECT * FROM hypertable_approximate_row_count('approx_count');
schema_name | table_name | row_estimate
-------------+--------------+--------------
public | approx_count | 10
(1 row)
-- all hypertables
SELECT * FROM hypertable_approximate_row_count();
schema_name | table_name | row_estimate
-------------+-------------------------+--------------
public | approx_count | 10
public | timestamp_partitioned | 0
public | timestamp_partitioned_2 | 0
public | toast_test | 0
public | two_Partitions | 0
(5 rows)