Skip to content

Commit 50cf120

Browse files
committed
Add check for large recorded materialization range
1 parent 4064e57 commit 50cf120

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

diagnostic.sql

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,34 @@ BEGIN
1919
END
2020
$$ SET search_path = pg_catalog, pg_temp;
2121

22+
CREATE OR REPLACE FUNCTION check_cagg_large_materialization_range() RETURNS void LANGUAGE plpgsql AS
23+
$$
24+
DECLARE
25+
cagg regclass;
26+
range text;
27+
BEGIN
28+
FOR cagg, range IN
29+
SELECT
30+
format('%I.%I', c.user_view_schema, c.user_view_name)::regclass AS continuous_aggregate,
31+
CASE
32+
WHEN d.column_type =ANY('{int4,int8}'::regtype[]) THEN (r.greatest_modified_value - r.lowest_modified_value)::text
33+
WHEN d.column_type =ANY('{timestamp,timestamptz}'::regtype[]) THEN _timescaledb_functions.to_interval(r.greatest_modified_value - r.lowest_modified_value)::text
34+
END AS range
35+
FROM _timescaledb_catalog.continuous_aggs_materialization_ranges r
36+
JOIN _timescaledb_catalog.continuous_agg c ON c.mat_hypertable_id=r.materialization_id
37+
JOIN _timescaledb_catalog.continuous_aggs_bucket_function f on f.mat_hypertable_id=c.mat_hypertable_id
38+
JOIN _timescaledb_catalog.dimension d ON d.hypertable_id=c.mat_hypertable_id
39+
WHERE
40+
CASE
41+
WHEN d.column_type =ANY('{int4,int8}'::regtype[]) THEN (r.greatest_modified_value - r.lowest_modified_value) > 250 * f.bucket_width::int
42+
WHEN d.column_type =ANY('{timestamp,timestamptz}'::regtype[]) THEN _timescaledb_functions.to_interval(r.greatest_modified_value - r.lowest_modified_value) > 250 * f.bucket_width::interval
43+
END
44+
LOOP
45+
RAISE WARNING 'Continuous aggregate % has large materialization range ''%''.', cagg, range;
46+
END LOOP;
47+
END
48+
$$ SET search_path = pg_catalog, pg_temp;
49+
2250
CREATE OR REPLACE FUNCTION check_job_failures() RETURNS void LANGUAGE plpgsql AS
2351
$$
2452
DECLARE
@@ -119,6 +147,7 @@ BEGIN
119147
PERFORM check_deprecated_features();
120148
PERFORM check_job_failures();
121149
PERFORM check_compressed_chunk_batch_sizes();
150+
PERFORM check_cagg_large_materialization_range();
122151
END
123152
$$;
124153

0 commit comments

Comments
 (0)