diff --git a/.unreleased/bugfix_5734 b/.unreleased/bugfix_5734 new file mode 100644 index 00000000000..17415ae00b2 --- /dev/null +++ b/.unreleased/bugfix_5734 @@ -0,0 +1,5 @@ +Implements: #5860 Rectifies interval calculation for Heirarchical CAggs + +Fixes: #5734 + +Thanks: @lukaskirner diff --git a/test/sql/updates/post.repair.hierarchical_cagg.sql b/test/sql/updates/post.repair.hierarchical_cagg.sql new file mode 100644 index 00000000000..1bddea73dae --- /dev/null +++ b/test/sql/updates/post.repair.hierarchical_cagg.sql @@ -0,0 +1,6 @@ +-- This file and its contents are licensed under the Apache License 2.0. +-- Please see the included NOTICE for copyright information and +-- LICENSE-APACHE for a copy of the license. + +SELECT count(*) FROM agg_test_monthly; + diff --git a/test/sql/updates/post.repair.sql b/test/sql/updates/post.repair.sql index 2de4689877b..b63c7b64cf7 100644 --- a/test/sql/updates/post.repair.sql +++ b/test/sql/updates/post.repair.sql @@ -20,6 +20,7 @@ WHERE extname = 'timescaledb' \gset \if :test_repair_cagg_joins --Check if the repaired cagg with joins work alright now -\ir post.repair.cagg_joins.sql + \ir post.repair.cagg_joins.sql + \ir post.repair.hierarchical_cagg.sql \endif diff --git a/test/sql/updates/setup.repair.hierarchical_cagg.sql b/test/sql/updates/setup.repair.hierarchical_cagg.sql new file mode 100644 index 00000000000..6419ea882f5 --- /dev/null +++ b/test/sql/updates/setup.repair.hierarchical_cagg.sql @@ -0,0 +1,46 @@ +-- This file and its contents are licensed under the Apache License 2.0. +-- Please see the included NOTICE for copyright information and +-- LICENSE-APACHE for a copy of the license. + +CREATE TABLE test ( + timestamp TIMESTAMPTZ NOT NULL, + device_id TEXT NOT NULL, + value INT NOT NULL, + + CONSTRAINT uk_test_timestamp_device_id UNIQUE (timestamp, device_id) +); + +SELECT create_hypertable('test', 'timestamp'); + +INSERT INTO test (timestamp, device_id, value) VALUES + ('2023-05-01 00:00:00+00', 'sensor0', 1), + ('2023-05-15 00:00:00+00', 'sensor0', 2), + ('2023-05-31 00:00:00+00', 'sensor0', 10); + + +CREATE MATERIALIZED VIEW agg_test_hourly WITH (timescaledb.continuous) AS + SELECT + time_bucket('1 hour'::interval, timestamp) AS hour_timestamp, + device_id, + SUM(value) + FROM test + GROUP BY hour_timestamp, device_id +WITH DATA; + +CREATE MATERIALIZED VIEW agg_test_daily WITH (timescaledb.continuous) AS + SELECT + time_bucket('1 day'::interval, hour_timestamp) AS day_timestamp, + device_id, + SUM(sum) + FROM agg_test_hourly + GROUP BY day_timestamp, device_id +WITH DATA; + +CREATE MATERIALIZED VIEW agg_test_monthly WITH (timescaledb.continuous) AS + SELECT + time_bucket('1 month'::interval, day_timestamp) AS month_timestamp, + device_id, + SUM(sum) + FROM agg_test_daily + GROUP BY month_timestamp, device_id +WITH DATA; diff --git a/test/sql/updates/setup.repair.sql b/test/sql/updates/setup.repair.sql index 738d465e4ad..39bd00dd853 100644 --- a/test/sql/updates/setup.repair.sql +++ b/test/sql/updates/setup.repair.sql @@ -189,7 +189,7 @@ DROP VIEW slices; \endif \ir setup.repair.cagg.sql - \if :has_cagg_joins + \ir setup.repair.hierarchical_cagg.sql \ir setup.repair.cagg_joins.sql \endif diff --git a/tsl/src/continuous_aggs/common.c b/tsl/src/continuous_aggs/common.c index fce510dfe0e..2678f2293f9 100644 --- a/tsl/src/continuous_aggs/common.c +++ b/tsl/src/continuous_aggs/common.c @@ -582,21 +582,26 @@ get_bucket_width(CAggTimebucketInfo bucket_info) break; case INTERVALOID: { + /* + * Original interval should not be changed, hence create a local copy + * for this check. + */ + Interval interval = { .time = bucket_info.interval->time, + .day = bucket_info.interval->day, + .month = bucket_info.interval->month }; + /* * epoch will treat year as 365.25 days. This leads to the unexpected * result that year is not multiple of day or month, which is perceived * as a bug. For that reason, we treat all months as 30 days regardless of year */ - if (bucket_info.interval->month && !bucket_info.interval->day && - !bucket_info.interval->time) + if (interval.month && !interval.day && !interval.time) { - bucket_info.interval->day = bucket_info.interval->month * DAYS_PER_MONTH; - bucket_info.interval->month = 0; + interval.day = interval.month * DAYS_PER_MONTH; + interval.month = 0; } - /* Convert Interval to int64 */ - width = - ts_interval_value_to_internal(IntervalPGetDatum(bucket_info.interval), INTERVALOID); + width = ts_interval_value_to_internal(IntervalPGetDatum(&interval), INTERVALOID); break; } default: diff --git a/tsl/test/expected/cagg_on_cagg.out b/tsl/test/expected/cagg_on_cagg.out index 1dc0871ddde..1120d8c7031 100644 --- a/tsl/test/expected/cagg_on_cagg.out +++ b/tsl/test/expected/cagg_on_cagg.out @@ -6,6 +6,7 @@ \set IS_TIME_DIMENSION_WITH_TIMEZONE_1ST FALSE \set IS_TIME_DIMENSION_WITH_TIMEZONE_2TH FALSE \set IS_JOIN FALSE +\set INTERVAL_TEST FALSE -- ######################################################## -- ## INTEGER data type tests -- ######################################################## @@ -868,6 +869,7 @@ psql:include/cagg_on_cagg_common.sql:200: ERROR: relation "conditions_summary_1 -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -920,16 +922,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [5] should be multiple of the time bucket width of "public.conditions_summary_1" [2]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- -- Validation test for equal bucket sizes @@ -943,6 +968,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -1013,6 +1039,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.cagg_watermark(11)::integer, '-2147483648'::integer) GROUP BY (time_bucket(2, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -1032,6 +1081,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -1084,16 +1134,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [2] should be greater or equal than the time bucket width of "public.conditions_summary_1" [4]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- ######################################################## -- ## TIMESTAMP data type tests @@ -1949,6 +2022,7 @@ psql:include/cagg_on_cagg_common.sql:200: ERROR: relation "conditions_summary_1 -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -2001,17 +2075,40 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with fixed-width bucket on top of one using variable-width bucket +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with fixed-width bucket on top of one using variable-width bucket DETAIL: Continuous aggregate with a fixed time bucket width (e.g. 61 days) cannot be created on top of one using variable time bucket width (e.g. 1 month). The variance can lead to the fixed width one not being a multiple of the variable width one. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- -- Validation test for non-multiple bucket sizes @@ -2025,6 +2122,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -2077,16 +2175,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [@ 3 hours] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 2 hours]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- -- Validation test for equal bucket sizes @@ -2100,6 +2221,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -2170,6 +2292,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp_without_timezone(_timescaledb_internal.cagg_watermark(24)), '-infinity'::timestamp without time zone) GROUP BY (time_bucket('@ 1 hour'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -2189,6 +2334,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -2241,16 +2387,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [@ 1 hour] should be greater or equal than the time bucket width of "public.conditions_summary_1" [@ 2 hours]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- ######################################################## -- ## TIMESTAMPTZ data type tests @@ -3104,6 +3273,7 @@ psql:include/cagg_on_cagg_common.sql:200: ERROR: relation "conditions_summary_1 -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3156,17 +3326,40 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with fixed-width bucket on top of one using variable-width bucket +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with fixed-width bucket on top of one using variable-width bucket DETAIL: Continuous aggregate with a fixed time bucket width (e.g. 61 days) cannot be created on top of one using variable time bucket width (e.g. 1 month). The variance can lead to the fixed width one not being a multiple of the variable width one. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- -- Validation test for non-multiple bucket sizes @@ -3180,6 +3373,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3232,16 +3426,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [@ 3 hours] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 2 hours]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- -- Validation test for equal bucket sizes @@ -3255,6 +3472,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3325,6 +3543,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(37)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 hour'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -3344,6 +3585,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3396,16 +3638,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [@ 1 hour] should be greater or equal than the time bucket width of "public.conditions_summary_1" [@ 2 hours]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- -- Validations using time bucket with timezone (ref issue #5126) @@ -3426,6 +3691,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3496,6 +3762,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(40)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 hour'::interval, conditions_summary_1.bucket, 'US/Pacific'::text)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -3512,6 +3801,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3564,16 +3854,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [@ 16 mins] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 5 mins]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- -- Variable bucket size with the same timezones @@ -3589,6 +3902,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3659,6 +3973,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(43)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 mon'::interval, conditions_summary_1.bucket, 'UTC'::text)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -3666,6 +4003,143 @@ UNION ALL -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; +--#Bugfix 5734 #1 +\set INTERVAL_TEST TRUE +\set BUCKET_WIDTH_1ST 'INTERVAL \'1 hour\'' +\set BUCKET_WIDTH_2TH 'INTERVAL \'1 day\'' +\set BUCKET_WIDTH_3TH 'INTERVAL \'1 month\'' +\ir include/cagg_on_cagg_validations.sql +-- 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. +\set CAGG_NAME_1ST_LEVEL conditions_summary_1 +\set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 +-- +-- CAGG on hypertable (1st level) +-- +CREATE MATERIALIZED VIEW :CAGG_NAME_1ST_LEVEL +WITH (timescaledb.continuous) AS +SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_1ST + time_bucket(:BUCKET_WIDTH_1ST, "time", :'BUCKET_TZNAME_1ST') AS bucket, + \else + time_bucket(:BUCKET_WIDTH_1ST, "time") AS bucket, + \endif + SUM(temperature) AS temperature +FROM conditions +GROUP BY 1 +WITH NO DATA; +\d+ :CAGG_NAME_1ST_LEVEL + View "public.conditions_summary_1" + Column | Type | Collation | Nullable | Default | Storage | Description +-------------+--------------------------+-----------+----------+---------+---------+------------- + bucket | timestamp with time zone | | | | plain | + temperature | numeric | | | | main | +View definition: + SELECT _materialized_hypertable_44.bucket, + _materialized_hypertable_44.temperature + FROM _timescaledb_internal._materialized_hypertable_44 + WHERE _materialized_hypertable_44.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(44)), '-infinity'::timestamp with time zone) +UNION ALL + SELECT time_bucket('@ 1 hour'::interval, conditions."time", 'UTC'::text) AS bucket, + sum(conditions.temperature) AS temperature + FROM conditions + WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(44)), '-infinity'::timestamp with time zone) + GROUP BY (time_bucket('@ 1 hour'::interval, conditions."time", 'UTC'::text)); + +-- +-- CAGG on CAGG (2th level) +-- +\set VERBOSITY default +\set ON_ERROR_STOP 0 +\echo :WARNING_MESSAGE +-- SHOULD WORK +CREATE MATERIALIZED VIEW :CAGG_NAME_2TH_LEVEL +WITH (timescaledb.continuous) AS +SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_2TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket, + \else + time_bucket(:BUCKET_WIDTH_2TH, "bucket") AS bucket, + \endif + SUM(temperature) AS temperature +FROM :CAGG_NAME_1ST_LEVEL +GROUP BY 1 +WITH NO DATA; +\d+ :CAGG_NAME_2TH_LEVEL + View "public.conditions_summary_2" + Column | Type | Collation | Nullable | Default | Storage | Description +-------------+--------------------------+-----------+----------+---------+---------+------------- + bucket | timestamp with time zone | | | | plain | + temperature | numeric | | | | main | +View definition: + SELECT _materialized_hypertable_45.bucket, + _materialized_hypertable_45.temperature + FROM _timescaledb_internal._materialized_hypertable_45 + WHERE _materialized_hypertable_45.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(45)), '-infinity'::timestamp with time zone) +UNION ALL + SELECT time_bucket('@ 1 day'::interval, conditions_summary_1.bucket, 'UTC'::text) AS bucket, + sum(conditions_summary_1.temperature) AS temperature + FROM conditions_summary_1 + WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(45)), '-infinity'::timestamp with time zone) + GROUP BY (time_bucket('@ 1 day'::interval, conditions_summary_1.bucket, 'UTC'::text)); + +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; +psql:include/cagg_on_cagg_validations.sql:68: NOTICE: refreshing continuous aggregate "conditions_summary_3" +HINT: Use WITH NO DATA if you do not want to refresh the continuous aggregate on creation. + \d+ :CAGG_NAME_3TH_LEVEL + View "public.conditions_summary_3" + Column | Type | Collation | Nullable | Default | Storage | Description +--------+--------------------------+-----------+----------+---------+---------+------------- + bucket | timestamp with time zone | | | | plain | +View definition: + SELECT _materialized_hypertable_46.bucket + FROM _timescaledb_internal._materialized_hypertable_46 + WHERE _materialized_hypertable_46.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(46)), '-infinity'::timestamp with time zone) +UNION ALL + SELECT time_bucket('@ 1 mon'::interval, conditions_summary_2.bucket, 'UTC'::text) AS bucket + FROM conditions_summary_2 + WHERE conditions_summary_2.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(46)), '-infinity'::timestamp with time zone) + GROUP BY (time_bucket('@ 1 mon'::interval, conditions_summary_2.bucket, 'UTC'::text)); + + SELECT * from :CAGG_NAME_3TH_LEVEL; + bucket +------------------------------ + Sat Jan 01 00:00:00 2022 UTC +(1 row) + + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; +psql:include/cagg_on_cagg_validations.sql:73: NOTICE: drop cascades to table _timescaledb_internal._hyper_46_31_chunk + DELETE FROM conditions WHERE device_id = 4; +\endif +\set ON_ERROR_STOP 1 +\set VERBOSITY terse +-- +-- Cleanup +-- +DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: drop cascades to table _timescaledb_internal._hyper_45_30_chunk +DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; +psql:include/cagg_on_cagg_validations.sql:84: NOTICE: drop cascades to table _timescaledb_internal._hyper_44_29_chunk +\set INTERVAL_TEST FALSE -- -- Variable bucket size with different timezones -- @@ -3680,6 +4154,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3702,15 +4177,15 @@ WITH NO DATA; bucket | timestamp with time zone | | | | plain | temperature | numeric | | | | main | View definition: - SELECT _materialized_hypertable_44.bucket, - _materialized_hypertable_44.temperature - FROM _timescaledb_internal._materialized_hypertable_44 - WHERE _materialized_hypertable_44.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(44)), '-infinity'::timestamp with time zone) + SELECT _materialized_hypertable_47.bucket, + _materialized_hypertable_47.temperature + FROM _timescaledb_internal._materialized_hypertable_47 + WHERE _materialized_hypertable_47.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(47)), '-infinity'::timestamp with time zone) UNION ALL SELECT time_bucket('@ 1 day'::interval, conditions."time", 'US/Pacific'::text) AS bucket, sum(conditions.temperature) AS temperature FROM conditions - WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(44)), '-infinity'::timestamp with time zone) + WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(47)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 day'::interval, conditions."time", 'US/Pacific'::text)); -- @@ -3739,17 +4214,40 @@ WITH NO DATA; bucket | timestamp with time zone | | | | plain | temperature | numeric | | | | main | View definition: - SELECT _materialized_hypertable_45.bucket, - _materialized_hypertable_45.temperature - FROM _timescaledb_internal._materialized_hypertable_45 - WHERE _materialized_hypertable_45.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(45)), '-infinity'::timestamp with time zone) + SELECT _materialized_hypertable_48.bucket, + _materialized_hypertable_48.temperature + FROM _timescaledb_internal._materialized_hypertable_48 + WHERE _materialized_hypertable_48.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(48)), '-infinity'::timestamp with time zone) UNION ALL SELECT time_bucket('@ 1 mon'::interval, conditions_summary_1.bucket, 'UTC'::text) AS bucket, sum(conditions_summary_1.temperature) AS temperature FROM conditions_summary_1 - WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(45)), '-infinity'::timestamp with time zone) + WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(48)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 mon'::interval, conditions_summary_1.bucket, 'UTC'::text)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -3757,6 +4255,143 @@ UNION ALL -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; +--#Bugfix 5734 #2 +\set INTERVAL_TEST TRUE +\set BUCKET_WIDTH_1ST 'INTERVAL \'1 hour\'' +\set BUCKET_WIDTH_2TH 'INTERVAL \'1 day\'' +\set BUCKET_WIDTH_3TH 'INTERVAL \'1 month\'' +\ir include/cagg_on_cagg_validations.sql +-- 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. +\set CAGG_NAME_1ST_LEVEL conditions_summary_1 +\set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 +-- +-- CAGG on hypertable (1st level) +-- +CREATE MATERIALIZED VIEW :CAGG_NAME_1ST_LEVEL +WITH (timescaledb.continuous) AS +SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_1ST + time_bucket(:BUCKET_WIDTH_1ST, "time", :'BUCKET_TZNAME_1ST') AS bucket, + \else + time_bucket(:BUCKET_WIDTH_1ST, "time") AS bucket, + \endif + SUM(temperature) AS temperature +FROM conditions +GROUP BY 1 +WITH NO DATA; +\d+ :CAGG_NAME_1ST_LEVEL + View "public.conditions_summary_1" + Column | Type | Collation | Nullable | Default | Storage | Description +-------------+--------------------------+-----------+----------+---------+---------+------------- + bucket | timestamp with time zone | | | | plain | + temperature | numeric | | | | main | +View definition: + SELECT _materialized_hypertable_49.bucket, + _materialized_hypertable_49.temperature + FROM _timescaledb_internal._materialized_hypertable_49 + WHERE _materialized_hypertable_49.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(49)), '-infinity'::timestamp with time zone) +UNION ALL + SELECT time_bucket('@ 1 hour'::interval, conditions."time", 'US/Pacific'::text) AS bucket, + sum(conditions.temperature) AS temperature + FROM conditions + WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(49)), '-infinity'::timestamp with time zone) + GROUP BY (time_bucket('@ 1 hour'::interval, conditions."time", 'US/Pacific'::text)); + +-- +-- CAGG on CAGG (2th level) +-- +\set VERBOSITY default +\set ON_ERROR_STOP 0 +\echo :WARNING_MESSAGE +-- SHOULD WORK +CREATE MATERIALIZED VIEW :CAGG_NAME_2TH_LEVEL +WITH (timescaledb.continuous) AS +SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_2TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket, + \else + time_bucket(:BUCKET_WIDTH_2TH, "bucket") AS bucket, + \endif + SUM(temperature) AS temperature +FROM :CAGG_NAME_1ST_LEVEL +GROUP BY 1 +WITH NO DATA; +\d+ :CAGG_NAME_2TH_LEVEL + View "public.conditions_summary_2" + Column | Type | Collation | Nullable | Default | Storage | Description +-------------+--------------------------+-----------+----------+---------+---------+------------- + bucket | timestamp with time zone | | | | plain | + temperature | numeric | | | | main | +View definition: + SELECT _materialized_hypertable_50.bucket, + _materialized_hypertable_50.temperature + FROM _timescaledb_internal._materialized_hypertable_50 + WHERE _materialized_hypertable_50.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(50)), '-infinity'::timestamp with time zone) +UNION ALL + SELECT time_bucket('@ 1 day'::interval, conditions_summary_1.bucket, 'UTC'::text) AS bucket, + sum(conditions_summary_1.temperature) AS temperature + FROM conditions_summary_1 + WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(50)), '-infinity'::timestamp with time zone) + GROUP BY (time_bucket('@ 1 day'::interval, conditions_summary_1.bucket, 'UTC'::text)); + +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; +psql:include/cagg_on_cagg_validations.sql:68: NOTICE: refreshing continuous aggregate "conditions_summary_3" +HINT: Use WITH NO DATA if you do not want to refresh the continuous aggregate on creation. + \d+ :CAGG_NAME_3TH_LEVEL + View "public.conditions_summary_3" + Column | Type | Collation | Nullable | Default | Storage | Description +--------+--------------------------+-----------+----------+---------+---------+------------- + bucket | timestamp with time zone | | | | plain | +View definition: + SELECT _materialized_hypertable_51.bucket + FROM _timescaledb_internal._materialized_hypertable_51 + WHERE _materialized_hypertable_51.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(51)), '-infinity'::timestamp with time zone) +UNION ALL + SELECT time_bucket('@ 1 mon'::interval, conditions_summary_2.bucket, 'UTC'::text) AS bucket + FROM conditions_summary_2 + WHERE conditions_summary_2.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(51)), '-infinity'::timestamp with time zone) + GROUP BY (time_bucket('@ 1 mon'::interval, conditions_summary_2.bucket, 'UTC'::text)); + + SELECT * from :CAGG_NAME_3TH_LEVEL; + bucket +------------------------------ + Sat Jan 01 00:00:00 2022 UTC +(1 row) + + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; +psql:include/cagg_on_cagg_validations.sql:73: NOTICE: drop cascades to table _timescaledb_internal._hyper_51_34_chunk + DELETE FROM conditions WHERE device_id = 4; +\endif +\set ON_ERROR_STOP 1 +\set VERBOSITY terse +-- +-- Cleanup +-- +DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: drop cascades to table _timescaledb_internal._hyper_50_33_chunk +DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; +psql:include/cagg_on_cagg_validations.sql:84: NOTICE: drop cascades to table _timescaledb_internal._hyper_49_32_chunk +\set INTERVAL_TEST FALSE -- -- TZ bucket on top of non-TZ bucket -- @@ -3772,6 +4407,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3794,15 +4430,15 @@ WITH NO DATA; bucket | timestamp with time zone | | | | plain | temperature | numeric | | | | main | View definition: - SELECT _materialized_hypertable_46.bucket, - _materialized_hypertable_46.temperature - FROM _timescaledb_internal._materialized_hypertable_46 - WHERE _materialized_hypertable_46.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(46)), '-infinity'::timestamp with time zone) + SELECT _materialized_hypertable_52.bucket, + _materialized_hypertable_52.temperature + FROM _timescaledb_internal._materialized_hypertable_52 + WHERE _materialized_hypertable_52.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(52)), '-infinity'::timestamp with time zone) UNION ALL SELECT time_bucket('@ 1 day'::interval, conditions."time") AS bucket, sum(conditions.temperature) AS temperature FROM conditions - WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(46)), '-infinity'::timestamp with time zone) + WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(52)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 day'::interval, conditions."time")); -- @@ -3831,24 +4467,184 @@ WITH NO DATA; bucket | timestamp with time zone | | | | plain | temperature | numeric | | | | main | View definition: - SELECT _materialized_hypertable_47.bucket, - _materialized_hypertable_47.temperature - FROM _timescaledb_internal._materialized_hypertable_47 - WHERE _materialized_hypertable_47.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(47)), '-infinity'::timestamp with time zone) + SELECT _materialized_hypertable_53.bucket, + _materialized_hypertable_53.temperature + FROM _timescaledb_internal._materialized_hypertable_53 + WHERE _materialized_hypertable_53.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(53)), '-infinity'::timestamp with time zone) UNION ALL SELECT time_bucket('@ 1 mon'::interval, conditions_summary_1.bucket, 'UTC'::text) AS bucket, sum(conditions_summary_1.temperature) AS temperature FROM conditions_summary_1 - WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(47)), '-infinity'::timestamp with time zone) + WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(53)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 mon'::interval, conditions_summary_1.bucket, 'UTC'::text)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif +\set ON_ERROR_STOP 1 +\set VERBOSITY terse +-- +-- Cleanup +-- +DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; +DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; +--#Bugfix 5734 #3 +\set INTERVAL_TEST TRUE +\set BUCKET_WIDTH_1ST 'INTERVAL \'1 hour\'' +\set BUCKET_WIDTH_2TH 'INTERVAL \'1 day\'' +\set BUCKET_WIDTH_3TH 'INTERVAL \'1 month\'' +\ir include/cagg_on_cagg_validations.sql +-- 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. +\set CAGG_NAME_1ST_LEVEL conditions_summary_1 +\set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 +-- +-- CAGG on hypertable (1st level) +-- +CREATE MATERIALIZED VIEW :CAGG_NAME_1ST_LEVEL +WITH (timescaledb.continuous) AS +SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_1ST + time_bucket(:BUCKET_WIDTH_1ST, "time", :'BUCKET_TZNAME_1ST') AS bucket, + \else + time_bucket(:BUCKET_WIDTH_1ST, "time") AS bucket, + \endif + SUM(temperature) AS temperature +FROM conditions +GROUP BY 1 +WITH NO DATA; +\d+ :CAGG_NAME_1ST_LEVEL + View "public.conditions_summary_1" + Column | Type | Collation | Nullable | Default | Storage | Description +-------------+--------------------------+-----------+----------+---------+---------+------------- + bucket | timestamp with time zone | | | | plain | + temperature | numeric | | | | main | +View definition: + SELECT _materialized_hypertable_54.bucket, + _materialized_hypertable_54.temperature + FROM _timescaledb_internal._materialized_hypertable_54 + WHERE _materialized_hypertable_54.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(54)), '-infinity'::timestamp with time zone) +UNION ALL + SELECT time_bucket('@ 1 hour'::interval, conditions."time") AS bucket, + sum(conditions.temperature) AS temperature + FROM conditions + WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(54)), '-infinity'::timestamp with time zone) + GROUP BY (time_bucket('@ 1 hour'::interval, conditions."time")); + +-- +-- CAGG on CAGG (2th level) +-- +\set VERBOSITY default +\set ON_ERROR_STOP 0 +\echo :WARNING_MESSAGE +-- SHOULD WORK +CREATE MATERIALIZED VIEW :CAGG_NAME_2TH_LEVEL +WITH (timescaledb.continuous) AS +SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_2TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket, + \else + time_bucket(:BUCKET_WIDTH_2TH, "bucket") AS bucket, + \endif + SUM(temperature) AS temperature +FROM :CAGG_NAME_1ST_LEVEL +GROUP BY 1 +WITH NO DATA; +\d+ :CAGG_NAME_2TH_LEVEL + View "public.conditions_summary_2" + Column | Type | Collation | Nullable | Default | Storage | Description +-------------+--------------------------+-----------+----------+---------+---------+------------- + bucket | timestamp with time zone | | | | plain | + temperature | numeric | | | | main | +View definition: + SELECT _materialized_hypertable_55.bucket, + _materialized_hypertable_55.temperature + FROM _timescaledb_internal._materialized_hypertable_55 + WHERE _materialized_hypertable_55.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(55)), '-infinity'::timestamp with time zone) +UNION ALL + SELECT time_bucket('@ 1 day'::interval, conditions_summary_1.bucket, 'UTC'::text) AS bucket, + sum(conditions_summary_1.temperature) AS temperature + FROM conditions_summary_1 + WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(55)), '-infinity'::timestamp with time zone) + GROUP BY (time_bucket('@ 1 day'::interval, conditions_summary_1.bucket, 'UTC'::text)); + +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; +psql:include/cagg_on_cagg_validations.sql:68: NOTICE: refreshing continuous aggregate "conditions_summary_3" +HINT: Use WITH NO DATA if you do not want to refresh the continuous aggregate on creation. + \d+ :CAGG_NAME_3TH_LEVEL + View "public.conditions_summary_3" + Column | Type | Collation | Nullable | Default | Storage | Description +--------+--------------------------+-----------+----------+---------+---------+------------- + bucket | timestamp with time zone | | | | plain | +View definition: + SELECT _materialized_hypertable_56.bucket + FROM _timescaledb_internal._materialized_hypertable_56 + WHERE _materialized_hypertable_56.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(56)), '-infinity'::timestamp with time zone) +UNION ALL + SELECT time_bucket('@ 1 mon'::interval, conditions_summary_2.bucket, 'UTC'::text) AS bucket + FROM conditions_summary_2 + WHERE conditions_summary_2.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(56)), '-infinity'::timestamp with time zone) + GROUP BY (time_bucket('@ 1 mon'::interval, conditions_summary_2.bucket, 'UTC'::text)); + + SELECT * from :CAGG_NAME_3TH_LEVEL; + bucket +------------------------------ + Sat Jan 01 00:00:00 2022 UTC +(1 row) + + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; +psql:include/cagg_on_cagg_validations.sql:73: NOTICE: drop cascades to table _timescaledb_internal._hyper_56_37_chunk + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: drop cascades to table _timescaledb_internal._hyper_55_36_chunk DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; +psql:include/cagg_on_cagg_validations.sql:84: NOTICE: drop cascades to table _timescaledb_internal._hyper_54_35_chunk +\set INTERVAL_TEST FALSE -- -- non-TZ bucket on top of TZ bucket -- @@ -3864,6 +4660,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3886,15 +4683,15 @@ WITH NO DATA; bucket | timestamp with time zone | | | | plain | temperature | numeric | | | | main | View definition: - SELECT _materialized_hypertable_48.bucket, - _materialized_hypertable_48.temperature - FROM _timescaledb_internal._materialized_hypertable_48 - WHERE _materialized_hypertable_48.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(48)), '-infinity'::timestamp with time zone) + SELECT _materialized_hypertable_57.bucket, + _materialized_hypertable_57.temperature + FROM _timescaledb_internal._materialized_hypertable_57 + WHERE _materialized_hypertable_57.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(57)), '-infinity'::timestamp with time zone) UNION ALL SELECT time_bucket('@ 1 day'::interval, conditions."time", 'UTC'::text) AS bucket, sum(conditions.temperature) AS temperature FROM conditions - WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(48)), '-infinity'::timestamp with time zone) + WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(57)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 day'::interval, conditions."time", 'UTC'::text)); -- @@ -3923,17 +4720,40 @@ WITH NO DATA; bucket | timestamp with time zone | | | | plain | temperature | numeric | | | | main | View definition: - SELECT _materialized_hypertable_49.bucket, - _materialized_hypertable_49.temperature - FROM _timescaledb_internal._materialized_hypertable_49 - WHERE _materialized_hypertable_49.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(49)), '-infinity'::timestamp with time zone) + SELECT _materialized_hypertable_58.bucket, + _materialized_hypertable_58.temperature + FROM _timescaledb_internal._materialized_hypertable_58 + WHERE _materialized_hypertable_58.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(58)), '-infinity'::timestamp with time zone) UNION ALL SELECT time_bucket('@ 1 mon'::interval, conditions_summary_1.bucket) AS bucket, sum(conditions_summary_1.temperature) AS temperature FROM conditions_summary_1 - WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(49)), '-infinity'::timestamp with time zone) + WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(58)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 mon'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -3955,6 +4775,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3977,15 +4798,15 @@ WITH NO DATA; bucket | timestamp with time zone | | | | plain | temperature | numeric | | | | main | View definition: - SELECT _materialized_hypertable_50.bucket, - _materialized_hypertable_50.temperature - FROM _timescaledb_internal._materialized_hypertable_50 - WHERE _materialized_hypertable_50.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(50)), '-infinity'::timestamp with time zone) + SELECT _materialized_hypertable_59.bucket, + _materialized_hypertable_59.temperature + FROM _timescaledb_internal._materialized_hypertable_59 + WHERE _materialized_hypertable_59.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(59)), '-infinity'::timestamp with time zone) UNION ALL SELECT time_bucket('@ 1 day'::interval, conditions."time", 'UTC'::text) AS bucket, sum(conditions.temperature) AS temperature FROM conditions - WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(50)), '-infinity'::timestamp with time zone) + WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(59)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 day'::interval, conditions."time", 'UTC'::text)); -- @@ -4014,17 +4835,40 @@ WITH NO DATA; bucket | timestamp with time zone | | | | plain | temperature | numeric | | | | main | View definition: - SELECT _materialized_hypertable_51.bucket, - _materialized_hypertable_51.temperature - FROM _timescaledb_internal._materialized_hypertable_51 - WHERE _materialized_hypertable_51.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(51)), '-infinity'::timestamp with time zone) + SELECT _materialized_hypertable_60.bucket, + _materialized_hypertable_60.temperature + FROM _timescaledb_internal._materialized_hypertable_60 + WHERE _materialized_hypertable_60.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(60)), '-infinity'::timestamp with time zone) UNION ALL SELECT time_bucket('@ 1 year'::interval, conditions_summary_1.bucket) AS bucket, sum(conditions_summary_1.temperature) AS temperature FROM conditions_summary_1 - WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(51)), '-infinity'::timestamp with time zone) + WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(60)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 year'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -4040,6 +4884,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4062,15 +4907,15 @@ WITH NO DATA; bucket | timestamp with time zone | | | | plain | temperature | numeric | | | | main | View definition: - SELECT _materialized_hypertable_52.bucket, - _materialized_hypertable_52.temperature - FROM _timescaledb_internal._materialized_hypertable_52 - WHERE _materialized_hypertable_52.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(52)), '-infinity'::timestamp with time zone) + SELECT _materialized_hypertable_61.bucket, + _materialized_hypertable_61.temperature + FROM _timescaledb_internal._materialized_hypertable_61 + WHERE _materialized_hypertable_61.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(61)), '-infinity'::timestamp with time zone) UNION ALL SELECT time_bucket('@ 1 day'::interval, conditions."time", 'UTC'::text) AS bucket, sum(conditions.temperature) AS temperature FROM conditions - WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(52)), '-infinity'::timestamp with time zone) + WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(61)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 day'::interval, conditions."time", 'UTC'::text)); -- @@ -4099,17 +4944,40 @@ WITH NO DATA; bucket | timestamp with time zone | | | | plain | temperature | numeric | | | | main | View definition: - SELECT _materialized_hypertable_53.bucket, - _materialized_hypertable_53.temperature - FROM _timescaledb_internal._materialized_hypertable_53 - WHERE _materialized_hypertable_53.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(53)), '-infinity'::timestamp with time zone) + SELECT _materialized_hypertable_62.bucket, + _materialized_hypertable_62.temperature + FROM _timescaledb_internal._materialized_hypertable_62 + WHERE _materialized_hypertable_62.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(62)), '-infinity'::timestamp with time zone) UNION ALL SELECT time_bucket('@ 3 mons'::interval, conditions_summary_1.bucket) AS bucket, sum(conditions_summary_1.temperature) AS temperature FROM conditions_summary_1 - WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(53)), '-infinity'::timestamp with time zone) + WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(62)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 3 mons'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -4125,6 +4993,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4147,15 +5016,15 @@ WITH NO DATA; bucket | timestamp with time zone | | | | plain | temperature | numeric | | | | main | View definition: - SELECT _materialized_hypertable_54.bucket, - _materialized_hypertable_54.temperature - FROM _timescaledb_internal._materialized_hypertable_54 - WHERE _materialized_hypertable_54.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(54)), '-infinity'::timestamp with time zone) + SELECT _materialized_hypertable_63.bucket, + _materialized_hypertable_63.temperature + FROM _timescaledb_internal._materialized_hypertable_63 + WHERE _materialized_hypertable_63.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(63)), '-infinity'::timestamp with time zone) UNION ALL SELECT time_bucket('@ 1 mon'::interval, conditions."time", 'UTC'::text) AS bucket, sum(conditions.temperature) AS temperature FROM conditions - WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(54)), '-infinity'::timestamp with time zone) + WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(63)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 mon'::interval, conditions."time", 'UTC'::text)); -- @@ -4184,17 +5053,40 @@ WITH NO DATA; bucket | timestamp with time zone | | | | plain | temperature | numeric | | | | main | View definition: - SELECT _materialized_hypertable_55.bucket, - _materialized_hypertable_55.temperature - FROM _timescaledb_internal._materialized_hypertable_55 - WHERE _materialized_hypertable_55.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(55)), '-infinity'::timestamp with time zone) + SELECT _materialized_hypertable_64.bucket, + _materialized_hypertable_64.temperature + FROM _timescaledb_internal._materialized_hypertable_64 + WHERE _materialized_hypertable_64.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(64)), '-infinity'::timestamp with time zone) UNION ALL SELECT time_bucket('@ 1 year'::interval, conditions_summary_1.bucket) AS bucket, sum(conditions_summary_1.temperature) AS temperature FROM conditions_summary_1 - WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(55)), '-infinity'::timestamp with time zone) + WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(64)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 year'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -4210,6 +5102,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4232,15 +5125,15 @@ WITH NO DATA; bucket | timestamp with time zone | | | | plain | temperature | numeric | | | | main | View definition: - SELECT _materialized_hypertable_56.bucket, - _materialized_hypertable_56.temperature - FROM _timescaledb_internal._materialized_hypertable_56 - WHERE _materialized_hypertable_56.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(56)), '-infinity'::timestamp with time zone) + SELECT _materialized_hypertable_65.bucket, + _materialized_hypertable_65.temperature + FROM _timescaledb_internal._materialized_hypertable_65 + WHERE _materialized_hypertable_65.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(65)), '-infinity'::timestamp with time zone) UNION ALL SELECT time_bucket('@ 7 days'::interval, conditions."time", 'UTC'::text) AS bucket, sum(conditions.temperature) AS temperature FROM conditions - WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(56)), '-infinity'::timestamp with time zone) + WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(65)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 7 days'::interval, conditions."time", 'UTC'::text)); -- @@ -4262,16 +5155,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width -DETAIL: Time bucket width of "public.conditions_summary_2" [@ 360 days] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 7 days]. +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width +DETAIL: Time bucket width of "public.conditions_summary_2" [@ 1 year] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 7 days]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; \set BUCKET_WIDTH_1ST 'INTERVAL \'1 week\'' \set BUCKET_WIDTH_2TH 'INTERVAL \'1 month\'' @@ -4281,6 +5197,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4303,15 +5220,15 @@ WITH NO DATA; bucket | timestamp with time zone | | | | plain | temperature | numeric | | | | main | View definition: - SELECT _materialized_hypertable_57.bucket, - _materialized_hypertable_57.temperature - FROM _timescaledb_internal._materialized_hypertable_57 - WHERE _materialized_hypertable_57.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(57)), '-infinity'::timestamp with time zone) + SELECT _materialized_hypertable_66.bucket, + _materialized_hypertable_66.temperature + FROM _timescaledb_internal._materialized_hypertable_66 + WHERE _materialized_hypertable_66.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(66)), '-infinity'::timestamp with time zone) UNION ALL SELECT time_bucket('@ 7 days'::interval, conditions."time", 'UTC'::text) AS bucket, sum(conditions.temperature) AS temperature FROM conditions - WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(57)), '-infinity'::timestamp with time zone) + WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(66)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 7 days'::interval, conditions."time", 'UTC'::text)); -- @@ -4333,16 +5250,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width -DETAIL: Time bucket width of "public.conditions_summary_2" [@ 30 days] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 7 days]. +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width +DETAIL: Time bucket width of "public.conditions_summary_2" [@ 1 mon] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 7 days]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- bug report 5277 \set IS_TIME_DIMENSION_WITH_TIMEZONE_1ST FALSE @@ -4356,6 +5296,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4378,15 +5319,15 @@ WITH NO DATA; bucket | timestamp with time zone | | | | plain | temperature | numeric | | | | main | View definition: - SELECT _materialized_hypertable_58.bucket, - _materialized_hypertable_58.temperature - FROM _timescaledb_internal._materialized_hypertable_58 - WHERE _materialized_hypertable_58.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(58)), '-infinity'::timestamp with time zone) + SELECT _materialized_hypertable_67.bucket, + _materialized_hypertable_67.temperature + FROM _timescaledb_internal._materialized_hypertable_67 + WHERE _materialized_hypertable_67.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(67)), '-infinity'::timestamp with time zone) UNION ALL SELECT time_bucket('@ 0.146 secs'::interval, conditions."time") AS bucket, sum(conditions.temperature) AS temperature FROM conditions - WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(58)), '-infinity'::timestamp with time zone) + WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(67)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 0.146 secs'::interval, conditions."time")); -- @@ -4415,17 +5356,40 @@ WITH NO DATA; bucket | timestamp with time zone | | | | plain | temperature | numeric | | | | main | View definition: - SELECT _materialized_hypertable_59.bucket, - _materialized_hypertable_59.temperature - FROM _timescaledb_internal._materialized_hypertable_59 - WHERE _materialized_hypertable_59.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(59)), '-infinity'::timestamp with time zone) + SELECT _materialized_hypertable_68.bucket, + _materialized_hypertable_68.temperature + FROM _timescaledb_internal._materialized_hypertable_68 + WHERE _materialized_hypertable_68.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(68)), '-infinity'::timestamp with time zone) UNION ALL SELECT time_bucket('@ 1.168 secs'::interval, conditions_summary_1.bucket) AS bucket, sum(conditions_summary_1.temperature) AS temperature FROM conditions_summary_1 - WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(59)), '-infinity'::timestamp with time zone) + WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(68)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1.168 secs'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -4441,6 +5405,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4463,15 +5428,15 @@ WITH NO DATA; bucket | timestamp with time zone | | | | plain | temperature | numeric | | | | main | View definition: - SELECT _materialized_hypertable_60.bucket, - _materialized_hypertable_60.temperature - FROM _timescaledb_internal._materialized_hypertable_60 - WHERE _materialized_hypertable_60.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(60)), '-infinity'::timestamp with time zone) + SELECT _materialized_hypertable_69.bucket, + _materialized_hypertable_69.temperature + FROM _timescaledb_internal._materialized_hypertable_69 + WHERE _materialized_hypertable_69.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(69)), '-infinity'::timestamp with time zone) UNION ALL SELECT time_bucket('@ 9.344 secs'::interval, conditions."time") AS bucket, sum(conditions.temperature) AS temperature FROM conditions - WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(60)), '-infinity'::timestamp with time zone) + WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(69)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 9.344 secs'::interval, conditions."time")); -- @@ -4500,17 +5465,40 @@ WITH NO DATA; bucket | timestamp with time zone | | | | plain | temperature | numeric | | | | main | View definition: - SELECT _materialized_hypertable_61.bucket, - _materialized_hypertable_61.temperature - FROM _timescaledb_internal._materialized_hypertable_61 - WHERE _materialized_hypertable_61.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(61)), '-infinity'::timestamp with time zone) + SELECT _materialized_hypertable_70.bucket, + _materialized_hypertable_70.temperature + FROM _timescaledb_internal._materialized_hypertable_70 + WHERE _materialized_hypertable_70.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(70)), '-infinity'::timestamp with time zone) UNION ALL SELECT time_bucket('@ 1 min 14.752 secs'::interval, conditions_summary_1.bucket) AS bucket, sum(conditions_summary_1.temperature) AS temperature FROM conditions_summary_1 - WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(61)), '-infinity'::timestamp with time zone) + WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(70)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 min 14.752 secs'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -4526,6 +5514,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4548,15 +5537,15 @@ WITH NO DATA; bucket | timestamp with time zone | | | | plain | temperature | numeric | | | | main | View definition: - SELECT _materialized_hypertable_62.bucket, - _materialized_hypertable_62.temperature - FROM _timescaledb_internal._materialized_hypertable_62 - WHERE _materialized_hypertable_62.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(62)), '-infinity'::timestamp with time zone) + SELECT _materialized_hypertable_71.bucket, + _materialized_hypertable_71.temperature + FROM _timescaledb_internal._materialized_hypertable_71 + WHERE _materialized_hypertable_71.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(71)), '-infinity'::timestamp with time zone) UNION ALL SELECT time_bucket('@ 1 min 14.752 secs'::interval, conditions."time") AS bucket, sum(conditions.temperature) AS temperature FROM conditions - WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(62)), '-infinity'::timestamp with time zone) + WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(71)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 min 14.752 secs'::interval, conditions."time")); -- @@ -4585,17 +5574,40 @@ WITH NO DATA; bucket | timestamp with time zone | | | | plain | temperature | numeric | | | | main | View definition: - SELECT _materialized_hypertable_63.bucket, - _materialized_hypertable_63.temperature - FROM _timescaledb_internal._materialized_hypertable_63 - WHERE _materialized_hypertable_63.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(63)), '-infinity'::timestamp with time zone) + SELECT _materialized_hypertable_72.bucket, + _materialized_hypertable_72.temperature + FROM _timescaledb_internal._materialized_hypertable_72 + WHERE _materialized_hypertable_72.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(72)), '-infinity'::timestamp with time zone) UNION ALL SELECT time_bucket('@ 9 mins 58.016 secs'::interval, conditions_summary_1.bucket) AS bucket, sum(conditions_summary_1.temperature) AS temperature FROM conditions_summary_1 - WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(63)), '-infinity'::timestamp with time zone) + WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(72)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 9 mins 58.016 secs'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -4612,6 +5624,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4634,15 +5647,15 @@ WITH NO DATA; bucket | timestamp with time zone | | | | plain | temperature | numeric | | | | main | View definition: - SELECT _materialized_hypertable_64.bucket, - _materialized_hypertable_64.temperature - FROM _timescaledb_internal._materialized_hypertable_64 - WHERE _materialized_hypertable_64.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(64)), '-infinity'::timestamp with time zone) + SELECT _materialized_hypertable_73.bucket, + _materialized_hypertable_73.temperature + FROM _timescaledb_internal._materialized_hypertable_73 + WHERE _materialized_hypertable_73.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(73)), '-infinity'::timestamp with time zone) UNION ALL SELECT time_bucket('@ 0.000146 secs'::interval, conditions."time") AS bucket, sum(conditions.temperature) AS temperature FROM conditions - WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(64)), '-infinity'::timestamp with time zone) + WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(73)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 0.000146 secs'::interval, conditions."time")); -- @@ -4671,17 +5684,40 @@ WITH NO DATA; bucket | timestamp with time zone | | | | plain | temperature | numeric | | | | main | View definition: - SELECT _materialized_hypertable_65.bucket, - _materialized_hypertable_65.temperature - FROM _timescaledb_internal._materialized_hypertable_65 - WHERE _materialized_hypertable_65.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(65)), '-infinity'::timestamp with time zone) + SELECT _materialized_hypertable_74.bucket, + _materialized_hypertable_74.temperature + FROM _timescaledb_internal._materialized_hypertable_74 + WHERE _materialized_hypertable_74.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(74)), '-infinity'::timestamp with time zone) UNION ALL SELECT time_bucket('@ 0.001168 secs'::interval, conditions_summary_1.bucket) AS bucket, sum(conditions_summary_1.temperature) AS temperature FROM conditions_summary_1 - WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(65)), '-infinity'::timestamp with time zone) + WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(74)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 0.001168 secs'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -4698,6 +5734,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4720,15 +5757,15 @@ WITH NO DATA; bucket | timestamp with time zone | | | | plain | temperature | numeric | | | | main | View definition: - SELECT _materialized_hypertable_66.bucket, - _materialized_hypertable_66.temperature - FROM _timescaledb_internal._materialized_hypertable_66 - WHERE _materialized_hypertable_66.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(66)), '-infinity'::timestamp with time zone) + SELECT _materialized_hypertable_75.bucket, + _materialized_hypertable_75.temperature + FROM _timescaledb_internal._materialized_hypertable_75 + WHERE _materialized_hypertable_75.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(75)), '-infinity'::timestamp with time zone) UNION ALL SELECT time_bucket('@ 0.000146 secs'::interval, conditions."time") AS bucket, sum(conditions.temperature) AS temperature FROM conditions - WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(66)), '-infinity'::timestamp with time zone) + WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(75)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 0.000146 secs'::interval, conditions."time")); -- @@ -4750,14 +5787,37 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [@ 0.00116 secs] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 0.000146 secs]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; diff --git a/tsl/test/expected/cagg_on_cagg_dist_ht.out b/tsl/test/expected/cagg_on_cagg_dist_ht.out index 1512c5eccbc..f4a5ce2efe6 100644 --- a/tsl/test/expected/cagg_on_cagg_dist_ht.out +++ b/tsl/test/expected/cagg_on_cagg_dist_ht.out @@ -8,6 +8,7 @@ \set DATA_NODE_1 :TEST_DBNAME _1 \set DATA_NODE_2 :TEST_DBNAME _2 \set DATA_NODE_3 :TEST_DBNAME _3 +\set INTERVAL_TEST FALSE \ir include/remote_exec.sql -- This file and its contents are licensed under the Timescale License. -- Please see the included NOTICE for copyright information and @@ -46,6 +47,7 @@ GRANT CREATE ON SCHEMA public TO :ROLE_DEFAULT_PERM_USER; -- Current test variables \set IS_TIME_DIMENSION FALSE \set TIME_DIMENSION_DATATYPE INTEGER +\set INTERVAL_TEST FALSE \set CAGG_NAME_1ST_LEVEL conditions_summary_1_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2_5 \set CAGG_NAME_3TH_LEVEL conditions_summary_3_10 @@ -902,6 +904,7 @@ psql:include/cagg_on_cagg_common.sql:200: ERROR: relation "conditions_summary_1 -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -954,16 +957,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [5] should be multiple of the time bucket width of "public.conditions_summary_1" [2]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- -- Validation test for equal bucket sizes @@ -977,6 +1003,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -1047,6 +1074,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.cagg_watermark(11)::integer, '-2147483648'::integer) GROUP BY (time_bucket(2, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -1066,6 +1116,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -1118,16 +1169,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [2] should be greater or equal than the time bucket width of "public.conditions_summary_1" [4]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- cleanup DROP TABLE conditions; @@ -1986,6 +2060,7 @@ psql:include/cagg_on_cagg_common.sql:200: ERROR: relation "conditions_summary_1 -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -2038,17 +2113,40 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with fixed-width bucket on top of one using variable-width bucket +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with fixed-width bucket on top of one using variable-width bucket DETAIL: Continuous aggregate with a fixed time bucket width (e.g. 61 days) cannot be created on top of one using variable time bucket width (e.g. 1 month). The variance can lead to the fixed width one not being a multiple of the variable width one. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- -- Validation test for non-multiple bucket sizes @@ -2062,6 +2160,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -2114,16 +2213,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [@ 3 hours] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 2 hours]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- -- Validation test for equal bucket sizes @@ -2137,6 +2259,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -2207,6 +2330,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp_without_timezone(_timescaledb_internal.cagg_watermark(24)), '-infinity'::timestamp without time zone) GROUP BY (time_bucket('@ 1 hour'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -2226,6 +2372,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -2278,16 +2425,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [@ 1 hour] should be greater or equal than the time bucket width of "public.conditions_summary_1" [@ 2 hours]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- ######################################################## -- ## TIMESTAMPTZ data type tests @@ -3141,6 +3311,7 @@ psql:include/cagg_on_cagg_common.sql:200: ERROR: relation "conditions_summary_1 -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3193,17 +3364,40 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with fixed-width bucket on top of one using variable-width bucket +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with fixed-width bucket on top of one using variable-width bucket DETAIL: Continuous aggregate with a fixed time bucket width (e.g. 61 days) cannot be created on top of one using variable time bucket width (e.g. 1 month). The variance can lead to the fixed width one not being a multiple of the variable width one. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- -- Validation test for non-multiple bucket sizes @@ -3217,6 +3411,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3269,16 +3464,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [@ 3 hours] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 2 hours]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- -- Validation test for equal bucket sizes @@ -3292,6 +3510,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3362,6 +3581,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(37)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 hour'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -3381,6 +3623,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3433,16 +3676,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [@ 1 hour] should be greater or equal than the time bucket width of "public.conditions_summary_1" [@ 2 hours]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- -- Validations using time bucket with timezone (ref issue #5126) @@ -3463,6 +3729,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3533,6 +3800,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(40)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 hour'::interval, conditions_summary_1.bucket, 'US/Pacific'::text)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -3549,6 +3839,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3601,22 +3892,46 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [@ 16 mins] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 5 mins]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- -- Variable bucket size with the same timezones -- \set BUCKET_TZNAME_1ST 'UTC' \set BUCKET_TZNAME_2TH 'UTC' +\set INTERVAL_TEST TRUE \set BUCKET_WIDTH_1ST 'INTERVAL \'1 day\'' \set BUCKET_WIDTH_2TH 'INTERVAL \'1 month\'' \set WARNING_MESSAGE '-- SHOULD WORK' @@ -3626,6 +3941,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3696,13 +4012,44 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(43)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 mon'::interval, conditions_summary_1.bucket, 'UTC'::text)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; +psql:include/cagg_on_cagg_validations.sql:68: ERROR: cannot create continuous aggregate with incompatible bucket width +DETAIL: Time bucket width of "public.conditions_summary_3" [@ 7 days] should be greater or equal than the time bucket width of "public.conditions_summary_2" [@ 1 mon]. + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; +psql:include/cagg_on_cagg_validations.sql:71: ERROR: relation "conditions_summary_3" does not exist +LINE 1: SELECT * from conditions_summary_3; + ^ + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; +psql:include/cagg_on_cagg_validations.sql:73: NOTICE: materialized view "conditions_summary_3" does not exist, skipping + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: drop cascades to table _timescaledb_internal._hyper_43_30_chunk DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; +psql:include/cagg_on_cagg_validations.sql:84: NOTICE: drop cascades to table _timescaledb_internal._hyper_42_29_chunk -- -- Variable bucket size with different timezones -- @@ -3717,6 +4064,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3787,13 +4135,44 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(45)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 mon'::interval, conditions_summary_1.bucket, 'UTC'::text)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; +psql:include/cagg_on_cagg_validations.sql:68: ERROR: cannot create continuous aggregate with incompatible bucket width +DETAIL: Time bucket width of "public.conditions_summary_3" [@ 7 days] should be greater or equal than the time bucket width of "public.conditions_summary_2" [@ 1 mon]. + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; +psql:include/cagg_on_cagg_validations.sql:71: ERROR: relation "conditions_summary_3" does not exist +LINE 1: SELECT * from conditions_summary_3; + ^ + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; +psql:include/cagg_on_cagg_validations.sql:73: NOTICE: materialized view "conditions_summary_3" does not exist, skipping + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: drop cascades to 2 other objects DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; +psql:include/cagg_on_cagg_validations.sql:84: NOTICE: drop cascades to table _timescaledb_internal._hyper_44_31_chunk -- -- TZ bucket on top of non-TZ bucket -- @@ -3809,6 +4188,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3879,13 +4259,44 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(47)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 mon'::interval, conditions_summary_1.bucket, 'UTC'::text)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; +psql:include/cagg_on_cagg_validations.sql:68: ERROR: cannot create continuous aggregate with incompatible bucket width +DETAIL: Time bucket width of "public.conditions_summary_3" [@ 7 days] should be greater or equal than the time bucket width of "public.conditions_summary_2" [@ 1 mon]. + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; +psql:include/cagg_on_cagg_validations.sql:71: ERROR: relation "conditions_summary_3" does not exist +LINE 1: SELECT * from conditions_summary_3; + ^ + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; +psql:include/cagg_on_cagg_validations.sql:73: NOTICE: materialized view "conditions_summary_3" does not exist, skipping + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: drop cascades to table _timescaledb_internal._hyper_47_35_chunk DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; +psql:include/cagg_on_cagg_validations.sql:84: NOTICE: drop cascades to table _timescaledb_internal._hyper_46_34_chunk -- -- non-TZ bucket on top of TZ bucket -- @@ -3901,6 +4312,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3971,13 +4383,46 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(49)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 mon'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; +psql:include/cagg_on_cagg_validations.sql:68: ERROR: cannot create continuous aggregate with fixed-width bucket on top of one using variable-width bucket +DETAIL: Continuous aggregate with a fixed time bucket width (e.g. 61 days) cannot be created on top of one using variable time bucket width (e.g. 1 month). +The variance can lead to the fixed width one not being a multiple of the variable width one. + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; +psql:include/cagg_on_cagg_validations.sql:71: ERROR: relation "conditions_summary_3" does not exist +LINE 1: SELECT * from conditions_summary_3; + ^ + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; +psql:include/cagg_on_cagg_validations.sql:73: NOTICE: materialized view "conditions_summary_3" does not exist, skipping + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: drop cascades to table _timescaledb_internal._hyper_49_37_chunk DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; +psql:include/cagg_on_cagg_validations.sql:84: NOTICE: drop cascades to table _timescaledb_internal._hyper_48_36_chunk +\set INTERVAL_TEST FALSE -- bug report 5231 \set BUCKET_WIDTH_1ST 'INTERVAL \'1 day\'' \set BUCKET_WIDTH_2TH 'INTERVAL \'1 year\'' @@ -3987,6 +4432,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4057,6 +4503,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(51)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 year'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -4072,6 +4541,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4142,6 +4612,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(53)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 3 mons'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -4157,6 +4650,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4227,6 +4721,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(55)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 year'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -4242,6 +4759,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4294,16 +4812,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width -DETAIL: Time bucket width of "public.conditions_summary_2" [@ 360 days] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 7 days]. +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width +DETAIL: Time bucket width of "public.conditions_summary_2" [@ 1 year] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 7 days]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; \set BUCKET_WIDTH_1ST 'INTERVAL \'1 week\'' \set BUCKET_WIDTH_2TH 'INTERVAL \'1 month\'' @@ -4313,6 +4854,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4365,16 +4907,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width -DETAIL: Time bucket width of "public.conditions_summary_2" [@ 30 days] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 7 days]. +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width +DETAIL: Time bucket width of "public.conditions_summary_2" [@ 1 mon] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 7 days]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- bug report 5277 \set IS_TIME_DIMENSION_WITH_TIMEZONE_1ST FALSE @@ -4388,6 +4953,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4458,6 +5024,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(59)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1.168 secs'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -4473,6 +5062,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4543,6 +5133,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(61)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 min 14.752 secs'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -4558,6 +5171,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4628,6 +5242,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(63)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 9 mins 58.016 secs'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -4644,6 +5281,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4714,6 +5352,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(65)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 0.001168 secs'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -4730,6 +5391,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4782,16 +5444,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [@ 0.00116 secs] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 0.000146 secs]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- Cleanup \c :TEST_DBNAME :ROLE_CLUSTER_SUPERUSER; diff --git a/tsl/test/expected/cagg_on_cagg_joins.out b/tsl/test/expected/cagg_on_cagg_joins.out index d02a84b0fa4..c99330c2f74 100644 --- a/tsl/test/expected/cagg_on_cagg_joins.out +++ b/tsl/test/expected/cagg_on_cagg_joins.out @@ -6,6 +6,7 @@ \set IS_TIME_DIMENSION_WITH_TIMEZONE_1ST FALSE \set IS_TIME_DIMENSION_WITH_TIMEZONE_2TH FALSE \set IS_JOIN TRUE +\set INTERVAL_TEST FALSE -- ######################################################## -- ## INTEGER data type tests -- ######################################################## @@ -891,6 +892,7 @@ psql:include/cagg_on_cagg_common.sql:200: ERROR: relation "conditions_summary_1 -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -943,16 +945,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [5] should be multiple of the time bucket width of "public.conditions_summary_1" [2]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- -- Validation test for equal bucket sizes @@ -967,6 +992,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -1037,6 +1063,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.cagg_watermark(11)::integer, '-2147483648'::integer) GROUP BY (time_bucket(2, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -1057,6 +1106,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -1109,16 +1159,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [2] should be greater or equal than the time bucket width of "public.conditions_summary_1" [4]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- ######################################################## -- ## TIMESTAMP data type tests @@ -1996,6 +2069,7 @@ psql:include/cagg_on_cagg_common.sql:200: ERROR: relation "conditions_summary_1 -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -2048,17 +2122,40 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with fixed-width bucket on top of one using variable-width bucket +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with fixed-width bucket on top of one using variable-width bucket DETAIL: Continuous aggregate with a fixed time bucket width (e.g. 61 days) cannot be created on top of one using variable time bucket width (e.g. 1 month). The variance can lead to the fixed width one not being a multiple of the variable width one. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- -- Validation test for non-multiple bucket sizes @@ -2073,6 +2170,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -2125,16 +2223,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [@ 3 hours] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 2 hours]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- -- Validation test for equal bucket sizes @@ -2149,6 +2270,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -2219,6 +2341,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp_without_timezone(_timescaledb_internal.cagg_watermark(24)), '-infinity'::timestamp without time zone) GROUP BY (time_bucket('@ 1 hour'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -2239,6 +2384,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -2291,16 +2437,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [@ 1 hour] should be greater or equal than the time bucket width of "public.conditions_summary_1" [@ 2 hours]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- ######################################################## -- ## TIMESTAMPTZ data type tests @@ -3177,6 +3346,7 @@ psql:include/cagg_on_cagg_common.sql:200: ERROR: relation "conditions_summary_1 -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3229,17 +3399,40 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with fixed-width bucket on top of one using variable-width bucket +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with fixed-width bucket on top of one using variable-width bucket DETAIL: Continuous aggregate with a fixed time bucket width (e.g. 61 days) cannot be created on top of one using variable time bucket width (e.g. 1 month). The variance can lead to the fixed width one not being a multiple of the variable width one. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- -- Validation test for non-multiple bucket sizes @@ -3254,6 +3447,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3306,16 +3500,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [@ 3 hours] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 2 hours]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- -- Validation test for equal bucket sizes @@ -3330,6 +3547,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3400,6 +3618,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(37)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 hour'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -3420,6 +3661,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3472,16 +3714,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [@ 1 hour] should be greater or equal than the time bucket width of "public.conditions_summary_1" [@ 2 hours]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- -- Validations using time bucket with timezone (ref issue #5126) @@ -3503,6 +3768,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3573,6 +3839,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(40)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 hour'::interval, conditions_summary_1.bucket, 'US/Pacific'::text)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -3589,6 +3878,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3641,16 +3931,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [@ 16 mins] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 5 mins]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- -- Variable bucket size with the same timezones @@ -3666,6 +3979,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3736,6 +4050,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(43)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 mon'::interval, conditions_summary_1.bucket, 'UTC'::text)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -3757,6 +4094,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3827,6 +4165,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(45)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 mon'::interval, conditions_summary_1.bucket, 'UTC'::text)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -3849,6 +4210,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3919,6 +4281,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(47)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 mon'::interval, conditions_summary_1.bucket, 'UTC'::text)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -3941,6 +4326,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4011,6 +4397,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(49)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 mon'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -4032,6 +4441,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4102,6 +4512,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(51)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 year'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -4117,6 +4550,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4187,6 +4621,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(53)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 3 mons'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -4202,6 +4659,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4272,6 +4730,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(55)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 year'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -4287,6 +4768,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4339,16 +4821,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width -DETAIL: Time bucket width of "public.conditions_summary_2" [@ 360 days] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 7 days]. +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width +DETAIL: Time bucket width of "public.conditions_summary_2" [@ 1 year] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 7 days]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; \set BUCKET_WIDTH_1ST 'INTERVAL \'1 week\'' \set BUCKET_WIDTH_2TH 'INTERVAL \'1 month\'' @@ -4358,6 +4863,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4410,14 +4916,37 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width -DETAIL: Time bucket width of "public.conditions_summary_2" [@ 30 days] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 7 days]. +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width +DETAIL: Time bucket width of "public.conditions_summary_2" [@ 1 mon] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 7 days]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; diff --git a/tsl/test/expected/cagg_on_cagg_joins_dist_ht.out b/tsl/test/expected/cagg_on_cagg_joins_dist_ht.out index 968e3f28397..ec1e3025a69 100644 --- a/tsl/test/expected/cagg_on_cagg_joins_dist_ht.out +++ b/tsl/test/expected/cagg_on_cagg_joins_dist_ht.out @@ -8,6 +8,7 @@ \set DATA_NODE_1 :TEST_DBNAME _1 \set DATA_NODE_2 :TEST_DBNAME _2 \set DATA_NODE_3 :TEST_DBNAME _3 +\set INTERVAL_TEST FALSE \ir include/remote_exec.sql -- This file and its contents are licensed under the Timescale License. -- Please see the included NOTICE for copyright information and @@ -923,6 +924,7 @@ psql:include/cagg_on_cagg_common.sql:200: ERROR: relation "conditions_summary_1 -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -975,16 +977,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [5] should be multiple of the time bucket width of "public.conditions_summary_1" [2]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- -- Validation test for equal bucket sizes @@ -998,6 +1023,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -1068,6 +1094,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.cagg_watermark(11)::integer, '-2147483648'::integer) GROUP BY (time_bucket(2, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -1087,6 +1136,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -1139,16 +1189,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [2] should be greater or equal than the time bucket width of "public.conditions_summary_1" [4]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- cleanup DROP TABLE conditions; @@ -2027,6 +2100,7 @@ psql:include/cagg_on_cagg_common.sql:200: ERROR: relation "conditions_summary_1 -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -2079,17 +2153,40 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with fixed-width bucket on top of one using variable-width bucket +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with fixed-width bucket on top of one using variable-width bucket DETAIL: Continuous aggregate with a fixed time bucket width (e.g. 61 days) cannot be created on top of one using variable time bucket width (e.g. 1 month). The variance can lead to the fixed width one not being a multiple of the variable width one. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- -- Validation test for non-multiple bucket sizes @@ -2103,6 +2200,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -2155,16 +2253,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [@ 3 hours] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 2 hours]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- -- Validation test for equal bucket sizes @@ -2178,6 +2299,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -2248,6 +2370,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp_without_timezone(_timescaledb_internal.cagg_watermark(24)), '-infinity'::timestamp without time zone) GROUP BY (time_bucket('@ 1 hour'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -2267,6 +2412,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -2319,16 +2465,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [@ 1 hour] should be greater or equal than the time bucket width of "public.conditions_summary_1" [@ 2 hours]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- ######################################################## -- ## TIMESTAMPTZ data type tests @@ -3202,6 +3371,7 @@ psql:include/cagg_on_cagg_common.sql:200: ERROR: relation "conditions_summary_1 -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3254,17 +3424,40 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with fixed-width bucket on top of one using variable-width bucket +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with fixed-width bucket on top of one using variable-width bucket DETAIL: Continuous aggregate with a fixed time bucket width (e.g. 61 days) cannot be created on top of one using variable time bucket width (e.g. 1 month). The variance can lead to the fixed width one not being a multiple of the variable width one. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- -- Validation test for non-multiple bucket sizes @@ -3278,6 +3471,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3330,16 +3524,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [@ 3 hours] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 2 hours]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- -- Validation test for equal bucket sizes @@ -3353,6 +3570,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3423,6 +3641,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(37)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 hour'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -3442,6 +3683,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3494,16 +3736,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [@ 1 hour] should be greater or equal than the time bucket width of "public.conditions_summary_1" [@ 2 hours]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- -- Validations using time bucket with timezone (ref issue #5126) @@ -3524,6 +3789,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3594,6 +3860,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(40)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 hour'::interval, conditions_summary_1.bucket, 'US/Pacific'::text)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -3610,6 +3899,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3662,16 +3952,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [@ 16 mins] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 5 mins]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- -- Variable bucket size with the same timezones @@ -3687,6 +4000,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3757,6 +4071,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(43)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 mon'::interval, conditions_summary_1.bucket, 'UTC'::text)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -3778,6 +4115,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3848,6 +4186,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(45)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 mon'::interval, conditions_summary_1.bucket, 'UTC'::text)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -3870,6 +4231,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -3940,6 +4302,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(47)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 mon'::interval, conditions_summary_1.bucket, 'UTC'::text)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -3962,6 +4347,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4032,6 +4418,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(49)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 mon'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -4048,6 +4457,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4118,6 +4528,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(51)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 year'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -4133,6 +4566,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4203,6 +4637,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(53)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 3 mons'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -4218,6 +4675,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4288,6 +4746,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(55)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 year'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -4303,6 +4784,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4355,16 +4837,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width -DETAIL: Time bucket width of "public.conditions_summary_2" [@ 360 days] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 7 days]. +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width +DETAIL: Time bucket width of "public.conditions_summary_2" [@ 1 year] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 7 days]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; \set BUCKET_WIDTH_1ST 'INTERVAL \'1 week\'' \set BUCKET_WIDTH_2TH 'INTERVAL \'1 month\'' @@ -4374,6 +4879,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4426,16 +4932,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width -DETAIL: Time bucket width of "public.conditions_summary_2" [@ 30 days] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 7 days]. +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width +DETAIL: Time bucket width of "public.conditions_summary_2" [@ 1 mon] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 7 days]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- bug report 5277 \set IS_TIME_DIMENSION_WITH_TIMEZONE_1ST FALSE @@ -4449,6 +4978,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4519,6 +5049,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(59)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1.168 secs'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -4534,6 +5087,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4604,6 +5158,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(61)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 1 min 14.752 secs'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -4619,6 +5196,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4689,6 +5267,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(63)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 9 mins 58.016 secs'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -4705,6 +5306,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4775,6 +5377,29 @@ UNION ALL WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(65)), '-infinity'::timestamp with time zone) GROUP BY (time_bucket('@ 0.001168 secs'::interval, conditions_summary_1.bucket)); +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- @@ -4791,6 +5416,7 @@ DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- LICENSE-TIMESCALE for a copy of the license. \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) -- @@ -4843,16 +5469,39 @@ SELECT FROM :CAGG_NAME_1ST_LEVEL GROUP BY 1 WITH NO DATA; -psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +psql:include/cagg_on_cagg_validations.sql:44: ERROR: cannot create continuous aggregate with incompatible bucket width DETAIL: Time bucket width of "public.conditions_summary_2" [@ 0.00116 secs] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 0.000146 secs]. \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif \set ON_ERROR_STOP 1 \set VERBOSITY terse -- -- Cleanup -- DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; -psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +psql:include/cagg_on_cagg_validations.sql:83: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- Cleanup \c :TEST_DBNAME :ROLE_CLUSTER_SUPERUSER; diff --git a/tsl/test/sql/cagg_on_cagg.sql b/tsl/test/sql/cagg_on_cagg.sql index 95460678c1c..99749c528f6 100644 --- a/tsl/test/sql/cagg_on_cagg.sql +++ b/tsl/test/sql/cagg_on_cagg.sql @@ -7,6 +7,7 @@ \set IS_TIME_DIMENSION_WITH_TIMEZONE_1ST FALSE \set IS_TIME_DIMENSION_WITH_TIMEZONE_2TH FALSE \set IS_JOIN FALSE +\set INTERVAL_TEST FALSE -- ######################################################## -- ## INTEGER data type tests -- ######################################################## @@ -213,6 +214,14 @@ SET timezone TO 'UTC'; \set WARNING_MESSAGE '-- SHOULD WORK' \ir include/cagg_on_cagg_validations.sql +--#Bugfix 5734 #1 +\set INTERVAL_TEST TRUE +\set BUCKET_WIDTH_1ST 'INTERVAL \'1 hour\'' +\set BUCKET_WIDTH_2TH 'INTERVAL \'1 day\'' +\set BUCKET_WIDTH_3TH 'INTERVAL \'1 month\'' +\ir include/cagg_on_cagg_validations.sql +\set INTERVAL_TEST FALSE + -- -- Variable bucket size with different timezones -- @@ -223,6 +232,14 @@ SET timezone TO 'UTC'; \set WARNING_MESSAGE '-- SHOULD WORK' \ir include/cagg_on_cagg_validations.sql +--#Bugfix 5734 #2 +\set INTERVAL_TEST TRUE +\set BUCKET_WIDTH_1ST 'INTERVAL \'1 hour\'' +\set BUCKET_WIDTH_2TH 'INTERVAL \'1 day\'' +\set BUCKET_WIDTH_3TH 'INTERVAL \'1 month\'' +\ir include/cagg_on_cagg_validations.sql +\set INTERVAL_TEST FALSE + -- -- TZ bucket on top of non-TZ bucket -- @@ -234,6 +251,14 @@ SET timezone TO 'UTC'; \set WARNING_MESSAGE '-- SHOULD WORK' \ir include/cagg_on_cagg_validations.sql +--#Bugfix 5734 #3 +\set INTERVAL_TEST TRUE +\set BUCKET_WIDTH_1ST 'INTERVAL \'1 hour\'' +\set BUCKET_WIDTH_2TH 'INTERVAL \'1 day\'' +\set BUCKET_WIDTH_3TH 'INTERVAL \'1 month\'' +\ir include/cagg_on_cagg_validations.sql +\set INTERVAL_TEST FALSE + -- -- non-TZ bucket on top of TZ bucket -- diff --git a/tsl/test/sql/cagg_on_cagg_dist_ht.sql b/tsl/test/sql/cagg_on_cagg_dist_ht.sql index c790da58723..f78e4c0ef36 100644 --- a/tsl/test/sql/cagg_on_cagg_dist_ht.sql +++ b/tsl/test/sql/cagg_on_cagg_dist_ht.sql @@ -10,6 +10,7 @@ \set DATA_NODE_1 :TEST_DBNAME _1 \set DATA_NODE_2 :TEST_DBNAME _2 \set DATA_NODE_3 :TEST_DBNAME _3 +\set INTERVAL_TEST FALSE \ir include/remote_exec.sql @@ -33,6 +34,7 @@ GRANT CREATE ON SCHEMA public TO :ROLE_DEFAULT_PERM_USER; -- Current test variables \set IS_TIME_DIMENSION FALSE \set TIME_DIMENSION_DATATYPE INTEGER +\set INTERVAL_TEST FALSE \set CAGG_NAME_1ST_LEVEL conditions_summary_1_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2_5 \set CAGG_NAME_3TH_LEVEL conditions_summary_3_10 @@ -229,6 +231,7 @@ SET timezone TO 'UTC'; -- \set BUCKET_TZNAME_1ST 'UTC' \set BUCKET_TZNAME_2TH 'UTC' +\set INTERVAL_TEST TRUE \set BUCKET_WIDTH_1ST 'INTERVAL \'1 day\'' \set BUCKET_WIDTH_2TH 'INTERVAL \'1 month\'' \set WARNING_MESSAGE '-- SHOULD WORK' @@ -265,6 +268,7 @@ SET timezone TO 'UTC'; \set BUCKET_WIDTH_2TH 'INTERVAL \'1 month\'' \set WARNING_MESSAGE '-- SHOULD WORK' \ir include/cagg_on_cagg_validations.sql +\set INTERVAL_TEST FALSE -- bug report 5231 \set BUCKET_WIDTH_1ST 'INTERVAL \'1 day\'' diff --git a/tsl/test/sql/cagg_on_cagg_joins.sql b/tsl/test/sql/cagg_on_cagg_joins.sql index 3611c5d3264..2ffd01cff9e 100644 --- a/tsl/test/sql/cagg_on_cagg_joins.sql +++ b/tsl/test/sql/cagg_on_cagg_joins.sql @@ -7,6 +7,7 @@ \set IS_TIME_DIMENSION_WITH_TIMEZONE_1ST FALSE \set IS_TIME_DIMENSION_WITH_TIMEZONE_2TH FALSE \set IS_JOIN TRUE +\set INTERVAL_TEST FALSE -- ######################################################## -- ## INTEGER data type tests -- ######################################################## diff --git a/tsl/test/sql/cagg_on_cagg_joins_dist_ht.sql b/tsl/test/sql/cagg_on_cagg_joins_dist_ht.sql index 715ce8a482f..4bff88bfb6c 100644 --- a/tsl/test/sql/cagg_on_cagg_joins_dist_ht.sql +++ b/tsl/test/sql/cagg_on_cagg_joins_dist_ht.sql @@ -10,6 +10,7 @@ \set DATA_NODE_1 :TEST_DBNAME _1 \set DATA_NODE_2 :TEST_DBNAME _2 \set DATA_NODE_3 :TEST_DBNAME _3 +\set INTERVAL_TEST FALSE \ir include/remote_exec.sql diff --git a/tsl/test/sql/include/cagg_on_cagg_setup.sql b/tsl/test/sql/include/cagg_on_cagg_setup.sql index d402990d2f6..b694be76c58 100644 --- a/tsl/test/sql/include/cagg_on_cagg_setup.sql +++ b/tsl/test/sql/include/cagg_on_cagg_setup.sql @@ -70,3 +70,4 @@ DROP TABLE IF EXISTS conditions CASCADE; INSERT INTO conditions ("time", temperature, device_id) VALUES (2, 5, 2); INSERT INTO conditions ("time", temperature, device_id) VALUES (5, 20, 3); \endif + diff --git a/tsl/test/sql/include/cagg_on_cagg_validations.sql b/tsl/test/sql/include/cagg_on_cagg_validations.sql index e43dc195bc7..a2a90512b06 100644 --- a/tsl/test/sql/include/cagg_on_cagg_validations.sql +++ b/tsl/test/sql/include/cagg_on_cagg_validations.sql @@ -4,6 +4,7 @@ \set CAGG_NAME_1ST_LEVEL conditions_summary_1 \set CAGG_NAME_2TH_LEVEL conditions_summary_2 +\set CAGG_NAME_3TH_LEVEL conditions_summary_3 -- -- CAGG on hypertable (1st level) @@ -44,6 +45,35 @@ WITH NO DATA; \d+ :CAGG_NAME_2TH_LEVEL +-- Check for incorrect CAGGs +\if :INTERVAL_TEST + + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-01 00:00:00-00', 10, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-15 01:00:00-00', 20, 4); + INSERT INTO conditions ("time", temperature, device_id) VALUES ('2022-01-31 01:00:00-00', 30, 4); + + CALL refresh_continuous_aggregate(:'CAGG_NAME_1ST_LEVEL', NULL, NULL); + CALL refresh_continuous_aggregate(:'CAGG_NAME_2TH_LEVEL', NULL, NULL); + + CREATE MATERIALIZED VIEW :CAGG_NAME_3TH_LEVEL + WITH (timescaledb.continuous) AS + SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_3TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket + \else + time_bucket(:BUCKET_WIDTH_3TH, "bucket") AS bucket + \endif + FROM :CAGG_NAME_2TH_LEVEL + GROUP BY 1 + WITH DATA; + + \d+ :CAGG_NAME_3TH_LEVEL + SELECT * from :CAGG_NAME_3TH_LEVEL; + + DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_3TH_LEVEL; + DELETE FROM conditions WHERE device_id = 4; +\endif + \set ON_ERROR_STOP 1 \set VERBOSITY terse