Skip to content

Commit

Permalink
Enable continuous_aggs tests on all PG version.
Browse files Browse the repository at this point in the history
  • Loading branch information
sb230132 authored and nikkhils committed Apr 28, 2023
1 parent 1d09256 commit bd9df4c
Show file tree
Hide file tree
Showing 22 changed files with 8,153 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ accidentally triggering the load of a previous DB version.**
* #5615 Add permission checks to run_job()
* #5614 Enable run_job() for telemetry job
* #5578 Fix on-insert decompression after schema changes
* #5613 Quote username identifier appropriately

**Thanks**
* @kovetskiy and @DZDomi for reporting peformance regression in Realtime Continuous Aggregates
Expand Down
2 changes: 1 addition & 1 deletion sql/job_error_log_retention.sql
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ VALUES
INTERVAL '1h',
'_timescaledb_internal',
'policy_job_error_retention',
current_role::regrole,
quote_ident(current_role)::regrole,
true,
'{"drop_after":"1 month"}',
'_timescaledb_internal',
Expand Down
2 changes: 1 addition & 1 deletion sql/pre_install/tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ CREATE TABLE _timescaledb_config.bgw_job (
retry_period interval NOT NULL,
proc_schema name NOT NULL,
proc_name name NOT NULL,
owner regrole NOT NULL DEFAULT current_role::regrole,
owner regrole NOT NULL DEFAULT quote_ident(current_role)::regrole,
scheduled bool NOT NULL DEFAULT TRUE,
fixed_schedule bool not null default true,
initial_start timestamptz,
Expand Down
70 changes: 70 additions & 0 deletions sql/updates/latest-dev.sql
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,73 @@ ALTER FUNCTION _timescaledb_internal.compressed_data_recv(internal) SET SCHEMA _
ALTER FUNCTION _timescaledb_internal.rxid_in(cstring) SET SCHEMA _timescaledb_functions;
ALTER FUNCTION _timescaledb_internal.rxid_out(@extschema@.rxid) SET SCHEMA _timescaledb_functions;

-- drop dependent views
DROP VIEW IF EXISTS timescaledb_information.job_errors;
DROP VIEW IF EXISTS timescaledb_information.job_stats;
DROP VIEW IF EXISTS timescaledb_information.jobs;
DROP VIEW IF EXISTS timescaledb_experimental.policies;

ALTER TABLE _timescaledb_config.bgw_job
ALTER COLUMN owner DROP DEFAULT,
ALTER COLUMN owner TYPE regrole USING quote_ident(owner)::regrole,
ALTER COLUMN owner SET DEFAULT quote_ident(current_role)::regrole;
CREATE TABLE _timescaledb_config.bgw_job_tmp AS SELECT * FROM _timescaledb_config.bgw_job;

ALTER EXTENSION timescaledb DROP TABLE _timescaledb_config.bgw_job;
ALTER EXTENSION timescaledb DROP SEQUENCE _timescaledb_config.bgw_job_id_seq;
ALTER TABLE _timescaledb_internal.bgw_job_stat
DROP CONSTRAINT IF EXISTS bgw_job_stat_job_id_fkey;
ALTER TABLE _timescaledb_internal.bgw_policy_chunk_stats
DROP CONSTRAINT IF EXISTS bgw_policy_chunk_stats_job_id_fkey;
CREATE TABLE _timescaledb_internal.tmp_bgw_job_seq_value AS
SELECT last_value, is_called FROM _timescaledb_config.bgw_job_id_seq;
DROP TABLE _timescaledb_config.bgw_job;

CREATE SEQUENCE _timescaledb_config.bgw_job_id_seq MINVALUE 1000;
SELECT pg_catalog.pg_extension_config_dump('_timescaledb_config.bgw_job_id_seq', '');
SELECT pg_catalog.setval('_timescaledb_config.bgw_job_id_seq', last_value, is_called)
FROM _timescaledb_internal.tmp_bgw_job_seq_value;
DROP TABLE _timescaledb_internal.tmp_bgw_job_seq_value;

CREATE TABLE _timescaledb_config.bgw_job (
id integer NOT NULL DEFAULT nextval('_timescaledb_config.bgw_job_id_seq'),
application_name name NOT NULL,
schedule_interval interval NOT NULL,
max_runtime interval NOT NULL,
max_retries integer NOT NULL,
retry_period interval NOT NULL,
proc_schema name NOT NULL,
proc_name name NOT NULL,
owner regrole NOT NULL DEFAULT quote_ident(current_role)::regrole,
scheduled bool NOT NULL DEFAULT TRUE,
fixed_schedule bool not null default true,
initial_start timestamptz,
hypertable_id integer,
config jsonb,
check_schema name,
check_name name,
timezone text,
CONSTRAINT bgw_job_pkey PRIMARY KEY (id),
CONSTRAINT bgw_job_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable (id) ON DELETE CASCADE
);

ALTER SEQUENCE _timescaledb_config.bgw_job_id_seq OWNED BY _timescaledb_config.bgw_job.id;
CREATE INDEX bgw_job_proc_hypertable_id_idx
ON _timescaledb_config.bgw_job(proc_schema,proc_name,hypertable_id);
INSERT INTO _timescaledb_config.bgw_job
SELECT * FROM _timescaledb_config.bgw_job_tmp ORDER BY id;
DROP TABLE _timescaledb_config.bgw_job_tmp;
ALTER TABLE _timescaledb_internal.bgw_job_stat
ADD CONSTRAINT bgw_job_stat_job_id_fkey
FOREIGN KEY(job_id)
REFERENCES _timescaledb_config.bgw_job(id)
ON DELETE CASCADE;
ALTER TABLE _timescaledb_internal.bgw_policy_chunk_stats
ADD CONSTRAINT bgw_policy_chunk_stats_job_id_fkey
FOREIGN KEY(job_id)
REFERENCES _timescaledb_config.bgw_job(id)
ON DELETE CASCADE;

SELECT pg_catalog.pg_extension_config_dump('_timescaledb_config.bgw_job', 'WHERE id >= 1000');
GRANT SELECT ON _timescaledb_config.bgw_job TO PUBLIC;
GRANT SELECT ON _timescaledb_config.bgw_job_id_seq TO PUBLIC;
65 changes: 65 additions & 0 deletions sql/updates/reverse-dev.sql
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,68 @@ BEGIN
END
$BODY$ SET search_path TO pg_catalog, pg_temp;

+-- drop dependent views
DROP VIEW IF EXISTS timescaledb_information.job_errors;
DROP VIEW IF EXISTS timescaledb_information.job_stats;
DROP VIEW IF EXISTS timescaledb_information.jobs;
DROP VIEW IF EXISTS timescaledb_experimental.policies;

ALTER TABLE _timescaledb_config.bgw_job
ALTER COLUMN owner DROP DEFAULT,
ALTER COLUMN owner TYPE regrole USING owner::regrole,
ALTER COLUMN owner SET DEFAULT current_role::regrole;
CREATE TABLE _timescaledb_config.bgw_job_tmp AS SELECT * FROM _timescaledb_config.bgw_job;

ALTER EXTENSION timescaledb DROP TABLE _timescaledb_config.bgw_job;
ALTER EXTENSION timescaledb DROP SEQUENCE _timescaledb_config.bgw_job_id_seq;
ALTER TABLE _timescaledb_internal.bgw_job_stat
DROP CONSTRAINT IF EXISTS bgw_job_stat_job_id_fkey;
ALTER TABLE _timescaledb_internal.bgw_policy_chunk_stats
DROP CONSTRAINT IF EXISTS bgw_policy_chunk_stats_job_id_fkey;
CREATE TABLE _timescaledb_internal.tmp_bgw_job_seq_value AS
SELECT last_value, is_called FROM _timescaledb_config.bgw_job_id_seq;
DROP TABLE _timescaledb_config.bgw_job;


CREATE TABLE _timescaledb_config.bgw_job (
id integer NOT NULL DEFAULT nextval('_timescaledb_config.bgw_job_id_seq'),
application_name name NOT NULL,
schedule_interval interval NOT NULL,
max_runtime interval NOT NULL,
max_retries integer NOT NULL,
retry_period interval NOT NULL,
proc_schema name NOT NULL,
proc_name name NOT NULL,
owner regrole NOT NULL DEFAULT current_role::regrole
scheduled bool NOT NULL DEFAULT TRUE,
fixed_schedule bool not null default true,
initial_start timestamptz,
hypertable_id integer,
config jsonb,
check_schema name,
check_name name,
timezone text,
CONSTRAINT bgw_job_pkey PRIMARY KEY (id),
CONSTRAINT bgw_job_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable (id) ON DELETE CASCADE
);

ALTER SEQUENCE _timescaledb_config.bgw_job_id_seq OWNED BY _timescaledb_config.bgw_job.id;
CREATE INDEX bgw_job_proc_hypertable_id_idx
ON _timescaledb_config.bgw_job(proc_schema,proc_name,hypertable_id);
INSERT INTO _timescaledb_config.bgw_job
SELECT * FROM _timescaledb_config.bgw_job_tmp ORDER BY id;
DROP TABLE _timescaledb_config.bgw_job_tmp;
ALTER TABLE _timescaledb_internal.bgw_job_stat
ADD CONSTRAINT bgw_job_stat_job_id_fkey
FOREIGN KEY(job_id)
REFERENCES _timescaledb_config.bgw_job(id)
ON DELETE CASCADE;
ALTER TABLE _timescaledb_internal.bgw_policy_chunk_stats
ADD CONSTRAINT bgw_policy_chunk_stats_job_id_fkey
FOREIGN KEY(job_id)
REFERENCES _timescaledb_config.bgw_job(id)
ON DELETE CASCADE;

SELECT pg_catalog.pg_extension_config_dump('_timescaledb_config.bgw_job', 'WHERE id >= 1000');
GRANT SELECT ON _timescaledb_config.bgw_job TO PUBLIC;
GRANT SELECT ON _timescaledb_config.bgw_job_id_seq TO PUBLIC;
2 changes: 1 addition & 1 deletion sql/with_telemetry.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ CREATE OR REPLACE FUNCTION @extschema@.get_telemetry_report() RETURNS jsonb
LANGUAGE C STABLE PARALLEL SAFE;

INSERT INTO _timescaledb_config.bgw_job (id, application_name, schedule_interval, max_runtime, max_retries, retry_period, proc_schema, proc_name, owner, scheduled, fixed_schedule) VALUES
(1, 'Telemetry Reporter [1]', INTERVAL '24h', INTERVAL '100s', -1, INTERVAL '1h', '_timescaledb_internal', 'policy_telemetry', current_role::regrole, true, false)
(1, 'Telemetry Reporter [1]', INTERVAL '24h', INTERVAL '100s', -1, INTERVAL '1h', '_timescaledb_internal', 'policy_telemetry', quote_ident(current_role)::regrole, true, false)
ON CONFLICT (id) DO NOTHING;
7 changes: 7 additions & 0 deletions test/expected/extension_scripts.out
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ CREATE OR REPLACE FUNCTION show_chunks(relation regclass, older_than "any" DEFAU
CREATE EXTENSION timescaledb;
ERROR: function "show_chunks" already exists with same argument types
DROP FUNCTION show_chunks;
-- Create a user that is not all-lowercase
CREATE USER "FooBar" WITH SUPERUSER;
\c :TEST_DBNAME "FooBar"
SET client_min_messages TO error;
CREATE EXTENSION timescaledb;
DROP EXTENSION timescaledb;
RESET client_min_messages;
\c :TEST_DBNAME :ROLE_SUPERUSER
SET client_min_messages TO ERROR;
CREATE EXTENSION timescaledb;
9 changes: 9 additions & 0 deletions test/sql/extension_scripts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ CREATE OR REPLACE FUNCTION show_chunks(relation regclass, older_than "any" DEFAU
CREATE EXTENSION timescaledb;
DROP FUNCTION show_chunks;

-- Create a user that is not all-lowercase
CREATE USER "FooBar" WITH SUPERUSER;

\c :TEST_DBNAME "FooBar"
SET client_min_messages TO error;
CREATE EXTENSION timescaledb;
DROP EXTENSION timescaledb;
RESET client_min_messages;

\c :TEST_DBNAME :ROLE_SUPERUSER
SET client_min_messages TO ERROR;
CREATE EXTENSION timescaledb;
Expand Down
2 changes: 1 addition & 1 deletion tsl/test/expected/bgw_db_scheduler_fixed.out
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ CREATE OR REPLACE FUNCTION insert_job(
schedule_interval INTERVAL,
max_runtime INTERVAL,
retry_period INTERVAL,
owner regrole DEFAULT current_role::regrole,
owner regrole DEFAULT quote_ident(current_role)::regrole,
scheduled BOOL DEFAULT true,
fixed_schedule BOOL DEFAULT true
)
Expand Down
10 changes: 6 additions & 4 deletions tsl/test/expected/continuous_aggs-12.out
Original file line number Diff line number Diff line change
Expand Up @@ -1552,11 +1552,13 @@ SELECT * from search_query_count_3 ORDER BY 1, 2, 3;
-- more data
-- ).
insert into raw_data select '2000-05-01 00:00+0','Q3', 0, 0;

-- On PG >= 14 the refresh test below will pass because we added support for UPDATE/DELETE on compressed chunks in PR #5339
\set ON_ERROR_STOP 0
CALL refresh_continuous_aggregate('search_query_count_3', NULL, '2000-06-01 00:00+0'::timestamptz);
ERROR: cannot update/delete rows from chunk "_hyper_41_79_chunk" as it is compressed
CALL refresh_continuous_aggregate('search_query_count_3', '2000-05-01 00:00+0'::timestamptz, '2000-06-01 00:00+0'::timestamptz);
NOTICE: continuous aggregate "search_query_count_3" is already up-to-date

ERROR: cannot update/delete rows from chunk "_hyper_41_79_chunk" as it is compressed
\set ON_ERROR_STOP 1
--insert row
insert into raw_data select '2001-05-10 00:00+0','Q3', 100, 100;
--this should succeed since it does not refresh any compressed regions in the cagg
Expand All @@ -1583,7 +1585,7 @@ WHERE materialization_id = :'MAT_HTID' ORDER BY 1, 2,3;
materialization_id | lowest_modified_value | greatest_modified_value
--------------------+-----------------------+-------------------------
41 | -9223372036854775808 | -210866803200000001
41 | 959817600000000 | 988675199999999
41 | 946857660000000 | 988675199999999
41 | 991353600000000 | 9223372036854775807
(3 rows)

Expand Down
9 changes: 6 additions & 3 deletions tsl/test/expected/continuous_aggs-13.out
Original file line number Diff line number Diff line change
Expand Up @@ -1552,10 +1552,13 @@ SELECT * from search_query_count_3 ORDER BY 1, 2, 3;
-- more data
-- ).
insert into raw_data select '2000-05-01 00:00+0','Q3', 0, 0;
-- On PG >= 14 the refresh test below will pass because we added support for UPDATE/DELETE on compressed chunks in PR #5339
\set ON_ERROR_STOP 0
CALL refresh_continuous_aggregate('search_query_count_3', NULL, '2000-06-01 00:00+0'::timestamptz);
ERROR: cannot update/delete rows from chunk "_hyper_41_79_chunk" as it is compressed
CALL refresh_continuous_aggregate('search_query_count_3', '2000-05-01 00:00+0'::timestamptz, '2000-06-01 00:00+0'::timestamptz);
NOTICE: continuous aggregate "search_query_count_3" is already up-to-date

ERROR: cannot update/delete rows from chunk "_hyper_41_79_chunk" as it is compressed
\set ON_ERROR_STOP 1
--insert row
insert into raw_data select '2001-05-10 00:00+0','Q3', 100, 100;
--this should succeed since it does not refresh any compressed regions in the cagg
Expand All @@ -1582,7 +1585,7 @@ WHERE materialization_id = :'MAT_HTID' ORDER BY 1, 2,3;
materialization_id | lowest_modified_value | greatest_modified_value
--------------------+-----------------------+-------------------------
41 | -9223372036854775808 | -210866803200000001
41 | 959817600000000 | 988675199999999
41 | 946857660000000 | 988675199999999
41 | 991353600000000 | 9223372036854775807
(3 rows)

Expand Down
4 changes: 3 additions & 1 deletion tsl/test/expected/continuous_aggs-14.out
Original file line number Diff line number Diff line change
Expand Up @@ -1552,10 +1552,12 @@ SELECT * from search_query_count_3 ORDER BY 1, 2, 3;
-- more data
-- ).
insert into raw_data select '2000-05-01 00:00+0','Q3', 0, 0;
-- On PG >= 14 the refresh test below will pass because we added support for UPDATE/DELETE on compressed chunks in PR #5339
\set ON_ERROR_STOP 0
CALL refresh_continuous_aggregate('search_query_count_3', NULL, '2000-06-01 00:00+0'::timestamptz);
CALL refresh_continuous_aggregate('search_query_count_3', '2000-05-01 00:00+0'::timestamptz, '2000-06-01 00:00+0'::timestamptz);
NOTICE: continuous aggregate "search_query_count_3" is already up-to-date

\set ON_ERROR_STOP 1
--insert row
insert into raw_data select '2001-05-10 00:00+0','Q3', 100, 100;
--this should succeed since it does not refresh any compressed regions in the cagg
Expand Down
4 changes: 3 additions & 1 deletion tsl/test/expected/continuous_aggs-15.out
Original file line number Diff line number Diff line change
Expand Up @@ -1552,10 +1552,12 @@ SELECT * from search_query_count_3 ORDER BY 1, 2, 3;
-- more data
-- ).
insert into raw_data select '2000-05-01 00:00+0','Q3', 0, 0;
-- On PG >= 14 the refresh test below will pass because we added support for UPDATE/DELETE on compressed chunks in PR #5339
\set ON_ERROR_STOP 0
CALL refresh_continuous_aggregate('search_query_count_3', NULL, '2000-06-01 00:00+0'::timestamptz);
CALL refresh_continuous_aggregate('search_query_count_3', '2000-05-01 00:00+0'::timestamptz, '2000-06-01 00:00+0'::timestamptz);
NOTICE: continuous aggregate "search_query_count_3" is already up-to-date

\set ON_ERROR_STOP 1
--insert row
insert into raw_data select '2001-05-10 00:00+0','Q3', 100, 100;
--this should succeed since it does not refresh any compressed regions in the cagg
Expand Down
Loading

0 comments on commit bd9df4c

Please sign in to comment.