From f93cd91bbcc3c4ec2a824f0a7a13ed2411982d0d Mon Sep 17 00:00:00 2001 From: "Christoph Engelbert (noctarius)" Date: Fri, 30 Jun 2023 10:47:24 +0200 Subject: [PATCH] Support CAGG names in chunk_detailed_size This patch adds support to pass continuous aggregate names to `chunk_detailed_size` to align it to the behavior of other functions such as `show_chunks`, `drop_chunks`, `hypertable_size`. --- .unreleased/PR_5839 | 1 + sql/size_utils.sql | 14 ++++++++++++-- tsl/test/expected/size_utils_tsl.out | 22 ++++++++++++++++++++++ tsl/test/sql/size_utils_tsl.sql | 5 ++++- 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 .unreleased/PR_5839 diff --git a/.unreleased/PR_5839 b/.unreleased/PR_5839 new file mode 100644 index 00000000000..31e5f8f8fe0 --- /dev/null +++ b/.unreleased/PR_5839 @@ -0,0 +1 @@ +Implements: #5839 Support CAGG names in chunk_detailed_size diff --git a/sql/size_utils.sql b/sql/size_utils.sql index ebda6604724..bafbca05ec8 100644 --- a/sql/size_utils.sql +++ b/sql/size_utils.sql @@ -348,8 +348,18 @@ 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; + 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 diff --git a/tsl/test/expected/size_utils_tsl.out b/tsl/test/expected/size_utils_tsl.out index 2e06228416e..b84991879e3 100644 --- a/tsl/test/expected/size_utils_tsl.out +++ b/tsl/test/expected/size_utils_tsl.out @@ -30,6 +30,11 @@ SELECT * FROM hypertable_detailed_size(:'MAT_HYPERTABLE_NAME') ORDER BY node_nam 0 | 8192 | 8192 | 16384 | (1 row) +SELECT * FROM chunks_detailed_size(:'MAT_HYPERTABLE_NAME') ORDER BY node_name; + chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name +--------------+------------+-------------+-------------+-------------+-------------+----------- +(0 rows) + SELECT * FROM hypertable_size('hypersize_cagg'); hypertable_size ----------------- @@ -42,6 +47,11 @@ SELECT * FROM hypertable_detailed_size('hypersize_cagg') ORDER BY node_name; 0 | 8192 | 8192 | 16384 | (1 row) +SELECT * FROM chunks_detailed_size('hypersize_cagg') ORDER BY node_name; + chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name +--------------+------------+-------------+-------------+-------------+-------------+----------- +(0 rows) + -- Test size functions on non-empty countinuous aggregate CALL refresh_continuous_aggregate('hypersize_cagg', NULL, NULL); SELECT * FROM hypertable_size('hypersize_cagg'); @@ -56,6 +66,12 @@ SELECT * FROM hypertable_detailed_size('hypersize_cagg') ORDER BY node_name; 8192 | 24576 | 16384 | 49152 | (1 row) +SELECT * FROM chunks_detailed_size('hypersize_cagg') ORDER BY node_name; + chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name +-----------------------+------------------+-------------+-------------+-------------+-------------+----------- + _timescaledb_internal | _hyper_2_2_chunk | 8192 | 16384 | 8192 | 32768 | +(1 row) + SELECT * FROM hypertable_size(:'MAT_HYPERTABLE_NAME'); hypertable_size ----------------- @@ -68,3 +84,9 @@ SELECT * FROM hypertable_detailed_size(:'MAT_HYPERTABLE_NAME') ORDER BY node_nam 8192 | 24576 | 16384 | 49152 | (1 row) +SELECT * FROM chunks_detailed_size(:'MAT_HYPERTABLE_NAME') ORDER BY node_name; + chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name +-----------------------+------------------+-------------+-------------+-------------+-------------+----------- + _timescaledb_internal | _hyper_2_2_chunk | 8192 | 16384 | 8192 | 32768 | +(1 row) + diff --git a/tsl/test/sql/size_utils_tsl.sql b/tsl/test/sql/size_utils_tsl.sql index 4f61c5a31be..9f0d771a27f 100644 --- a/tsl/test/sql/size_utils_tsl.sql +++ b/tsl/test/sql/size_utils_tsl.sql @@ -17,13 +17,16 @@ WHERE user_view_name = 'hypersize_cagg' SELECT * FROM hypertable_size(:'MAT_HYPERTABLE_NAME'); SELECT * FROM hypertable_detailed_size(:'MAT_HYPERTABLE_NAME') ORDER BY node_name; +SELECT * FROM chunks_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; +SELECT * FROM chunks_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 chunks_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; - +SELECT * FROM chunks_detailed_size(:'MAT_HYPERTABLE_NAME') ORDER BY node_name;