-
Notifications
You must be signed in to change notification settings - Fork 907
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support CAGG names in hypertable_(detailed_)size
This small patch adds support for continuous aggregates to the `hypertable_detailed_size` (and with that `hypertable_size`). It adds an additional check to see if a continuous aggregate exists if a hypertable with the given regclass name isn't found.
- Loading branch information
1 parent
c8c50da
commit 0118e6b
Showing
4 changed files
with
114 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|