Remove requirement of CASCADE from DROP VIEW

To drop a continuous aggregate it was necessary to use the `CASCADE`
keyword, which would then cascade to the materialized hypertable. Since
this can cascade the drop to other objects that are dependent on the
continuous aggregate, this could accidentally drop more objects than
intended.

This commit fixes this by removing the check for `CASCADE` and adding
the materialized hypertable to the list of objects to drop.

Fixes timescale/timescaledb-private#659
This commit is contained in:
Mats Kindahl 2020-07-31 11:49:35 +02:00 committed by Mats Kindahl
parent 9f13fb9906
commit 9049a5d3cb
26 changed files with 186 additions and 96 deletions

View File

@ -1079,9 +1079,8 @@ process_grant_and_revoke_role(ProcessUtilityArgs *args)
return DDL_DONE; return DDL_DONE;
} }
/* Force the use of CASCADE to drop continuous aggregates */
static void static void
block_dropping_continuous_aggregates_without_cascade(ProcessUtilityArgs *args, DropStmt *stmt) process_drop_continuous_aggregates(ProcessUtilityArgs *args, DropStmt *stmt)
{ {
ListCell *lc; ListCell *lc;
@ -1108,13 +1107,19 @@ block_dropping_continuous_aggregates_without_cascade(ProcessUtilityArgs *args, D
name = get_rel_name(relid); name = get_rel_name(relid);
cagg = ts_continuous_agg_find_by_view_name(schema, name); cagg = ts_continuous_agg_find_by_view_name(schema, name);
if (cagg == NULL) if (cagg)
continue; {
/* Add the materialization table to the arguments so that the
if (ts_continuous_agg_view_type(&cagg->data, schema, name) == ContinuousAggUserView) * continuous aggregate and associated materialization table is
ereport(ERROR, * dropped together.
(errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST), *
errmsg("dropping a continuous aggregate requires using CASCADE"))); * If the table is missing, something is wrong, but we proceed
* with dropping the view anyway since the user cannot get rid of
* the broken view if we generate an error. */
Hypertable *ht = ts_hypertable_get_by_id(cagg->data.mat_hypertable_id);
if (ht)
process_add_hypertable(args, ht);
}
} }
} }
@ -1133,7 +1138,7 @@ process_drop_start(ProcessUtilityArgs *args)
process_drop_hypertable_index(args, stmt); process_drop_hypertable_index(args, stmt);
break; break;
case OBJECT_VIEW: case OBJECT_VIEW:
block_dropping_continuous_aggregates_without_cascade(args, stmt); process_drop_continuous_aggregates(args, stmt);
break; break;
case OBJECT_FOREIGN_SERVER: case OBJECT_FOREIGN_SERVER:
process_drop_foreign_server_start(stmt); process_drop_foreign_server_start(stmt);

View File

@ -658,5 +658,5 @@ SELECT show_chunks('test_drop_chunks_table');
(4 rows) (4 rows)
--drop the view to allow drop chunks to work --drop the view to allow drop chunks to work
DROP VIEW tdc_view CASCADE; DROP VIEW tdc_view;
NOTICE: drop cascades to table _timescaledb_internal._hyper_3_13_chunk NOTICE: drop cascades to table _timescaledb_internal._hyper_3_13_chunk

View File

@ -91,7 +91,7 @@ order by tgname;
SET ROLE :ROLE_DEFAULT_PERM_USER; SET ROLE :ROLE_DEFAULT_PERM_USER;
-- TEST2 --- -- TEST2 ---
drop view mat_m1 cascade; DROP VIEW mat_m1;
NOTICE: drop cascades to table _timescaledb_internal._hyper_2_2_chunk NOTICE: drop cascades to table _timescaledb_internal._hyper_2_2_chunk
SELECT * FROM _timescaledb_config.bgw_job; SELECT * FROM _timescaledb_config.bgw_job;
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
@ -241,7 +241,7 @@ order by time_bucket('1week', timec);
-- use previous data from conditions -- use previous data from conditions
--drop only the view. --drop only the view.
-- apply where clause on result of mat_m1 -- -- apply where clause on result of mat_m1 --
drop view mat_m1 cascade; DROP VIEW mat_m1;
NOTICE: drop cascades to 2 other objects NOTICE: drop cascades to 2 other objects
create or replace view mat_m1( timec, minl, sumth, stddevh) create or replace view mat_m1( timec, minl, sumth, stddevh)
WITH (timescaledb.continuous, timescaledb.materialized_only=true) WITH (timescaledb.continuous, timescaledb.materialized_only=true)
@ -295,7 +295,7 @@ order by time_bucket('1week', timec);
-- TEST5 -- -- TEST5 --
---------test with having clause ---------------------- ---------test with having clause ----------------------
drop view mat_m1 cascade; DROP VIEW mat_m1;
NOTICE: drop cascades to 2 other objects NOTICE: drop cascades to 2 other objects
create or replace view mat_m1( timec, minl, sumth, stddevh) create or replace view mat_m1( timec, minl, sumth, stddevh)
WITH (timescaledb.continuous, timescaledb.materialized_only=true) WITH (timescaledb.continuous, timescaledb.materialized_only=true)
@ -370,7 +370,6 @@ insert into conditions
select generate_series('2018-11-01 00:00'::timestamp, '2018-12-31 00:00'::timestamp, '1 day'), 'NYC', 35, 45, 50, 40; select generate_series('2018-11-01 00:00'::timestamp, '2018-12-31 00:00'::timestamp, '1 day'), 'NYC', 35, 45, 50, 40;
insert into conditions insert into conditions
select generate_series('2018-11-01 00:00'::timestamp, '2018-12-15 00:00'::timestamp, '1 day'), 'LA', 73, 55, 71, 28; select generate_series('2018-11-01 00:00'::timestamp, '2018-12-15 00:00'::timestamp, '1 day'), 'LA', 73, 55, 71, 28;
--drop view mat_m1 cascade;
--naming with AS clauses --naming with AS clauses
create or replace view mat_naming create or replace view mat_naming
WITH (timescaledb.continuous, timescaledb.materialized_only=true) WITH (timescaledb.continuous, timescaledb.materialized_only=true)
@ -405,7 +404,7 @@ order by attnum, attname;
8 | chunk_id 8 | chunk_id
(8 rows) (8 rows)
DROP VIEW mat_naming CASCADE; DROP VIEW mat_naming;
--naming with default names --naming with default names
create or replace view mat_naming create or replace view mat_naming
WITH (timescaledb.continuous, timescaledb.materialized_only=true) WITH (timescaledb.continuous, timescaledb.materialized_only=true)
@ -440,7 +439,7 @@ order by attnum, attname;
8 | chunk_id 8 | chunk_id
(8 rows) (8 rows)
DROP VIEW mat_naming CASCADE; DROP VIEW mat_naming;
--naming with view col names --naming with view col names
create or replace view mat_naming (bucket, loc, sum_t_h, stdd) create or replace view mat_naming (bucket, loc, sum_t_h, stdd)
WITH (timescaledb.continuous, timescaledb.materialized_only=true) WITH (timescaledb.continuous, timescaledb.materialized_only=true)
@ -475,7 +474,7 @@ order by attnum, attname;
8 | chunk_id 8 | chunk_id
(8 rows) (8 rows)
DROP VIEW mat_naming CASCADE; DROP VIEW mat_naming;
create or replace view mat_m1( timec, minl, sumth, stddevh) create or replace view mat_m1( timec, minl, sumth, stddevh)
WITH (timescaledb.continuous, timescaledb.materialized_only=true) WITH (timescaledb.continuous, timescaledb.materialized_only=true)
as as
@ -561,7 +560,7 @@ insert into :"MAT_SCHEMA_NAME".:"MAT_TABLE_NAME"
select * from :"PART_VIEW_SCHEMA".:"PART_VIEW_NAME"; select * from :"PART_VIEW_SCHEMA".:"PART_VIEW_NAME";
SET ROLE :ROLE_DEFAULT_PERM_USER; SET ROLE :ROLE_DEFAULT_PERM_USER;
--lets drop the view and check --lets drop the view and check
drop view mat_m1 cascade; DROP VIEW mat_m1;
NOTICE: drop cascades to 2 other objects NOTICE: drop cascades to 2 other objects
drop table conditions; drop table conditions;
CREATE TABLE conditions ( CREATE TABLE conditions (
@ -636,8 +635,6 @@ DROP VIEW :"PART_VIEW_SCHEMA".:"PART_VIEW_NAME";
ERROR: cannot drop the partial/direct view because it is required by a continuous aggregate ERROR: cannot drop the partial/direct view because it is required by a continuous aggregate
DROP VIEW :"DIR_VIEW_SCHEMA".:"DIR_VIEW_NAME"; DROP VIEW :"DIR_VIEW_SCHEMA".:"DIR_VIEW_NAME";
ERROR: cannot drop the partial/direct view because it is required by a continuous aggregate ERROR: cannot drop the partial/direct view because it is required by a continuous aggregate
DROP VIEW mat_test;
ERROR: dropping a continuous aggregate requires using CASCADE
\set ON_ERROR_STOP 1 \set ON_ERROR_STOP 1
--catalog entry still there; --catalog entry still there;
SELECT count(*) SELECT count(*)
@ -673,7 +670,7 @@ select count(*) from pg_class where relname = 'mat_test';
1 1
(1 row) (1 row)
DROP VIEW mat_test CASCADE; DROP VIEW mat_test;
NOTICE: drop cascades to 2 other objects NOTICE: drop cascades to 2 other objects
--catalog entry should be gone --catalog entry should be gone
SELECT count(*) SELECT count(*)
@ -904,7 +901,7 @@ order by indexname;
_materialized_hypertable_20_timec_idx | CREATE INDEX _materialized_hypertable_20_timec_idx ON _timescaledb_internal._materialized_hypertable_20 USING btree (timec DESC) _materialized_hypertable_20_timec_idx | CREATE INDEX _materialized_hypertable_20_timec_idx ON _timescaledb_internal._materialized_hypertable_20 USING btree (timec DESC)
(4 rows) (4 rows)
drop view mat_with_test cascade; DROP VIEW mat_with_test;
--no additional indexes --no additional indexes
create or replace view mat_with_test( timec, minl, sumt , sumh) create or replace view mat_with_test( timec, minl, sumt , sumh)
WITH (timescaledb.continuous, timescaledb.materialized_only=true, timescaledb.refresh_lag = '5 hours', timescaledb.refresh_interval = '1h', timescaledb.create_group_indexes=false) WITH (timescaledb.continuous, timescaledb.materialized_only=true, timescaledb.refresh_lag = '5 hours', timescaledb.refresh_interval = '1h', timescaledb.create_group_indexes=false)
@ -1166,7 +1163,7 @@ WARNING: type integer text
100 | 100 |
(3 rows) (3 rows)
DROP view mat_ffunc_test cascade; DROP view mat_ffunc_test;
NOTICE: drop cascades to table _timescaledb_internal._hyper_27_67_chunk NOTICE: drop cascades to table _timescaledb_internal._hyper_27_67_chunk
create or replace view mat_ffunc_test create or replace view mat_ffunc_test
WITH (timescaledb.continuous, timescaledb.materialized_only=true, timescaledb.refresh_lag = '-200') WITH (timescaledb.continuous, timescaledb.materialized_only=true, timescaledb.refresh_lag = '-200')
@ -1188,7 +1185,7 @@ WARNING: type integer bigint
(3 rows) (3 rows)
--refresh mat view test when time_bucket is not projected -- --refresh mat view test when time_bucket is not projected --
drop view mat_ffunc_test cascade; DROP VIEW mat_ffunc_test;
NOTICE: drop cascades to table _timescaledb_internal._hyper_28_68_chunk NOTICE: drop cascades to table _timescaledb_internal._hyper_28_68_chunk
create or replace view mat_refresh_test create or replace view mat_refresh_test
WITH (timescaledb.continuous, timescaledb.materialized_only=true, timescaledb.refresh_lag = '-200') WITH (timescaledb.continuous, timescaledb.materialized_only=true, timescaledb.refresh_lag = '-200')

View File

@ -342,7 +342,7 @@ SELECT ts_bgw_params_reset_time();
(1 row) (1 row)
DROP VIEW test_continuous_agg_view CASCADE; DROP VIEW test_continuous_agg_view;
NOTICE: drop cascades to table _timescaledb_internal._hyper_2_3_chunk NOTICE: drop cascades to table _timescaledb_internal._hyper_2_3_chunk
CREATE VIEW test_continuous_agg_view CREATE VIEW test_continuous_agg_view
WITH (timescaledb.continuous, WITH (timescaledb.continuous,
@ -486,7 +486,7 @@ job_status | Scheduled
last_run_duration | last_run_duration |
\x off \x off
DROP VIEW test_continuous_agg_view CASCADE; DROP VIEW test_continuous_agg_view;
NOTICE: drop cascades to table _timescaledb_internal._hyper_3_4_chunk NOTICE: drop cascades to table _timescaledb_internal._hyper_3_4_chunk
--create a view with a function that it has no permission to execute --create a view with a function that it has no permission to execute
CREATE VIEW test_continuous_agg_view CREATE VIEW test_continuous_agg_view

View File

@ -82,7 +82,7 @@ SELECT
replace(:'QUERY_TEMPLATE', 'TABLE', 'conditions_before') AS "QUERY_BEFORE", replace(:'QUERY_TEMPLATE', 'TABLE', 'conditions_before') AS "QUERY_BEFORE",
replace(:'QUERY_TEMPLATE', 'TABLE', 'conditions_after') AS "QUERY_AFTER" replace(:'QUERY_TEMPLATE', 'TABLE', 'conditions_after') AS "QUERY_AFTER"
\gset \gset
DROP VIEW if exists mat_test cascade; DROP VIEW IF EXISTS mat_test;
NOTICE: view "mat_test" does not exist, skipping NOTICE: view "mat_test" does not exist, skipping
--materialize this VIEW before dump this tests --materialize this VIEW before dump this tests
--that the partial state survives the dump intact --that the partial state survives the dump intact
@ -176,10 +176,6 @@ DROP table :"MAT_SCHEMA_NAME".:"MAT_TABLE_NAME";
ERROR: cannot drop table _timescaledb_internal._materialized_hypertable_3 because other objects depend on it ERROR: cannot drop table _timescaledb_internal._materialized_hypertable_3 because other objects depend on it
DROP VIEW :"PART_VIEW_SCHEMA".:"PART_VIEW_NAME"; DROP VIEW :"PART_VIEW_SCHEMA".:"PART_VIEW_NAME";
ERROR: cannot drop the partial/direct view because it is required by a continuous aggregate ERROR: cannot drop the partial/direct view because it is required by a continuous aggregate
DROP VIEW mat_before;
ERROR: dropping a continuous aggregate requires using CASCADE
DROP VIEW mat_after;
ERROR: dropping a continuous aggregate requires using CASCADE
\set ON_ERROR_STOP 1 \set ON_ERROR_STOP 1
--materialize mat_after --materialize mat_after
SET timescaledb.current_timestamp_mock = '2019-02-01 00:00'; SET timescaledb.current_timestamp_mock = '2019-02-01 00:00';
@ -219,7 +215,7 @@ SELECT count(*) FROM conditions_after;
Number of rows different between view and original (expect 0) | mat_after | 0 Number of rows different between view and original (expect 0) | mat_after | 0
(1 row) (1 row)
DROP VIEW mat_after cascade; DROP VIEW mat_after;
NOTICE: drop cascades to 2 other objects NOTICE: drop cascades to 2 other objects
DROP VIEW mat_before cascade; DROP VIEW mat_before;
NOTICE: drop cascades to 2 other objects NOTICE: drop cascades to 2 other objects

View File

@ -489,7 +489,7 @@ ERROR: timescaledb.refresh_lag out of range
ALTER TABLE conditions ALTER timec type bigint; ALTER TABLE conditions ALTER timec type bigint;
ERROR: cannot alter type of a column used by a view or rule ERROR: cannot alter type of a column used by a view or rule
\set ON_ERROR_STOP \set ON_ERROR_STOP
drop view mat_with_test CASCADE; DROP VIEW mat_with_test;
ALTER TABLE conditions ALTER timec type bigint; ALTER TABLE conditions ALTER timec type bigint;
create or replace view mat_with_test( timec, minl, sumt , sumh) create or replace view mat_with_test( timec, minl, sumt , sumh)
WITH ( timescaledb.continuous, timescaledb.refresh_lag = '2147483647', timescaledb.refresh_interval = '2h') WITH ( timescaledb.continuous, timescaledb.refresh_lag = '2147483647', timescaledb.refresh_interval = '2h')

View File

@ -955,9 +955,9 @@ SELECT hypertable_id, watermark
(1 row) (1 row)
--cleanup of continuous agg views -- --cleanup of continuous agg views --
DROP view test_t_mat_view CASCADE; DROP view test_t_mat_view;
NOTICE: drop cascades to table _timescaledb_internal._hyper_6_16_chunk NOTICE: drop cascades to table _timescaledb_internal._hyper_6_16_chunk
DROP view extreme_view CASCADE; DROP view extreme_view;
NOTICE: drop cascades to 4 other objects NOTICE: drop cascades to 4 other objects
-- negative lag test -- negative lag test
CREATE TABLE continuous_agg_negative(time BIGINT, data BIGINT); CREATE TABLE continuous_agg_negative(time BIGINT, data BIGINT);
@ -1032,7 +1032,7 @@ SELECT * FROM negative_view_5 ORDER BY 1;
10 | 5 10 | 5
(3 rows) (3 rows)
DROP VIEW negative_view_5 CASCADE; DROP VIEW negative_view_5;
NOTICE: drop cascades to table _timescaledb_internal._hyper_10_27_chunk NOTICE: drop cascades to table _timescaledb_internal._hyper_10_27_chunk
TRUNCATE continuous_agg_negative; TRUNCATE continuous_agg_negative;
CREATE VIEW negative_view_5 CREATE VIEW negative_view_5

View File

@ -215,7 +215,7 @@ select count(*) from _timescaledb_catalog.continuous_aggs_materialization_invali
(1 row) (1 row)
--now drop cagg_1, should still have materialization_invalidation_log --now drop cagg_1, should still have materialization_invalidation_log
drop view cagg_1 cascade; DROP VIEW cagg_1;
NOTICE: drop cascades to table _timescaledb_internal._hyper_2_5_chunk NOTICE: drop cascades to table _timescaledb_internal._hyper_2_5_chunk
select count(*) from _timescaledb_catalog.continuous_aggs_materialization_invalidation_log; select count(*) from _timescaledb_catalog.continuous_aggs_materialization_invalidation_log;
count count
@ -386,9 +386,9 @@ select * from _timescaledb_catalog.continuous_aggs_materialization_invalidation_
6 | 18 | 18 | 18 6 | 18 | 18 | 18
(2 rows) (2 rows)
DROP VIEW cagg_1 cascade; DROP VIEW cagg_1;
NOTICE: drop cascades to table _timescaledb_internal._hyper_5_11_chunk NOTICE: drop cascades to table _timescaledb_internal._hyper_5_11_chunk
DROP VIEW cagg_2 cascade; DROP VIEW cagg_2;
NOTICE: drop cascades to table _timescaledb_internal._hyper_6_12_chunk NOTICE: drop cascades to table _timescaledb_internal._hyper_6_12_chunk
--TEST6 test the ignore_invalidation_older_than setting --TEST6 test the ignore_invalidation_older_than setting
CREATE TABLE continuous_agg_test_ignore_invalidation_older_than(timeval integer, col1 integer, col2 integer); CREATE TABLE continuous_agg_test_ignore_invalidation_older_than(timeval integer, col1 integer, col2 integer);

View File

@ -111,7 +111,7 @@ ALTER VIEW mat_refresh_test SET(timescaledb.refresh_lag = '6 h', timescaledb.ref
ERROR: must be owner of view mat_refresh_test ERROR: must be owner of view mat_refresh_test
ALTER VIEW mat_refresh_test SET(timescaledb.materialized_only = true); ALTER VIEW mat_refresh_test SET(timescaledb.materialized_only = true);
ERROR: must be owner of view mat_refresh_test ERROR: must be owner of view mat_refresh_test
DROP VIEW mat_refresh_test CASCADE; DROP VIEW mat_refresh_test;
ERROR: must be owner of view mat_refresh_test ERROR: must be owner of view mat_refresh_test
REFRESH MATERIALIZED VIEW mat_refresh_test; REFRESH MATERIALIZED VIEW mat_refresh_test;
ERROR: permission denied for table conditions ERROR: permission denied for table conditions
@ -152,7 +152,7 @@ NOTICE: adding index _materialized_hypertable_7_get_constant_time_partition_col
--this should fail --this should fail
REFRESH MATERIALIZED VIEW mat_perm_view_test; REFRESH MATERIALIZED VIEW mat_perm_view_test;
ERROR: permission denied for function get_constant ERROR: permission denied for function get_constant
DROP VIEW mat_perm_view_test CASCADE; DROP VIEW mat_perm_view_test;
--can create a mat view on something with select and trigger grants --can create a mat view on something with select and trigger grants
create or replace view mat_perm_view_test create or replace view mat_perm_view_test
WITH ( timescaledb.continuous, timescaledb.materialized_only=true, timescaledb.refresh_lag = '-200') WITH ( timescaledb.continuous, timescaledb.materialized_only=true, timescaledb.refresh_lag = '-200')

View File

@ -177,7 +177,7 @@ SELECT time_bucket,avg FROM metrics_summary ORDER BY 1;
Fri Dec 31 16:00:00 1999 PST | 0.5 Fri Dec 31 16:00:00 1999 PST | 0.5
(1 row) (1 row)
DROP VIEW metrics_summary CASCADE; DROP VIEW metrics_summary;
NOTICE: drop cascades to table _timescaledb_internal._hyper_2_2_chunk NOTICE: drop cascades to table _timescaledb_internal._hyper_2_2_chunk
-- check default view for new continuous aggregate with materialized_only to true -- check default view for new continuous aggregate with materialized_only to true
CREATE VIEW metrics_summary CREATE VIEW metrics_summary
@ -259,7 +259,7 @@ SELECT time_bucket,avg FROM metrics_summary ORDER BY 1;
-------------+----- -------------+-----
(0 rows) (0 rows)
DROP VIEW metrics_summary CASCADE; DROP VIEW metrics_summary;
-- --
-- test queries on union view -- test queries on union view
-- --
@ -548,7 +548,7 @@ ORDER BY 1;
31 | 2 | 129 | 56 | 50 31 | 2 | 129 | 56 | 50
(3 rows) (3 rows)
DROP VIEW mat_m1 cascade; DROP VIEW mat_m1;
NOTICE: drop cascades to table _timescaledb_internal._hyper_8_12_chunk NOTICE: drop cascades to table _timescaledb_internal._hyper_8_12_chunk
--- TEST union view with multiple WHERE and HAVING clauses --- TEST union view with multiple WHERE and HAVING clauses
CREATE VIEW mat_m1 CREATE VIEW mat_m1

View File

@ -177,7 +177,7 @@ SELECT time_bucket,avg FROM metrics_summary ORDER BY 1;
Fri Dec 31 16:00:00 1999 PST | 0.5 Fri Dec 31 16:00:00 1999 PST | 0.5
(1 row) (1 row)
DROP VIEW metrics_summary CASCADE; DROP VIEW metrics_summary;
NOTICE: drop cascades to table _timescaledb_internal._hyper_2_2_chunk NOTICE: drop cascades to table _timescaledb_internal._hyper_2_2_chunk
-- check default view for new continuous aggregate with materialized_only to true -- check default view for new continuous aggregate with materialized_only to true
CREATE VIEW metrics_summary CREATE VIEW metrics_summary
@ -259,7 +259,7 @@ SELECT time_bucket,avg FROM metrics_summary ORDER BY 1;
-------------+----- -------------+-----
(0 rows) (0 rows)
DROP VIEW metrics_summary CASCADE; DROP VIEW metrics_summary;
-- --
-- test queries on union view -- test queries on union view
-- --
@ -548,7 +548,7 @@ ORDER BY 1;
31 | 2 | 129 | 56 | 50 31 | 2 | 129 | 56 | 50
(3 rows) (3 rows)
DROP VIEW mat_m1 cascade; DROP VIEW mat_m1;
NOTICE: drop cascades to table _timescaledb_internal._hyper_8_12_chunk NOTICE: drop cascades to table _timescaledb_internal._hyper_8_12_chunk
--- TEST union view with multiple WHERE and HAVING clauses --- TEST union view with multiple WHERE and HAVING clauses
CREATE VIEW mat_m1 CREATE VIEW mat_m1

View File

@ -203,7 +203,7 @@ SELECT * FROM device_summary WHERE device_id = 'device_1' and bucket = 'Sun Dec
-- For example you cannot cast to the local time. This is because -- For example you cannot cast to the local time. This is because
-- a timezone setting can alter from user-to-user and thus -- a timezone setting can alter from user-to-user and thus
-- cannot be materialized. -- cannot be materialized.
DROP VIEW device_summary CASCADE; DROP VIEW device_summary;
NOTICE: drop cascades to table _timescaledb_internal._hyper_2_6_chunk NOTICE: drop cascades to table _timescaledb_internal._hyper_2_6_chunk
CREATE VIEW device_summary CREATE VIEW device_summary
WITH (timescaledb.continuous, timescaledb.materialized_only=true) WITH (timescaledb.continuous, timescaledb.materialized_only=true)
@ -221,7 +221,7 @@ ERROR: only immutable functions are supported for continuous aggregate query
--note the error. --note the error.
-- You have two options: -- You have two options:
-- Option 1: be explicit in your timezone: -- Option 1: be explicit in your timezone:
DROP VIEW device_summary CASCADE; DROP VIEW device_summary;
ERROR: view "device_summary" does not exist ERROR: view "device_summary" does not exist
CREATE VIEW device_summary CREATE VIEW device_summary
WITH (timescaledb.continuous, timescaledb.materialized_only=true) WITH (timescaledb.continuous, timescaledb.materialized_only=true)
@ -236,10 +236,10 @@ FROM
device_readings device_readings
GROUP BY bucket, device_id; GROUP BY bucket, device_id;
NOTICE: adding index _materialized_hypertable_3_device_id_bucket_idx ON _timescaledb_internal._materialized_hypertable_3 USING BTREE(device_id, bucket) NOTICE: adding index _materialized_hypertable_3_device_id_bucket_idx ON _timescaledb_internal._materialized_hypertable_3 USING BTREE(device_id, bucket)
DROP VIEW device_summary CASCADE; DROP VIEW device_summary;
-- Option 2: Keep things as TIMESTAMPTZ in the view and convert to local time when -- Option 2: Keep things as TIMESTAMPTZ in the view and convert to local time when
-- querying from the view -- querying from the view
DROP VIEW device_summary CASCADE; DROP VIEW device_summary;
ERROR: view "device_summary" does not exist ERROR: view "device_summary" does not exist
CREATE VIEW device_summary CREATE VIEW device_summary
WITH (timescaledb.continuous, timescaledb.materialized_only=true) WITH (timescaledb.continuous, timescaledb.materialized_only=true)
@ -391,3 +391,55 @@ SELECT * FROM device_readings_jit ORDER BY time_bucket;
60 | 600 60 | 600
(6 rows) (6 rows)
-- START OF BASIC USAGE TESTS --
-- Check that continuous aggregate and materialized table is dropped
-- together.
CREATE TABLE whatever(time TIMESTAMPTZ NOT NULL, metric INTEGER);
SELECT * FROM create_hypertable('whatever', 'time');
hypertable_id | schema_name | table_name | created
---------------+-------------+------------+---------
8 | public | whatever | t
(1 row)
CREATE VIEW whatever_summary WITH (timescaledb.continuous) AS
SELECT time_bucket('1 hour', time) AS bucket, avg(metric)
FROM whatever GROUP BY bucket;
SELECT (SELECT format('%1$I.%2$I', schema_name, table_name)::regclass::oid
FROM _timescaledb_catalog.hypertable
WHERE id = raw_hypertable_id) AS raw_table
, (SELECT format('%1$I.%2$I', schema_name, table_name)::regclass::oid
FROM _timescaledb_catalog.hypertable
WHERE id = mat_hypertable_id) AS mat_table
FROM _timescaledb_catalog.continuous_agg
WHERE user_view_name = 'whatever_summary' \gset
SELECT relname FROM pg_class WHERE oid = :mat_table;
relname
----------------------------
_materialized_hypertable_9
(1 row)
----------------------------------------------------------------
-- Should generate an error since the cagg is dependent on the table.
DROP TABLE whatever;
ERROR: cannot drop table whatever because other objects depend on it
----------------------------------------------------------------
-- Checking that a cagg cannot be dropped if there is a dependent
-- object on it.
CREATE VIEW whatever_summary_dependency AS SELECT * FROM whatever_summary;
-- Should generate an error
DROP VIEW whatever_summary;
ERROR: cannot drop view whatever_summary because other objects depend on it
-- Dropping the dependent view so that we can do a proper drop below.
DROP VIEW whatever_summary_dependency;
----------------------------------------------------------------
-- Dropping the cagg should also remove the materialized table
DROP VIEW whatever_summary;
SELECT relname FROM pg_class WHERE oid = :mat_table;
relname
---------
(0 rows)
----------------------------------------------------------------
-- Cleanup
DROP TABLE whatever;
-- END OF BASIC USAGE TESTS --

View File

@ -2998,7 +2998,7 @@ LIMIT 1;
Fri Dec 31 16:00:00 1999 PST Fri Dec 31 16:00:00 1999 PST
(1 row) (1 row)
DROP VIEW cagg_test CASCADE; DROP VIEW cagg_test;
RESET client_min_messages; RESET client_min_messages;
--github issue 1558. nested loop with index scan needed --github issue 1558. nested loop with index scan needed
--disables parallel scan --disables parallel scan
@ -6785,7 +6785,7 @@ LIMIT 1;
Fri Dec 31 16:00:00 1999 PST Fri Dec 31 16:00:00 1999 PST
(1 row) (1 row)
DROP VIEW cagg_test CASCADE; DROP VIEW cagg_test;
RESET client_min_messages; RESET client_min_messages;
--github issue 1558. nested loop with index scan needed --github issue 1558. nested loop with index scan needed
--disables parallel scan --disables parallel scan

View File

@ -2968,7 +2968,7 @@ LIMIT 1;
Fri Dec 31 16:00:00 1999 PST Fri Dec 31 16:00:00 1999 PST
(1 row) (1 row)
DROP VIEW cagg_test CASCADE; DROP VIEW cagg_test;
RESET client_min_messages; RESET client_min_messages;
--github issue 1558. nested loop with index scan needed --github issue 1558. nested loop with index scan needed
--disables parallel scan --disables parallel scan
@ -6714,7 +6714,7 @@ LIMIT 1;
Fri Dec 31 16:00:00 1999 PST Fri Dec 31 16:00:00 1999 PST
(1 row) (1 row)
DROP VIEW cagg_test CASCADE; DROP VIEW cagg_test;
RESET client_min_messages; RESET client_min_messages;
--github issue 1558. nested loop with index scan needed --github issue 1558. nested loop with index scan needed
--disables parallel scan --disables parallel scan

View File

@ -308,4 +308,4 @@ SELECT job_id, time_bucket('1m',next_start) AS next_start, time_bucket('1m',last
SELECT show_chunks('test_drop_chunks_table'); SELECT show_chunks('test_drop_chunks_table');
--drop the view to allow drop chunks to work --drop the view to allow drop chunks to work
DROP VIEW tdc_view CASCADE; DROP VIEW tdc_view;

View File

@ -75,7 +75,7 @@ order by tgname;
SET ROLE :ROLE_DEFAULT_PERM_USER; SET ROLE :ROLE_DEFAULT_PERM_USER;
-- TEST2 --- -- TEST2 ---
drop view mat_m1 cascade; DROP VIEW mat_m1;
SELECT * FROM _timescaledb_config.bgw_job; SELECT * FROM _timescaledb_config.bgw_job;
@ -201,7 +201,7 @@ order by time_bucket('1week', timec);
--drop only the view. --drop only the view.
-- apply where clause on result of mat_m1 -- -- apply where clause on result of mat_m1 --
drop view mat_m1 cascade; DROP VIEW mat_m1;
create or replace view mat_m1( timec, minl, sumth, stddevh) create or replace view mat_m1( timec, minl, sumth, stddevh)
WITH (timescaledb.continuous, timescaledb.materialized_only=true) WITH (timescaledb.continuous, timescaledb.materialized_only=true)
as as
@ -247,7 +247,7 @@ order by time_bucket('1week', timec);
-- TEST5 -- -- TEST5 --
---------test with having clause ---------------------- ---------test with having clause ----------------------
drop view mat_m1 cascade; DROP VIEW mat_m1;
create or replace view mat_m1( timec, minl, sumth, stddevh) create or replace view mat_m1( timec, minl, sumth, stddevh)
WITH (timescaledb.continuous, timescaledb.materialized_only=true) WITH (timescaledb.continuous, timescaledb.materialized_only=true)
as as
@ -312,7 +312,6 @@ select generate_series('2018-11-01 00:00'::timestamp, '2018-12-31 00:00'::timest
insert into conditions insert into conditions
select generate_series('2018-11-01 00:00'::timestamp, '2018-12-15 00:00'::timestamp, '1 day'), 'LA', 73, 55, 71, 28; select generate_series('2018-11-01 00:00'::timestamp, '2018-12-15 00:00'::timestamp, '1 day'), 'LA', 73, 55, 71, 28;
--drop view mat_m1 cascade;
--naming with AS clauses --naming with AS clauses
create or replace view mat_naming create or replace view mat_naming
WITH (timescaledb.continuous, timescaledb.materialized_only=true) WITH (timescaledb.continuous, timescaledb.materialized_only=true)
@ -337,7 +336,7 @@ where attnum > 0 and attrelid =
(Select oid from pg_class where relname like :'MAT_TABLE_NAME') (Select oid from pg_class where relname like :'MAT_TABLE_NAME')
order by attnum, attname; order by attnum, attname;
DROP VIEW mat_naming CASCADE; DROP VIEW mat_naming;
--naming with default names --naming with default names
create or replace view mat_naming create or replace view mat_naming
@ -363,7 +362,7 @@ where attnum > 0 and attrelid =
(Select oid from pg_class where relname like :'MAT_TABLE_NAME') (Select oid from pg_class where relname like :'MAT_TABLE_NAME')
order by attnum, attname; order by attnum, attname;
DROP VIEW mat_naming CASCADE; DROP VIEW mat_naming;
--naming with view col names --naming with view col names
create or replace view mat_naming (bucket, loc, sum_t_h, stdd) create or replace view mat_naming (bucket, loc, sum_t_h, stdd)
@ -389,7 +388,7 @@ where attnum > 0 and attrelid =
(Select oid from pg_class where relname like :'MAT_TABLE_NAME') (Select oid from pg_class where relname like :'MAT_TABLE_NAME')
order by attnum, attname; order by attnum, attname;
DROP VIEW mat_naming CASCADE; DROP VIEW mat_naming;
create or replace view mat_m1( timec, minl, sumth, stddevh) create or replace view mat_m1( timec, minl, sumth, stddevh)
WITH (timescaledb.continuous, timescaledb.materialized_only=true) WITH (timescaledb.continuous, timescaledb.materialized_only=true)
@ -449,7 +448,7 @@ select * from :"PART_VIEW_SCHEMA".:"PART_VIEW_NAME";
SET ROLE :ROLE_DEFAULT_PERM_USER; SET ROLE :ROLE_DEFAULT_PERM_USER;
--lets drop the view and check --lets drop the view and check
drop view mat_m1 cascade; DROP VIEW mat_m1;
drop table conditions; drop table conditions;
CREATE TABLE conditions ( CREATE TABLE conditions (
@ -517,7 +516,6 @@ WHERE user_view_name = 'mat_test'
DROP TABLE :"MAT_SCHEMA_NAME".:"MAT_TABLE_NAME"; DROP TABLE :"MAT_SCHEMA_NAME".:"MAT_TABLE_NAME";
DROP VIEW :"PART_VIEW_SCHEMA".:"PART_VIEW_NAME"; DROP VIEW :"PART_VIEW_SCHEMA".:"PART_VIEW_NAME";
DROP VIEW :"DIR_VIEW_SCHEMA".:"DIR_VIEW_NAME"; DROP VIEW :"DIR_VIEW_SCHEMA".:"DIR_VIEW_NAME";
DROP VIEW mat_test;
\set ON_ERROR_STOP 1 \set ON_ERROR_STOP 1
--catalog entry still there; --catalog entry still there;
@ -531,7 +529,7 @@ select count(*) from pg_class where relname = :'MAT_TABLE_NAME';
select count(*) from pg_class where relname = :'DIR_VIEW_NAME'; select count(*) from pg_class where relname = :'DIR_VIEW_NAME';
select count(*) from pg_class where relname = 'mat_test'; select count(*) from pg_class where relname = 'mat_test';
DROP VIEW mat_test CASCADE; DROP VIEW mat_test;
--catalog entry should be gone --catalog entry should be gone
SELECT count(*) SELECT count(*)
@ -657,7 +655,7 @@ INNER JOIN _timescaledb_catalog.hypertable h ON(h.id = ca.mat_hypertable_id)
WHERE user_view_name = 'mat_with_test') WHERE user_view_name = 'mat_with_test')
order by indexname; order by indexname;
drop view mat_with_test cascade; DROP VIEW mat_with_test;
--no additional indexes --no additional indexes
create or replace view mat_with_test( timec, minl, sumt , sumh) create or replace view mat_with_test( timec, minl, sumt , sumh)
WITH (timescaledb.continuous, timescaledb.materialized_only=true, timescaledb.refresh_lag = '5 hours', timescaledb.refresh_interval = '1h', timescaledb.create_group_indexes=false) WITH (timescaledb.continuous, timescaledb.materialized_only=true, timescaledb.refresh_lag = '5 hours', timescaledb.refresh_interval = '1h', timescaledb.create_group_indexes=false)
@ -844,7 +842,7 @@ REFRESH MATERIALIZED VIEW mat_ffunc_test;
SELECT * FROM mat_ffunc_test; SELECT * FROM mat_ffunc_test;
DROP view mat_ffunc_test cascade; DROP view mat_ffunc_test;
create or replace view mat_ffunc_test create or replace view mat_ffunc_test
WITH (timescaledb.continuous, timescaledb.materialized_only=true, timescaledb.refresh_lag = '-200') WITH (timescaledb.continuous, timescaledb.materialized_only=true, timescaledb.refresh_lag = '-200')
@ -858,7 +856,7 @@ REFRESH MATERIALIZED VIEW mat_ffunc_test;
SELECT * FROM mat_ffunc_test; SELECT * FROM mat_ffunc_test;
--refresh mat view test when time_bucket is not projected -- --refresh mat view test when time_bucket is not projected --
drop view mat_ffunc_test cascade; DROP VIEW mat_ffunc_test;
create or replace view mat_refresh_test create or replace view mat_refresh_test
WITH (timescaledb.continuous, timescaledb.materialized_only=true, timescaledb.refresh_lag = '-200') WITH (timescaledb.continuous, timescaledb.materialized_only=true, timescaledb.refresh_lag = '-200')
as as

View File

@ -219,7 +219,7 @@ SELECT * FROM test_continuous_agg_view ORDER BY 1;
-- fast restart test -- fast restart test
SELECT ts_bgw_params_reset_time(); SELECT ts_bgw_params_reset_time();
DROP VIEW test_continuous_agg_view CASCADE; DROP VIEW test_continuous_agg_view;
CREATE VIEW test_continuous_agg_view CREATE VIEW test_continuous_agg_view
WITH (timescaledb.continuous, WITH (timescaledb.continuous,
@ -283,7 +283,7 @@ select view_name, completed_threshold, invalidation_threshold, job_status, last_
\x off \x off
DROP VIEW test_continuous_agg_view CASCADE; DROP VIEW test_continuous_agg_view;
--create a view with a function that it has no permission to execute --create a view with a function that it has no permission to execute
CREATE VIEW test_continuous_agg_view CREATE VIEW test_continuous_agg_view

View File

@ -81,7 +81,7 @@ SELECT
\gset \gset
DROP VIEW if exists mat_test cascade; DROP VIEW IF EXISTS mat_test;
--materialize this VIEW before dump this tests --materialize this VIEW before dump this tests
--that the partial state survives the dump intact --that the partial state survives the dump intact
@ -138,8 +138,6 @@ SELECT _timescaledb_internal.stop_background_workers();
\set ON_ERROR_STOP 0 \set ON_ERROR_STOP 0
DROP table :"MAT_SCHEMA_NAME".:"MAT_TABLE_NAME"; DROP table :"MAT_SCHEMA_NAME".:"MAT_TABLE_NAME";
DROP VIEW :"PART_VIEW_SCHEMA".:"PART_VIEW_NAME"; DROP VIEW :"PART_VIEW_SCHEMA".:"PART_VIEW_NAME";
DROP VIEW mat_before;
DROP VIEW mat_after;
\set ON_ERROR_STOP 1 \set ON_ERROR_STOP 1
--materialize mat_after --materialize mat_after
@ -161,5 +159,5 @@ SELECT count(*) FROM conditions_after;
\ir include/cont_agg_test_equal.sql \ir include/cont_agg_test_equal.sql
\set ECHO all \set ECHO all
DROP VIEW mat_after cascade; DROP VIEW mat_after;
DROP VIEW mat_before cascade; DROP VIEW mat_before;

View File

@ -471,7 +471,7 @@ ALTER VIEW mat_with_test SET(timescaledb.refresh_lag = '1h');
ALTER VIEW mat_with_test SET(timescaledb.refresh_lag = '2147483648'); ALTER VIEW mat_with_test SET(timescaledb.refresh_lag = '2147483648');
ALTER TABLE conditions ALTER timec type bigint; ALTER TABLE conditions ALTER timec type bigint;
\set ON_ERROR_STOP \set ON_ERROR_STOP
drop view mat_with_test CASCADE; DROP VIEW mat_with_test;
ALTER TABLE conditions ALTER timec type bigint; ALTER TABLE conditions ALTER timec type bigint;
create or replace view mat_with_test( timec, minl, sumt , sumh) create or replace view mat_with_test( timec, minl, sumt , sumh)

View File

@ -434,8 +434,8 @@ SELECT hypertable_id, watermark
WHERE hypertable_id=:raw_table_id; WHERE hypertable_id=:raw_table_id;
--cleanup of continuous agg views -- --cleanup of continuous agg views --
DROP view test_t_mat_view CASCADE; DROP view test_t_mat_view;
DROP view extreme_view CASCADE; DROP view extreme_view;
-- negative lag test -- negative lag test
CREATE TABLE continuous_agg_negative(time BIGINT, data BIGINT); CREATE TABLE continuous_agg_negative(time BIGINT, data BIGINT);
@ -472,7 +472,7 @@ INSERT INTO continuous_agg_negative VALUES (:big_int_max-3, 201);
REFRESH MATERIALIZED VIEW negative_view_5; REFRESH MATERIALIZED VIEW negative_view_5;
SELECT * FROM negative_view_5 ORDER BY 1; SELECT * FROM negative_view_5 ORDER BY 1;
DROP VIEW negative_view_5 CASCADE; DROP VIEW negative_view_5;
TRUNCATE continuous_agg_negative; TRUNCATE continuous_agg_negative;
CREATE VIEW negative_view_5 CREATE VIEW negative_view_5

View File

@ -83,7 +83,7 @@ select count(*) from _timescaledb_catalog.continuous_aggs_hypertable_invalidatio
select count(*) from _timescaledb_catalog.continuous_aggs_materialization_invalidation_log; select count(*) from _timescaledb_catalog.continuous_aggs_materialization_invalidation_log;
--now drop cagg_1, should still have materialization_invalidation_log --now drop cagg_1, should still have materialization_invalidation_log
drop view cagg_1 cascade; DROP VIEW cagg_1;
select count(*) from _timescaledb_catalog.continuous_aggs_materialization_invalidation_log; select count(*) from _timescaledb_catalog.continuous_aggs_materialization_invalidation_log;
--cagg_2 still exists --cagg_2 still exists
select view_name from timescaledb_information.continuous_aggregates; select view_name from timescaledb_information.continuous_aggregates;
@ -145,8 +145,8 @@ refresh materialized view cagg_1;
select * from cagg_1 where timed = 18 ; select * from cagg_1 where timed = 18 ;
--copied over for cagg_2 to process later? --copied over for cagg_2 to process later?
select * from _timescaledb_catalog.continuous_aggs_materialization_invalidation_log order by 1; select * from _timescaledb_catalog.continuous_aggs_materialization_invalidation_log order by 1;
DROP VIEW cagg_1 cascade; DROP VIEW cagg_1;
DROP VIEW cagg_2 cascade; DROP VIEW cagg_2;
--TEST6 test the ignore_invalidation_older_than setting --TEST6 test the ignore_invalidation_older_than setting
CREATE TABLE continuous_agg_test_ignore_invalidation_older_than(timeval integer, col1 integer, col2 integer); CREATE TABLE continuous_agg_test_ignore_invalidation_older_than(timeval integer, col1 integer, col2 integer);

View File

@ -103,7 +103,7 @@ select from alter_job_schedule(:cagg_job_id, max_runtime => NULL);
ALTER VIEW mat_refresh_test SET(timescaledb.refresh_lag = '6 h', timescaledb.refresh_interval = '2h'); ALTER VIEW mat_refresh_test SET(timescaledb.refresh_lag = '6 h', timescaledb.refresh_interval = '2h');
ALTER VIEW mat_refresh_test SET(timescaledb.materialized_only = true); ALTER VIEW mat_refresh_test SET(timescaledb.materialized_only = true);
DROP VIEW mat_refresh_test CASCADE; DROP VIEW mat_refresh_test;
REFRESH MATERIALIZED VIEW mat_refresh_test; REFRESH MATERIALIZED VIEW mat_refresh_test;
SELECT * FROM mat_refresh_test; SELECT * FROM mat_refresh_test;
SELECT * FROM :materialization_hypertable; SELECT * FROM :materialization_hypertable;
@ -136,7 +136,7 @@ group by time_bucket(100, timec), location;
--this should fail --this should fail
REFRESH MATERIALIZED VIEW mat_perm_view_test; REFRESH MATERIALIZED VIEW mat_perm_view_test;
DROP VIEW mat_perm_view_test CASCADE; DROP VIEW mat_perm_view_test;
--can create a mat view on something with select and trigger grants --can create a mat view on something with select and trigger grants
create or replace view mat_perm_view_test create or replace view mat_perm_view_test

View File

@ -66,7 +66,7 @@ SELECT pg_get_viewdef('metrics_summary',true);
-- view should have results now after refresh -- view should have results now after refresh
SELECT time_bucket,avg FROM metrics_summary ORDER BY 1; SELECT time_bucket,avg FROM metrics_summary ORDER BY 1;
DROP VIEW metrics_summary CASCADE; DROP VIEW metrics_summary;
-- check default view for new continuous aggregate with materialized_only to true -- check default view for new continuous aggregate with materialized_only to true
CREATE VIEW metrics_summary CREATE VIEW metrics_summary
@ -93,7 +93,7 @@ SELECT user_view_name, materialized_only FROM _timescaledb_catalog.continuous_ag
SELECT pg_get_viewdef('metrics_summary',true); SELECT pg_get_viewdef('metrics_summary',true);
SELECT time_bucket,avg FROM metrics_summary ORDER BY 1; SELECT time_bucket,avg FROM metrics_summary ORDER BY 1;
DROP VIEW metrics_summary CASCADE; DROP VIEW metrics_summary;
-- --
-- test queries on union view -- test queries on union view
@ -245,7 +245,7 @@ GROUP BY time_bucket(1, a)
HAVING sum(c) > 50 HAVING sum(c) > 50
ORDER BY 1; ORDER BY 1;
DROP VIEW mat_m1 cascade; DROP VIEW mat_m1;
--- TEST union view with multiple WHERE and HAVING clauses --- TEST union view with multiple WHERE and HAVING clauses
CREATE VIEW mat_m1 CREATE VIEW mat_m1

View File

@ -118,7 +118,7 @@ SELECT * FROM device_summary WHERE device_id = 'device_1' and bucket = 'Sun Dec
-- a timezone setting can alter from user-to-user and thus -- a timezone setting can alter from user-to-user and thus
-- cannot be materialized. -- cannot be materialized.
DROP VIEW device_summary CASCADE; DROP VIEW device_summary;
CREATE VIEW device_summary CREATE VIEW device_summary
WITH (timescaledb.continuous, timescaledb.materialized_only=true) WITH (timescaledb.continuous, timescaledb.materialized_only=true)
AS AS
@ -136,7 +136,7 @@ GROUP BY bucket, device_id;
-- You have two options: -- You have two options:
-- Option 1: be explicit in your timezone: -- Option 1: be explicit in your timezone:
DROP VIEW device_summary CASCADE; DROP VIEW device_summary;
CREATE VIEW device_summary CREATE VIEW device_summary
WITH (timescaledb.continuous, timescaledb.materialized_only=true) WITH (timescaledb.continuous, timescaledb.materialized_only=true)
AS AS
@ -149,12 +149,12 @@ SELECT
FROM FROM
device_readings device_readings
GROUP BY bucket, device_id; GROUP BY bucket, device_id;
DROP VIEW device_summary CASCADE; DROP VIEW device_summary;
-- Option 2: Keep things as TIMESTAMPTZ in the view and convert to local time when -- Option 2: Keep things as TIMESTAMPTZ in the view and convert to local time when
-- querying from the view -- querying from the view
DROP VIEW device_summary CASCADE; DROP VIEW device_summary;
CREATE VIEW device_summary CREATE VIEW device_summary
WITH (timescaledb.continuous, timescaledb.materialized_only=true) WITH (timescaledb.continuous, timescaledb.materialized_only=true)
AS AS
@ -236,5 +236,49 @@ SELECT * FROM device_readings_mat_only ORDER BY time_bucket;
-- jit aggregate should have 6 rows -- jit aggregate should have 6 rows
SELECT * FROM device_readings_jit ORDER BY time_bucket; SELECT * FROM device_readings_jit ORDER BY time_bucket;
-- START OF BASIC USAGE TESTS --
-- Check that continuous aggregate and materialized table is dropped
-- together.
CREATE TABLE whatever(time TIMESTAMPTZ NOT NULL, metric INTEGER);
SELECT * FROM create_hypertable('whatever', 'time');
CREATE VIEW whatever_summary WITH (timescaledb.continuous) AS
SELECT time_bucket('1 hour', time) AS bucket, avg(metric)
FROM whatever GROUP BY bucket;
SELECT (SELECT format('%1$I.%2$I', schema_name, table_name)::regclass::oid
FROM _timescaledb_catalog.hypertable
WHERE id = raw_hypertable_id) AS raw_table
, (SELECT format('%1$I.%2$I', schema_name, table_name)::regclass::oid
FROM _timescaledb_catalog.hypertable
WHERE id = mat_hypertable_id) AS mat_table
FROM _timescaledb_catalog.continuous_agg
WHERE user_view_name = 'whatever_summary' \gset
SELECT relname FROM pg_class WHERE oid = :mat_table;
----------------------------------------------------------------
-- Should generate an error since the cagg is dependent on the table.
DROP TABLE whatever;
----------------------------------------------------------------
-- Checking that a cagg cannot be dropped if there is a dependent
-- object on it.
CREATE VIEW whatever_summary_dependency AS SELECT * FROM whatever_summary;
-- Should generate an error
DROP VIEW whatever_summary;
-- Dropping the dependent view so that we can do a proper drop below.
DROP VIEW whatever_summary_dependency;
----------------------------------------------------------------
-- Dropping the cagg should also remove the materialized table
DROP VIEW whatever_summary;
SELECT relname FROM pg_class WHERE oid = :mat_table;
----------------------------------------------------------------
-- Cleanup
DROP TABLE whatever;
-- END OF BASIC USAGE TESTS --

View File

@ -5,7 +5,7 @@
--expects QUERY to be set --expects QUERY to be set
\o /dev/null \o /dev/null
drop view if exists mat_test cascade; DROP VIEW IF EXISTS mat_test;
create view mat_test create view mat_test
WITH ( timescaledb.continuous) WITH ( timescaledb.continuous)

View File

@ -827,7 +827,7 @@ FROM cagg_test
ORDER BY time ORDER BY time
LIMIT 1; LIMIT 1;
DROP VIEW cagg_test CASCADE; DROP VIEW cagg_test;
RESET client_min_messages; RESET client_min_messages;