Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support CAGG names in hypertable_(detailed_)size #5159

Merged
merged 1 commit into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions sql/size_utils.sql
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,19 @@ BEGIN
INNER JOIN _timescaledb_catalog.hypertable ht ON (ht.schema_name = n.nspname AND ht.table_name = c.relname)
WHERE c.OID = hypertable;

IF table_name IS NULL THEN
RETURN;
END IF;
IF table_name IS NULL THEN
SELECT h.schema_name, h.table_name, replication_factor > 0
INTO schema_name, table_name, is_distributed
FROM pg_class c
INNER JOIN pg_namespace n ON (n.OID = c.relnamespace)
INNER JOIN _timescaledb_catalog.continuous_agg a ON (a.user_view_schema = n.nspname AND a.user_view_name = c.relname)
INNER JOIN _timescaledb_catalog.hypertable h ON h.id = a.mat_hypertable_id
WHERE c.OID = hypertable;

IF table_name IS NULL THEN
RETURN;
END IF;
END IF;

CASE WHEN is_distributed THEN
RETURN QUERY
Expand Down
70 changes: 70 additions & 0 deletions tsl/test/expected/size_utils.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
-- This file and its contents are licensed under the Timescale License.
-- Please see the included NOTICE for copyright information and
-- LICENSE-TIMESCALE for a copy of the license.
-- Prepare test data for continuous aggregate size function tests
CREATE TABLE hypersize(time timestamptz, device int);
SELECT * FROM create_hypertable('hypersize', 'time');
NOTICE: adding not-null constraint to column "time"
hypertable_id | schema_name | table_name | created
---------------+-------------+------------+---------
1 | public | hypersize | t
(1 row)

INSERT INTO hypersize VALUES('2021-02-25', 1);
-- Test size functions on empty continuous aggregate
CREATE MATERIALIZED VIEW hypersize_cagg WITH (timescaledb.continuous) AS SELECT time_bucket('1 day', "time") AS bucket, AVG(device) AS value FROM hypersize GROUP BY 1 WITH NO DATA;
SELECT format('%I.%I', h.schema_name, h.table_name) AS "MAT_HYPERTABLE_NAME"
FROM _timescaledb_catalog.continuous_agg ca
INNER JOIN _timescaledb_catalog.hypertable h ON(h.id = ca.mat_hypertable_id)
WHERE user_view_name = 'hypersize_cagg'
\gset
SELECT * FROM hypertable_size(:'MAT_HYPERTABLE_NAME');
hypertable_size
-----------------
16384
(1 row)

SELECT * FROM hypertable_detailed_size(:'MAT_HYPERTABLE_NAME') ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-----------
0 | 8192 | 8192 | 16384 |
(1 row)

SELECT * FROM hypertable_size('hypersize_cagg');
hypertable_size
-----------------
16384
(1 row)

SELECT * FROM hypertable_detailed_size('hypersize_cagg') ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-----------
0 | 8192 | 8192 | 16384 |
(1 row)

-- Test size functions on non-empty countinuous aggregate
CALL refresh_continuous_aggregate('hypersize_cagg', NULL, NULL);
SELECT * FROM hypertable_size('hypersize_cagg');
hypertable_size
-----------------
49152
(1 row)

SELECT * FROM hypertable_detailed_size('hypersize_cagg') ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-----------
8192 | 24576 | 16384 | 49152 |
(1 row)

noctarius marked this conversation as resolved.
Show resolved Hide resolved
SELECT * FROM hypertable_size(:'MAT_HYPERTABLE_NAME');
hypertable_size
-----------------
49152
(1 row)

SELECT * FROM hypertable_detailed_size(:'MAT_HYPERTABLE_NAME') ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-----------
8192 | 24576 | 16384 | 49152 |
(1 row)

3 changes: 2 additions & 1 deletion tsl/test/sql/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ set(TEST_FILES
move.sql
partialize_finalize.sql
reorder.sql
skip_scan.sql)
skip_scan.sql
size_utils.sql)

if(CMAKE_BUILD_TYPE MATCHES Debug)
list(
Expand Down
29 changes: 29 additions & 0 deletions tsl/test/sql/size_utils.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-- This file and its contents are licensed under the Timescale License.
-- Please see the included NOTICE for copyright information and
-- LICENSE-TIMESCALE for a copy of the license.

-- Prepare test data for continuous aggregate size function tests
CREATE TABLE hypersize(time timestamptz, device int);
SELECT * FROM create_hypertable('hypersize', 'time');
INSERT INTO hypersize VALUES('2021-02-25', 1);

-- Test size functions on empty continuous aggregate
CREATE MATERIALIZED VIEW hypersize_cagg WITH (timescaledb.continuous) AS SELECT time_bucket('1 day', "time") AS bucket, AVG(device) AS value FROM hypersize GROUP BY 1 WITH NO DATA;
SELECT format('%I.%I', h.schema_name, h.table_name) AS "MAT_HYPERTABLE_NAME"
FROM _timescaledb_catalog.continuous_agg ca
INNER JOIN _timescaledb_catalog.hypertable h ON(h.id = ca.mat_hypertable_id)
WHERE user_view_name = 'hypersize_cagg'
\gset

SELECT * FROM hypertable_size(:'MAT_HYPERTABLE_NAME');
SELECT * FROM hypertable_detailed_size(:'MAT_HYPERTABLE_NAME') ORDER BY node_name;
SELECT * FROM hypertable_size('hypersize_cagg');
SELECT * FROM hypertable_detailed_size('hypersize_cagg') ORDER BY node_name;

-- Test size functions on non-empty countinuous aggregate
CALL refresh_continuous_aggregate('hypersize_cagg', NULL, NULL);
SELECT * FROM hypertable_size('hypersize_cagg');
SELECT * FROM hypertable_detailed_size('hypersize_cagg') ORDER BY node_name;
SELECT * FROM hypertable_size(:'MAT_HYPERTABLE_NAME');
SELECT * FROM hypertable_detailed_size(:'MAT_HYPERTABLE_NAME') ORDER BY node_name;