Skip to content

Commit 09ce299

Browse files
committed
Add check for cagg chunk width
1 parent 47742bc commit 09ce299

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

diagnostic.sql

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ $$ SET search_path = pg_catalog, pg_temp;
4242
CREATE OR REPLACE FUNCTION pg_temp.check_cagg_large_materialization_range() RETURNS void LANGUAGE plpgsql AS
4343
$$
4444
DECLARE
45-
cagg regclass;
46-
range text;
45+
v_cagg regclass;
46+
v_range text;
4747
BEGIN
48-
FOR cagg, range IN
48+
FOR v_cagg, v_range IN
4949
SELECT
5050
format('%I.%I', c.user_view_schema, c.user_view_name)::regclass AS continuous_aggregate,
5151
CASE
@@ -62,7 +62,36 @@ BEGIN
6262
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
6363
END
6464
LOOP
65-
RAISE WARNING 'Continuous aggregate % has large materialization range ''%''.', cagg, range;
65+
RAISE WARNING 'Continuous aggregate % has large materialization range ''%''.', v_cagg, v_range;
66+
END LOOP;
67+
END
68+
$$ SET search_path = pg_catalog, pg_temp;
69+
70+
CREATE OR REPLACE FUNCTION pg_temp.check_cagg_chunk_interval() RETURNS void LANGUAGE plpgsql AS
71+
$$
72+
DECLARE
73+
v_cagg regclass;
74+
v_cagg_width text;
75+
v_chunk_width text;
76+
BEGIN
77+
FOR v_cagg, v_chunk_width, v_cagg_width IN
78+
SELECT
79+
format('%I.%I', c.user_view_schema, c.user_view_name)::regclass AS continuous_aggregate,
80+
CASE
81+
WHEN d.column_type =ANY('{int4,int8}'::regtype[]) THEN d.interval_length::text
82+
WHEN d.column_type =ANY('{timestamp,timestamptz}'::regtype[]) THEN _timescaledb_functions.to_interval(d.interval_length)::text
83+
END AS chunk_width,
84+
f.bucket_width cagg_width
85+
FROM _timescaledb_catalog.continuous_agg c
86+
JOIN _timescaledb_catalog.continuous_aggs_bucket_function f ON f.mat_hypertable_id=c.mat_hypertable_id
87+
JOIN _timescaledb_catalog.dimension d ON d.hypertable_id=c.mat_hypertable_id
88+
WHERE
89+
CASE
90+
WHEN d.column_type =ANY('{int4,int8}'::regtype[]) THEN d.interval_length <= f.bucket_width::int
91+
WHEN d.column_type =ANY('{timestamp,timestamptz}'::regtype[]) THEN _timescaledb_functions.to_interval(d.interval_length) <= f.bucket_width::interval
92+
END
93+
LOOP
94+
RAISE WARNING 'Continuous aggregate % has chunk width smaller than bucket width % <= %', v_cagg, v_chunk_width, v_cagg_width;
6695
END LOOP;
6796
END
6897
$$ SET search_path = pg_catalog, pg_temp;
@@ -169,6 +198,7 @@ BEGIN
169198
PERFORM pg_temp.check_job_failures();
170199
PERFORM pg_temp.check_compressed_chunk_batch_sizes();
171200
PERFORM pg_temp.check_cagg_large_materialization_range();
201+
PERFORM pg_temp.check_cagg_chunk_interval();
172202
END
173203
$$ SET search_path = pg_catalog, pg_temp;
174204

0 commit comments

Comments
 (0)