Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cagg trigger on compat schema layer #6163

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions sql/compat.sql
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,8 @@ BEGIN
END$$
SET search_path TO pg_catalog,pg_temp;


CREATE OR REPLACE FUNCTION _timescaledb_internal.continuous_agg_invalidation_trigger() RETURNS trigger LANGUAGE PLPGSQL AS $$
BEGIN
IF current_setting('timescaledb.enable_deprecation_warnings', true)::bool THEN
RAISE WARNING 'function _timescaledb_internal.continuous_agg_invalidation_trigger() is deprecated and has been moved to _timescaledb_functions schema. this compatibility function will be removed in a future version.';
END IF;
RETURN _timescaledb_functions.continuous_agg_invalidation_trigger();
END$$
SET search_path TO pg_catalog,pg_temp;

CREATE OR REPLACE FUNCTION _timescaledb_internal.continuous_agg_invalidation_trigger() RETURNS TRIGGER
AS '@MODULE_PATHNAME@', 'ts_continuous_agg_invalidation_trigger' LANGUAGE C;

-- we have to prefix slices, schema_name and table_name parameter with _ here to not clash with output names otherwise plpgsql will complain
CREATE OR REPLACE FUNCTION _timescaledb_internal.create_chunk(hypertable regclass,_slices jsonb,_schema_name name=NULL,_table_name name=NULL,chunk_table regclass=NULL) RETURNS TABLE(chunk_id INTEGER, hypertable_id INTEGER, schema_name NAME, table_name NAME, relkind "char", slices JSONB, created BOOLEAN) LANGUAGE PLPGSQL AS $$
Expand Down
43 changes: 43 additions & 0 deletions tsl/test/shared/expected/compat.out
Original file line number Diff line number Diff line change
Expand Up @@ -421,3 +421,46 @@ WARNING: procedure _timescaledb_internal.policy_retention(integer,jsonb) is dep
CALL _timescaledb_internal.wait_subscription_sync(NULL,NULL,0,0);
WARNING: procedure _timescaledb_internal.wait_subscription_sync(name,name,integer,numeric) is deprecated and has been moved to _timescaledb_functions schema. this compatibility function will be removed in a future version.
ERROR: subscription sync wait timedout
\set ON_ERROR_STOP 1
-- tests for the cagg invalidation trigger on the deprecated schema
CREATE TABLE sensor_data (
time TIMESTAMPTZ NOT NULL,
temperature DOUBLE PRECISION NULL
);
SELECT hypertable_id FROM create_hypertable('sensor_data','time') \gset
CREATE MATERIALIZED VIEW sensor_data_hourly WITH (timescaledb.continuous, timescaledb.materialized_only=false) AS
SELECT time_bucket(INTERVAL '1 hour', time),
min(time),
max(time)
FROM sensor_data
GROUP BY 1
WITH DATA;
NOTICE: continuous aggregate "sensor_data_hourly" is already up-to-date
DROP TRIGGER ts_cagg_invalidation_trigger ON sensor_data;
CREATE TRIGGER ts_cagg_invalidation_trigger
AFTER INSERT OR DELETE OR UPDATE ON sensor_data
FOR EACH ROW EXECUTE FUNCTION _timescaledb_internal.continuous_agg_invalidation_trigger(:'hypertable_id');
INSERT INTO sensor_data values('1980-01-01 00:00:00-00', 1);
CALL refresh_continuous_aggregate('sensor_data_hourly', NULL, NULL);
-- should not return rows because there's old invalid regions
SELECT lowest_modified_value, greatest_modified_value
FROM _timescaledb_catalog.continuous_aggs_hypertable_invalidation_log
WHERE hypertable_id = :'hypertable_id';
lowest_modified_value | greatest_modified_value
-----------------------+-------------------------
(0 rows)

-- insert old data to create invalidation log
INSERT INTO sensor_data values('1979-12-31 00:00:00-00', 1);
-- should return the invalidation log generated by previous insert
SELECT lowest_modified_value, greatest_modified_value
FROM _timescaledb_catalog.continuous_aggs_hypertable_invalidation_log
WHERE hypertable_id = :'hypertable_id';
lowest_modified_value | greatest_modified_value
-----------------------+-------------------------
315446400000000 | 315446400000000
(1 row)

DROP MATERIALIZED VIEW sensor_data_hourly;
NOTICE: drop cascades to table _timescaledb_internal._hyper_X_X_chunk
DROP TABLE sensor_data CASCADE;
40 changes: 40 additions & 0 deletions tsl/test/shared/sql/compat.sql
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,45 @@ CALL _timescaledb_internal.policy_recompression(0,NULL);
CALL _timescaledb_internal.policy_refresh_continuous_aggregate(0,NULL);
CALL _timescaledb_internal.policy_reorder(0,NULL);
CALL _timescaledb_internal.policy_retention(0,NULL);

CALL _timescaledb_internal.wait_subscription_sync(NULL,NULL,0,0);
\set ON_ERROR_STOP 1

-- tests for the cagg invalidation trigger on the deprecated schema
CREATE TABLE sensor_data (
time TIMESTAMPTZ NOT NULL,
temperature DOUBLE PRECISION NULL
);

SELECT hypertable_id FROM create_hypertable('sensor_data','time') \gset

CREATE MATERIALIZED VIEW sensor_data_hourly WITH (timescaledb.continuous, timescaledb.materialized_only=false) AS
SELECT time_bucket(INTERVAL '1 hour', time),
min(time),
max(time)
FROM sensor_data
GROUP BY 1
WITH DATA;

DROP TRIGGER ts_cagg_invalidation_trigger ON sensor_data;

CREATE TRIGGER ts_cagg_invalidation_trigger
AFTER INSERT OR DELETE OR UPDATE ON sensor_data
FOR EACH ROW EXECUTE FUNCTION _timescaledb_internal.continuous_agg_invalidation_trigger(:'hypertable_id');

INSERT INTO sensor_data values('1980-01-01 00:00:00-00', 1);
CALL refresh_continuous_aggregate('sensor_data_hourly', NULL, NULL);
-- should not return rows because there's old invalid regions
SELECT lowest_modified_value, greatest_modified_value
FROM _timescaledb_catalog.continuous_aggs_hypertable_invalidation_log
WHERE hypertable_id = :'hypertable_id';

-- insert old data to create invalidation log
INSERT INTO sensor_data values('1979-12-31 00:00:00-00', 1);
-- should return the invalidation log generated by previous insert
SELECT lowest_modified_value, greatest_modified_value
FROM _timescaledb_catalog.continuous_aggs_hypertable_invalidation_log
WHERE hypertable_id = :'hypertable_id';

DROP MATERIALIZED VIEW sensor_data_hourly;
DROP TABLE sensor_data CASCADE;
Loading