timescaledb/test/expected/size_utils.out
Bharathy dd65a6b436 Fix segfault after second ANALYZE
Issue occurs in extended query protocol mode only where every
query goes through PREPARE and EXECUTE phase. First time ANALYZE
is executed, a list of relations to be vaccumed is extracted and
saved in a list. This list is referenced in parsetree node. Once
execution of ANALYZE is complete, this list is cleaned up, however
reference to the same is not cleaned up in parsetree node. When
second time ANALYZE is executed, segfault happens as we access an
invalid memory location.

Fixed the issue by restoring the actual value in parsetree node
once ANALYZE completes its execution.

Fixes #4857
2022-12-12 17:34:41 +05:30

761 lines
37 KiB
Plaintext

-- This file and its contents are licensed under the Apache License 2.0.
-- Please see the included NOTICE for copyright information and
-- LICENSE-APACHE for a copy of the license.
\ir include/insert_two_partitions.sql
-- This file and its contents are licensed under the Apache License 2.0.
-- Please see the included NOTICE for copyright information and
-- LICENSE-APACHE for a copy of the license.
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'));
hypertable_id | schema_name | table_name | created
---------------+-------------+----------------+---------
1 | public | two_Partitions | t
(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_detailed_size('"public"."two_Partitions"');
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-----------
32768 | 475136 | 40960 | 548864 |
(1 row)
SELECT * FROM hypertable_index_size('"public"."two_Partitions_device_id_timeCustom_idx"');
hypertable_index_size
-----------------------
73728
(1 row)
SELECT * FROM hypertable_index_size('"public"."two_Partitions_timeCustom_device_id_idx"');
hypertable_index_size
-----------------------
73728
(1 row)
SELECT * FROM hypertable_index_size('"public"."two_Partitions_timeCustom_idx"');
hypertable_index_size
-----------------------
73728
(1 row)
SELECT * FROM hypertable_index_size('"public"."two_Partitions_timeCustom_series_0_idx"');
hypertable_index_size
-----------------------
73728
(1 row)
SELECT * FROM hypertable_index_size('"public"."two_Partitions_timeCustom_series_1_idx"');
hypertable_index_size
-----------------------
73728
(1 row)
SELECT * FROM hypertable_index_size('"public"."two_Partitions_timeCustom_series_2_idx"');
hypertable_index_size
-----------------------
49152
(1 row)
SELECT * FROM hypertable_index_size('"public"."two_Partitions_timeCustom_series_bool_idx"');
hypertable_index_size
-----------------------
57344
(1 row)
SELECT * FROM chunks_detailed_size('"public"."two_Partitions"') order by chunk_name;
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-----------------------+------------------+-------------+-------------+-------------+-------------+-----------
_timescaledb_internal | _hyper_1_1_chunk | 8192 | 114688 | 8192 | 131072 |
_timescaledb_internal | _hyper_1_2_chunk | 8192 | 106496 | 8192 | 122880 |
_timescaledb_internal | _hyper_1_3_chunk | 8192 | 98304 | 8192 | 114688 |
_timescaledb_internal | _hyper_1_4_chunk | 8192 | 98304 | 8192 | 114688 |
(4 rows)
CREATE TABLE timestamp_partitioned(time TIMESTAMP, value TEXT);
SELECT * FROM create_hypertable('timestamp_partitioned', 'time', 'value', 2);
WARNING: column type "timestamp without time zone" used for "time" does not follow best practices
NOTICE: adding not-null constraint to column "time"
hypertable_id | schema_name | table_name | created
---------------+-------------+-----------------------+---------
2 | public | timestamp_partitioned | t
(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 chunks_detailed_size('timestamp_partitioned') order by chunk_name;
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-----------------------+------------------+-------------+-------------+-------------+-------------+-----------
_timescaledb_internal | _hyper_2_5_chunk | 8192 | 32768 | 8192 | 49152 |
_timescaledb_internal | _hyper_2_6_chunk | 8192 | 32768 | 8192 | 49152 |
(2 rows)
CREATE TABLE timestamp_partitioned_2(time TIMESTAMP, value CHAR(9));
SELECT * FROM create_hypertable('timestamp_partitioned_2', 'time', 'value', 2);
WARNING: column type "timestamp without time zone" used for "time" does not follow best practices
NOTICE: adding not-null constraint to column "time"
hypertable_id | schema_name | table_name | created
---------------+-------------+-------------------------+---------
3 | public | timestamp_partitioned_2 | t
(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 chunks_detailed_size('timestamp_partitioned_2') order by chunk_name;
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-----------------------+------------------+-------------+-------------+-------------+-------------+-----------
_timescaledb_internal | _hyper_3_7_chunk | 8192 | 32768 | 0 | 40960 |
_timescaledb_internal | _hyper_3_8_chunk | 8192 | 32768 | 0 | 40960 |
(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');
WARNING: column type "timestamp without time zone" used for "time" does not follow best practices
NOTICE: adding not-null constraint to column "time"
hypertable_id | schema_name | table_name | created
---------------+-------------+------------+---------
4 | public | toast_test | t
(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 chunks_detailed_size('toast_test');
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-----------------------+------------------+-------------+-------------+-------------+-------------+-----------
_timescaledb_internal | _hyper_4_9_chunk | 8192 | 16384 | 24576 | 49152 |
(1 row)
--
-- Tests for approximate_row_count()
--
-- Regular table
--
CREATE TABLE approx_count(time TIMESTAMP, value int);
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);
SELECT * FROM approximate_row_count('approx_count');
approximate_row_count
-----------------------
0
(1 row)
ANALYZE approx_count;
SELECT count(*) FROM approx_count;
count
-------
7
(1 row)
SELECT * FROM approximate_row_count('approx_count');
approximate_row_count
-----------------------
7
(1 row)
DROP TABLE approx_count;
-- Regular table with basic inheritance
--
CREATE TABLE approx_count(id int);
CREATE TABLE approx_count_child(id2 int) INHERITS (approx_count);
INSERT INTO approx_count_child VALUES(0);
INSERT INTO approx_count VALUES(1);
SELECT count(*) FROM approx_count;
count
-------
2
(1 row)
SELECT * FROM approximate_row_count('approx_count');
approximate_row_count
-----------------------
0
(1 row)
ANALYZE approx_count;
SELECT * FROM approximate_row_count('approx_count');
approximate_row_count
-----------------------
1
(1 row)
ANALYZE approx_count_child;
SELECT * FROM approximate_row_count('approx_count');
approximate_row_count
-----------------------
2
(1 row)
DROP TABLE approx_count CASCADE;
NOTICE: drop cascades to table approx_count_child
-- Regular table with nested inheritance
--
CREATE TABLE approx_count(id int);
CREATE TABLE approx_count_a(id2 int) INHERITS (approx_count);
CREATE TABLE approx_count_b(id3 int) INHERITS (approx_count_a);
CREATE TABLE approx_count_c(id4 int) INHERITS (approx_count_b);
INSERT INTO approx_count_a VALUES(0);
INSERT INTO approx_count_b VALUES(1);
INSERT INTO approx_count_c VALUES(2);
INSERT INTO approx_count VALUES(3);
SELECT * FROM approximate_row_count('approx_count');
approximate_row_count
-----------------------
0
(1 row)
ANALYZE approx_count_a;
ANALYZE approx_count_b;
ANALYZE approx_count_c;
ANALYZE approx_count;
SELECT count(*) FROM approx_count;
count
-------
4
(1 row)
SELECT * FROM approximate_row_count('approx_count');
approximate_row_count
-----------------------
4
(1 row)
SELECT count(*) FROM approx_count_a;
count
-------
3
(1 row)
SELECT * FROM approximate_row_count('approx_count_a');
approximate_row_count
-----------------------
3
(1 row)
SELECT count(*) FROM approx_count_b;
count
-------
2
(1 row)
SELECT * FROM approximate_row_count('approx_count_b');
approximate_row_count
-----------------------
2
(1 row)
SELECT count(*) FROM approx_count_c;
count
-------
1
(1 row)
SELECT * FROM approximate_row_count('approx_count_c');
approximate_row_count
-----------------------
1
(1 row)
DROP TABLE approx_count CASCADE;
NOTICE: drop cascades to 3 other objects
-- table with declarative partitioning
--
CREATE TABLE approx_count_dp(time TIMESTAMP, value int) PARTITION BY RANGE(time);
CREATE TABLE approx_count_dp0 PARTITION OF approx_count_dp
FOR VALUES FROM ('2004-01-01 00:00:00') TO ('2005-01-01 00:00:00');
CREATE TABLE approx_count_dp1 PARTITION OF approx_count_dp
FOR VALUES FROM ('2005-01-01 00:00:00') TO ('2006-01-01 00:00:00');
CREATE TABLE approx_count_dp2 PARTITION OF approx_count_dp
FOR VALUES FROM ('2006-01-01 00:00:00') TO ('2007-01-01 00:00:00');
INSERT INTO approx_count_dp VALUES('2004-01-01 10:00:00', 1);
INSERT INTO approx_count_dp VALUES('2004-01-01 11:00:00', 1);
INSERT INTO approx_count_dp VALUES('2004-01-01 12:00:01', 1);
INSERT INTO approx_count_dp VALUES('2005-01-01 10:00:00', 1);
INSERT INTO approx_count_dp VALUES('2005-01-01 11:00:00', 1);
INSERT INTO approx_count_dp VALUES('2005-01-01 12:00:01', 1);
INSERT INTO approx_count_dp VALUES('2006-01-01 10:00:00', 1);
INSERT INTO approx_count_dp VALUES('2006-01-01 11:00:00', 1);
INSERT INTO approx_count_dp VALUES('2006-01-01 12:00:01', 1);
SELECT count(*) FROM approx_count_dp;
count
-------
9
(1 row)
SELECT count(*) FROM approx_count_dp0;
count
-------
3
(1 row)
SELECT count(*) FROM approx_count_dp1;
count
-------
3
(1 row)
SELECT count(*) FROM approx_count_dp2;
count
-------
3
(1 row)
SELECT * FROM approximate_row_count('approx_count_dp');
approximate_row_count
-----------------------
0
(1 row)
ANALYZE approx_count_dp;
SELECT * FROM approximate_row_count('approx_count_dp');
approximate_row_count
-----------------------
9
(1 row)
SELECT * FROM approximate_row_count('approx_count_dp0');
approximate_row_count
-----------------------
3
(1 row)
SELECT * FROM approximate_row_count('approx_count_dp1');
approximate_row_count
-----------------------
3
(1 row)
SELECT * FROM approximate_row_count('approx_count_dp2');
approximate_row_count
-----------------------
3
(1 row)
CREATE TABLE approx_count_dp_nested(time TIMESTAMP, device_id int, value int) PARTITION BY RANGE(time);
CREATE TABLE approx_count_dp_nested_0 PARTITION OF approx_count_dp_nested FOR VALUES FROM ('2004-01-01 00:00:00') TO ('2005-01-01 00:00:00') PARTITION BY RANGE (device_id);
CREATE TABLE approx_count_dp_nested_0_0 PARTITION OF approx_count_dp_nested_0 FOR VALUES FROM (0) TO (10);
CREATE TABLE approx_count_dp_nested_0_1 PARTITION OF approx_count_dp_nested_0 FOR VALUES FROM (10) TO (20);
CREATE TABLE approx_count_dp_nested_1 PARTITION OF approx_count_dp_nested FOR VALUES FROM ('2005-01-01 00:00:00') TO ('2006-01-01 00:00:00') PARTITION BY RANGE (device_id);
CREATE TABLE approx_count_dp_nested_1_0 PARTITION OF approx_count_dp_nested_1 FOR VALUES FROM (0) TO (10);
CREATE TABLE approx_count_dp_nested_1_1 PARTITION OF approx_count_dp_nested_1 FOR VALUES FROM (10) TO (20);
INSERT INTO approx_count_dp_nested VALUES('2004-01-01 10:00:00', 1, 1);
INSERT INTO approx_count_dp_nested VALUES('2004-01-01 10:00:00', 2, 1);
INSERT INTO approx_count_dp_nested VALUES('2004-01-01 10:00:00', 3, 1);
INSERT INTO approx_count_dp_nested VALUES('2004-01-01 10:00:00', 11, 1);
INSERT INTO approx_count_dp_nested VALUES('2004-01-01 10:00:00', 12, 1);
INSERT INTO approx_count_dp_nested VALUES('2004-01-01 10:00:00', 13, 1);
INSERT INTO approx_count_dp_nested VALUES('2005-01-01 10:00:00', 1, 1);
INSERT INTO approx_count_dp_nested VALUES('2005-01-01 10:00:00', 2, 1);
INSERT INTO approx_count_dp_nested VALUES('2005-01-01 10:00:00', 3, 1);
INSERT INTO approx_count_dp_nested VALUES('2005-01-01 10:00:00', 11, 1);
INSERT INTO approx_count_dp_nested VALUES('2005-01-01 10:00:00', 12, 1);
INSERT INTO approx_count_dp_nested VALUES('2005-01-01 10:00:00', 13, 1);
SELECT * FROM approximate_row_count('approx_count_dp_nested');
approximate_row_count
-----------------------
0
(1 row)
ANALYZE approx_count_dp_nested;
SELECT
(SELECT count(*) FROM approx_count_dp_nested) AS dp_nested,
(SELECT count(*) FROM approx_count_dp_nested_0) AS dp_nested_0,
(SELECT count(*) FROM approx_count_dp_nested_0_0) AS dp_nested_0_0,
(SELECT count(*) FROM approx_count_dp_nested_0_1) AS dp_nested_0_1,
(SELECT count(*) FROM approx_count_dp_nested_1) AS dp_nested_1,
(SELECT count(*) FROM approx_count_dp_nested_1_0) AS dp_nested_1_0,
(SELECT count(*) FROM approx_count_dp_nested_1_1) AS dp_nested_1_1
UNION ALL
SELECT
approximate_row_count('approx_count_dp_nested'),
approximate_row_count('approx_count_dp_nested_0'),
approximate_row_count('approx_count_dp_nested_0_0'),
approximate_row_count('approx_count_dp_nested_0_1'),
approximate_row_count('approx_count_dp_nested_1'),
approximate_row_count('approx_count_dp_nested_1_0'),
approximate_row_count('approx_count_dp_nested_1_1');
dp_nested | dp_nested_0 | dp_nested_0_0 | dp_nested_0_1 | dp_nested_1 | dp_nested_1_0 | dp_nested_1_1
-----------+-------------+---------------+---------------+-------------+---------------+---------------
12 | 6 | 3 | 3 | 6 | 3 | 3
12 | 6 | 3 | 3 | 6 | 3 | 3
(2 rows)
-- Hypertable
--
CREATE TABLE approx_count(time TIMESTAMP, value int);
SELECT * FROM create_hypertable('approx_count', 'time');
WARNING: column type "timestamp without time zone" used for "time" does not follow best practices
NOTICE: adding not-null constraint to column "time"
hypertable_id | schema_name | table_name | created
---------------+-------------+--------------+---------
5 | public | approx_count | t
(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);
SELECT count(*) FROM approx_count;
count
-------
10
(1 row)
SELECT * FROM approximate_row_count('approx_count');
approximate_row_count
-----------------------
0
(1 row)
ANALYZE approx_count;
SELECT * FROM approximate_row_count('approx_count');
approximate_row_count
-----------------------
10
(1 row)
\set ON_ERROR_STOP 0
SELECT * FROM approximate_row_count('unexisting');
ERROR: relation "unexisting" does not exist at character 37
SELECT * FROM approximate_row_count();
ERROR: function approximate_row_count() does not exist at character 15
SELECT * FROM approximate_row_count(NULL);
approximate_row_count
-----------------------
(1 row)
\set ON_ERROR_STOP 1
-- Test size functions with invalid or non-existing OID
SELECT * FROM hypertable_size(0);
hypertable_size
-----------------
(1 row)
SELECT * FROM hypertable_detailed_size(0) ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-----------
(0 rows)
SELECT * FROM chunks_detailed_size(0) ORDER BY node_name;
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
--------------+------------+-------------+-------------+-------------+-------------+-----------
(0 rows)
SELECT * FROM hypertable_compression_stats(0) ORDER BY node_name;
total_chunks | number_compressed_chunks | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+--------------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM chunk_compression_stats(0) ORDER BY node_name;
chunk_schema | chunk_name | compression_status | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+------------+--------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM hypertable_index_size(0);
hypertable_index_size
-----------------------
(1 row)
SELECT * FROM _timescaledb_internal.relation_size(0);
total_size | heap_size | index_size | toast_size
------------+-----------+------------+------------
| | |
(1 row)
SELECT * FROM hypertable_size(1);
hypertable_size
-----------------
(1 row)
SELECT * FROM hypertable_detailed_size(1) ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-----------
(0 rows)
SELECT * FROM chunks_detailed_size(1) ORDER BY node_name;
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
--------------+------------+-------------+-------------+-------------+-------------+-----------
(0 rows)
SELECT * FROM hypertable_compression_stats(1) ORDER BY node_name;
total_chunks | number_compressed_chunks | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+--------------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM chunk_compression_stats(1) ORDER BY node_name;
chunk_schema | chunk_name | compression_status | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+------------+--------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM hypertable_index_size(1);
hypertable_index_size
-----------------------
(1 row)
SELECT * FROM _timescaledb_internal.relation_size(1);
total_size | heap_size | index_size | toast_size
------------+-----------+------------+------------
0 | 0 | 0 | 0
(1 row)
-- Test size functions with NULL input
SELECT * FROM hypertable_size(NULL);
hypertable_size
-----------------
(1 row)
SELECT * FROM hypertable_detailed_size(NULL) ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-----------
(0 rows)
SELECT * FROM chunks_detailed_size(NULL) ORDER BY node_name;
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
--------------+------------+-------------+-------------+-------------+-------------+-----------
(0 rows)
SELECT * FROM hypertable_compression_stats(NULL) ORDER BY node_name;
total_chunks | number_compressed_chunks | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+--------------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM chunk_compression_stats(NULL) ORDER BY node_name;
chunk_schema | chunk_name | compression_status | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+------------+--------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM hypertable_index_size(NULL);
hypertable_index_size
-----------------------
(1 row)
SELECT * FROM _timescaledb_internal.relation_size(NULL);
total_size | heap_size | index_size | toast_size
------------+-----------+------------+------------
| | |
(1 row)
-- Test size functions on regular table
CREATE TABLE hypersize(time timestamptz, device int);
CREATE INDEX hypersize_time_idx ON hypersize (time);
\set ON_ERROR_STOP 0
\set VERBOSITY default
\set SHOW_CONTEXT never
SELECT pg_relation_size('hypersize'), pg_table_size('hypersize'), pg_indexes_size('hypersize'), pg_total_relation_size('hypersize'), pg_relation_size('hypersize_time_idx');
pg_relation_size | pg_table_size | pg_indexes_size | pg_total_relation_size | pg_relation_size
------------------+---------------+-----------------+------------------------+------------------
0 | 0 | 8192 | 8192 | 8192
(1 row)
SELECT * FROM _timescaledb_internal.relation_size('hypersize');
total_size | heap_size | index_size | toast_size
------------+-----------+------------+------------
8192 | 0 | 8192 | 0
(1 row)
SELECT * FROM hypertable_size('hypersize');
hypertable_size
-----------------
(1 row)
SELECT * FROM hypertable_detailed_size('hypersize') ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-----------
(0 rows)
SELECT * FROM chunks_detailed_size('hypersize') ORDER BY node_name;
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
--------------+------------+-------------+-------------+-------------+-------------+-----------
(0 rows)
SELECT * FROM hypertable_compression_stats('hypersize') ORDER BY node_name;
total_chunks | number_compressed_chunks | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+--------------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM chunk_compression_stats('hypersize') ORDER BY node_name;
chunk_schema | chunk_name | compression_status | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+------------+--------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM hypertable_index_size('hypersize_time_idx');
hypertable_index_size
-----------------------
(1 row)
\set VERBOSITY terse
\set ON_ERROR_STOP 1
-- Test size functions on empty hypertable
SELECT * FROM create_hypertable('hypersize', 'time');
NOTICE: adding not-null constraint to column "time"
hypertable_id | schema_name | table_name | created
---------------+-------------+------------+---------
6 | public | hypersize | t
(1 row)
SELECT pg_relation_size('hypersize'), pg_table_size('hypersize'), pg_indexes_size('hypersize'), pg_total_relation_size('hypersize'), pg_relation_size('hypersize_time_idx');
pg_relation_size | pg_table_size | pg_indexes_size | pg_total_relation_size | pg_relation_size
------------------+---------------+-----------------+------------------------+------------------
0 | 0 | 8192 | 8192 | 8192
(1 row)
SELECT * FROM _timescaledb_internal.relation_size('hypersize');
total_size | heap_size | index_size | toast_size
------------+-----------+------------+------------
8192 | 0 | 8192 | 0
(1 row)
SELECT * FROM hypertable_size('hypersize');
hypertable_size
-----------------
8192
(1 row)
SELECT * FROM hypertable_detailed_size('hypersize') ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-----------
0 | 8192 | 0 | 8192 |
(1 row)
SELECT * FROM chunks_detailed_size('hypersize') ORDER BY node_name;
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
--------------+------------+-------------+-------------+-------------+-------------+-----------
(0 rows)
SELECT * FROM hypertable_compression_stats('hypersize') ORDER BY node_name;
total_chunks | number_compressed_chunks | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+--------------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM chunk_compression_stats('hypersize') ORDER BY node_name;
chunk_schema | chunk_name | compression_status | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+------------+--------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM hypertable_index_size('hypersize_time_idx');
hypertable_index_size
-----------------------
8192
(1 row)
-- Test size functions on non-empty hypertable
INSERT INTO hypersize VALUES('2021-02-25', 1);
SELECT pg_relation_size('hypersize'), pg_table_size('hypersize'), pg_indexes_size('hypersize'), pg_total_relation_size('hypersize'), pg_relation_size('hypersize_time_idx');
pg_relation_size | pg_table_size | pg_indexes_size | pg_total_relation_size | pg_relation_size
------------------+---------------+-----------------+------------------------+------------------
0 | 0 | 8192 | 8192 | 8192
(1 row)
SELECT pg_relation_size(ch), pg_table_size(ch), pg_indexes_size(ch), pg_total_relation_size(ch)
FROM show_chunks('hypersize') ch
ORDER BY ch;
pg_relation_size | pg_table_size | pg_indexes_size | pg_total_relation_size
------------------+---------------+-----------------+------------------------
8192 | 8192 | 16384 | 24576
(1 row)
SELECT * FROM show_chunks('hypersize') ch JOIN LATERAL _timescaledb_internal.relation_size(ch) ON true;
ch | total_size | heap_size | index_size | toast_size
-----------------------------------------+------------+-----------+------------+------------
_timescaledb_internal._hyper_6_11_chunk | 24576 | 8192 | 16384 | 0
(1 row)
SELECT * FROM hypertable_size('hypersize');
hypertable_size
-----------------
32768
(1 row)
SELECT * FROM hypertable_detailed_size('hypersize') ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-----------
8192 | 24576 | 0 | 32768 |
(1 row)
SELECT * FROM chunks_detailed_size('hypersize') ORDER BY node_name;
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-----------------------+-------------------+-------------+-------------+-------------+-------------+-----------
_timescaledb_internal | _hyper_6_11_chunk | 8192 | 16384 | 0 | 24576 |
(1 row)
SELECT * FROM hypertable_compression_stats('hypersize') ORDER BY node_name;
total_chunks | number_compressed_chunks | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+--------------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM chunk_compression_stats('hypersize') ORDER BY node_name;
chunk_schema | chunk_name | compression_status | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+------------+--------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM hypertable_index_size('hypersize_time_idx');
hypertable_index_size
-----------------------
24576
(1 row)
-- github issue #4857
-- below procedure should not crash
SET client_min_messages = ERROR;
do
$$
DECLARE
o INT;
BEGIN
FOR c IN 1..20 LOOP
ANALYZE;
END LOOP;
END;
$$;
RESET client_min_messages;