fix: use WITH NO DATA for continuous aggregates to avoid transaction block error
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
-- flyway:executeInTransaction=false
|
||||
|
||||
-- Global stats
|
||||
CREATE MATERIALIZED VIEW stats_1m_all
|
||||
WITH (timescaledb.continuous) AS
|
||||
WITH (timescaledb.continuous, timescaledb.materialized_only = false) AS
|
||||
SELECT
|
||||
time_bucket('1 minute', start_time) AS bucket,
|
||||
COUNT(*) AS total_count,
|
||||
@@ -13,7 +11,8 @@ SELECT
|
||||
approx_percentile(0.99, percentile_agg(duration_ms::DOUBLE PRECISION)) AS p99_duration
|
||||
FROM executions
|
||||
WHERE status IS NOT NULL
|
||||
GROUP BY bucket;
|
||||
GROUP BY bucket
|
||||
WITH NO DATA;
|
||||
|
||||
SELECT add_continuous_aggregate_policy('stats_1m_all',
|
||||
start_offset => INTERVAL '1 hour',
|
||||
@@ -22,7 +21,7 @@ SELECT add_continuous_aggregate_policy('stats_1m_all',
|
||||
|
||||
-- Per-application stats
|
||||
CREATE MATERIALIZED VIEW stats_1m_app
|
||||
WITH (timescaledb.continuous) AS
|
||||
WITH (timescaledb.continuous, timescaledb.materialized_only = false) AS
|
||||
SELECT
|
||||
time_bucket('1 minute', start_time) AS bucket,
|
||||
group_name,
|
||||
@@ -34,7 +33,8 @@ SELECT
|
||||
approx_percentile(0.99, percentile_agg(duration_ms::DOUBLE PRECISION)) AS p99_duration
|
||||
FROM executions
|
||||
WHERE status IS NOT NULL
|
||||
GROUP BY bucket, group_name;
|
||||
GROUP BY bucket, group_name
|
||||
WITH NO DATA;
|
||||
|
||||
SELECT add_continuous_aggregate_policy('stats_1m_app',
|
||||
start_offset => INTERVAL '1 hour',
|
||||
@@ -43,7 +43,7 @@ SELECT add_continuous_aggregate_policy('stats_1m_app',
|
||||
|
||||
-- Per-route stats
|
||||
CREATE MATERIALIZED VIEW stats_1m_route
|
||||
WITH (timescaledb.continuous) AS
|
||||
WITH (timescaledb.continuous, timescaledb.materialized_only = false) AS
|
||||
SELECT
|
||||
time_bucket('1 minute', start_time) AS bucket,
|
||||
group_name,
|
||||
@@ -56,7 +56,8 @@ SELECT
|
||||
approx_percentile(0.99, percentile_agg(duration_ms::DOUBLE PRECISION)) AS p99_duration
|
||||
FROM executions
|
||||
WHERE status IS NOT NULL
|
||||
GROUP BY bucket, group_name, route_id;
|
||||
GROUP BY bucket, group_name, route_id
|
||||
WITH NO DATA;
|
||||
|
||||
SELECT add_continuous_aggregate_policy('stats_1m_route',
|
||||
start_offset => INTERVAL '1 hour',
|
||||
@@ -65,7 +66,7 @@ SELECT add_continuous_aggregate_policy('stats_1m_route',
|
||||
|
||||
-- Per-processor stats (uses denormalized group_name/route_id on processor_executions)
|
||||
CREATE MATERIALIZED VIEW stats_1m_processor
|
||||
WITH (timescaledb.continuous) AS
|
||||
WITH (timescaledb.continuous, timescaledb.materialized_only = false) AS
|
||||
SELECT
|
||||
time_bucket('1 minute', start_time) AS bucket,
|
||||
group_name,
|
||||
@@ -77,7 +78,8 @@ SELECT
|
||||
MAX(duration_ms) AS duration_max,
|
||||
approx_percentile(0.99, percentile_agg(duration_ms::DOUBLE PRECISION)) AS p99_duration
|
||||
FROM processor_executions
|
||||
GROUP BY bucket, group_name, route_id, processor_type;
|
||||
GROUP BY bucket, group_name, route_id, processor_type
|
||||
WITH NO DATA;
|
||||
|
||||
SELECT add_continuous_aggregate_policy('stats_1m_processor',
|
||||
start_offset => INTERVAL '1 hour',
|
||||
|
||||
Reference in New Issue
Block a user