Skip to content

Commit

Permalink
Support CAGG names in chunk_detailed_size (#5839)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
noctarius authored Jul 12, 2023
1 parent 963d4ee commit 4c3d64a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
1 change: 1 addition & 0 deletions .unreleased/PR_5839
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implements: #5839 Support CAGG names in chunk_detailed_size
14 changes: 12 additions & 2 deletions sql/size_utils.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions tsl/test/expected/size_utils_tsl.out
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------------
Expand All @@ -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');
Expand All @@ -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
-----------------
Expand All @@ -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)

5 changes: 4 additions & 1 deletion tsl/test/sql/size_utils_tsl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 4c3d64a

Please sign in to comment.