Skip to content

Commit de43b80

Browse files
committed
Merge remote-tracking branch 'origin/main' into HEAD
2 parents 20c60cb + 9b42be0 commit de43b80

186 files changed

Lines changed: 5539 additions & 1687 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
/sql/pre_install/*.gen
99
/sql/updates/*.gen
1010
/sql/updates/header.sql
11+
/sql/updates/views_detached.sql
1112
/data/
1213
/src/*.o
1314
/src/*.so

.unreleased/pr_9825

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Implements: #9825 Support ADD COLUMN on continuous aggregates

cmake/GenerateScripts.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function(generate_downgrade_script)
5959
include(
6060
${CMAKE_BINARY_DIR}/v${_downgrade_TARGET_VERSION}/cmake/ScriptFiles.cmake)
6161

62-
set(_downgrade_PRE_FILES "header.sql;${PRE_DOWNGRADE_FILES}")
62+
set(_downgrade_PRE_FILES "header.sql;views_detached.sql;${PRE_DOWNGRADE_FILES}")
6363
set(_downgrade_POST_FILES "${PRE_INSTALL_FUNCTION_FILES};${SOURCE_FILES}" ${POST_UPDATE_FILES})
6464

6565
# Fetch epilog from target version.

scripts/check_updates.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from pglast import parse_sql
88
from pglast.ast import ColumnDef
9+
from pglast.enums.parsenodes import ObjectType
910
from pglast.visitors import Visitor
1011
from pglast import enums
1112
import sys
@@ -178,6 +179,14 @@ def visit_CreateFunctionStmt(
178179
"_timescaledb_functions should be used as schema for internal functions",
179180
)
180181

182+
def visit_DropStmt(self, _ancestors, node):
183+
if node.removeType == ObjectType.OBJECT_VIEW:
184+
if node.objects[0][0].sval == "timescaledb_information":
185+
self.error(
186+
f"Attempting to drop view {node.objects[0][0].sval}.{node.objects[0][1].sval}",
187+
"Views in schema timescaledb_information must not be dropped in update scripts",
188+
)
189+
181190

182191
# copied from pgspot
183192
def visit_sql(sql):

scripts/test_updates.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ if [ -n "${VERSIONS}" ]; then
9191
for version in ${VERSIONS}; do
9292
ts_minor_version=$(echo "${version}" | awk -F. '{print $2}')
9393

94-
if [ "${ts_minor_version}" -ge 22 ]; then
94+
if [ "${ts_minor_version}" -ge 25 ]; then
95+
TEST_VERSION=v12
96+
elif [ "${ts_minor_version}" -ge 22 ]; then
9597
TEST_VERSION=v11
9698
elif [ "${ts_minor_version}" -ge 20 ]; then
9799
TEST_VERSION=v10

sql/pre_install/tables.sql

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -320,15 +320,6 @@ CREATE TABLE _timescaledb_catalog.metadata (
320320

321321
SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.metadata', $$ WHERE key <> 'uuid' $$);
322322

323-
-- Log with events that will be sent out with the telemetry. The log
324-
-- will be flushed after it has been sent out. We do not save it to
325-
-- backups since it should not contain important data.
326-
CREATE TABLE _timescaledb_catalog.telemetry_event (
327-
created timestamptz NOT NULL DEFAULT current_timestamp,
328-
tag name NOT NULL,
329-
body jsonb NOT NULL
330-
);
331-
332323
CREATE TABLE _timescaledb_catalog.continuous_agg (
333324
mat_hypertable_id integer NOT NULL,
334325
raw_hypertable_id integer NOT NULL,
@@ -340,6 +331,7 @@ CREATE TABLE _timescaledb_catalog.continuous_agg (
340331
direct_view_schema name NOT NULL,
341332
direct_view_name name NOT NULL,
342333
materialized_only bool NOT NULL DEFAULT FALSE,
334+
schema_change_timestamp bigint,
343335
-- table constraints
344336
CONSTRAINT continuous_agg_pkey PRIMARY KEY (mat_hypertable_id),
345337
CONSTRAINT continuous_agg_partial_view_schema_partial_view_name_key UNIQUE (partial_view_schema, partial_view_name),

sql/updates/2.23.1--2.24.0.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
DROP FUNCTION IF EXISTS _timescaledb_functions.policy_job_stat_history_retention;
2+
DROP VIEW IF EXISTS timescaledb_information.hypertables;
23
DROP VIEW IF EXISTS timescaledb_information.chunks;
4+
DROP VIEW IF EXISTS timescaledb_information.chunk_columnstore_settings;
5+
DROP VIEW IF EXISTS timescaledb_information.chunk_compression_settings;
36

47
-- Add support for concurrent merge_chunks()
58
CREATE TABLE _timescaledb_catalog.chunk_rewrite (
@@ -27,3 +30,4 @@ BEGIN
2730
END IF;
2831
END
2932
$$;
33+

sql/updates/2.24.0--2.25.0.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
DROP VIEW IF EXISTS timescaledb_information.dimensions;
2+
DROP VIEW IF EXISTS timescaledb_information.hypertables;
3+
DROP VIEW IF EXISTS timescaledb_information.chunks;
4+
DROP VIEW IF EXISTS timescaledb_information.chunk_columnstore_settings;
5+
DROP VIEW IF EXISTS timescaledb_information.chunk_compression_settings;
6+
27
-- Block update if CAggs in old format are found
38
DO
49
$$
@@ -252,3 +257,4 @@ DROP FUNCTION timescaledb_experimental.time_bucket_ng(bucket_width INTERVAL, ts
252257
DROP FUNCTION timescaledb_experimental.time_bucket_ng(bucket_width INTERVAL, ts TIMESTAMPTZ);
253258

254259
DROP FUNCTION timescaledb_experimental.time_bucket_ng(bucket_width INTERVAL, ts TIMESTAMPTZ, origin TIMESTAMPTZ);
260+

sql/updates/2.25.2--2.26.0.sql

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,8 @@ ALTER TABLE _timescaledb_catalog.compression_chunk_size DROP CONSTRAINT compress
1414
ALTER TABLE _timescaledb_catalog.compression_chunk_size DROP CONSTRAINT compression_chunk_size_compressed_chunk_id_fkey;
1515

1616
--drop dependent views
17-
DROP VIEW IF EXISTS timescaledb_information.hypertables;
18-
DROP VIEW IF EXISTS timescaledb_information.chunks;
1917
DROP VIEW IF EXISTS _timescaledb_internal.hypertable_chunk_local_size;
2018
DROP VIEW IF EXISTS _timescaledb_internal.compressed_chunk_stats;
21-
DROP VIEW IF EXISTS timescaledb_information.chunk_columnstore_settings;
22-
DROP VIEW IF EXISTS timescaledb_information.chunk_compression_settings;
2319

2420
ALTER EXTENSION timescaledb DROP TABLE _timescaledb_catalog.chunk;
2521
ALTER EXTENSION timescaledb DROP SEQUENCE _timescaledb_catalog.chunk_id_seq;

sql/updates/latest-dev.sql

Lines changed: 97 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,6 @@ BEGIN
1111
END;
1212
$$;
1313

14-
-- Drop obsolete chunk_constraint rows for inherited CHECK constraints on
15-
-- OSM chunks; PG inheritance handles propagation now.
16-
DELETE FROM _timescaledb_catalog.chunk_constraint cc
17-
USING _timescaledb_catalog.chunk c
18-
WHERE cc.chunk_id = c.id
19-
AND c.osm_chunk
20-
AND cc.dimension_slice_id IS NULL
21-
AND cc.hypertable_constraint_name IS NOT NULL
22-
AND cc.constraint_name = cc.hypertable_constraint_name;
23-
2414
-- Rename legacy chunk-side constraints to the names the new code recomputes:
2515
-- FKs use the parent's name; unique/PK/exclusion/trigger use the deterministic
2616
-- "<chunk_id>_<parent>" form
@@ -52,14 +42,6 @@ BEGIN
5242
END
5343
$$;
5444

55-
-- Remove the chunk_constraint rows that mirrored non-dimensional constraints.
56-
-- FK chunk-side constraints are now located by name through the event-trigger
57-
-- hooks; unique/PK/exclusion/trigger constraints through the deterministic
58-
-- "<chunk_id>_<parent>" name pattern.
59-
DELETE FROM _timescaledb_catalog.chunk_constraint
60-
WHERE dimension_slice_id IS NULL
61-
AND hypertable_constraint_name IS NOT NULL;
62-
6345
ALTER TABLE _timescaledb_catalog.hypertable SET (user_catalog_table = true);
6446
ALTER TABLE _timescaledb_catalog.chunk SET (user_catalog_table = true);
6547

@@ -72,8 +54,6 @@ CREATE TABLE _timescaledb_internal.tmp_dimension_slice_seq_value AS
7254
ALTER TABLE _timescaledb_catalog.chunk_constraint
7355
DROP CONSTRAINT IF EXISTS chunk_constraint_dimension_slice_id_fkey;
7456

75-
DROP VIEW IF EXISTS timescaledb_information.chunks;
76-
7757
ALTER EXTENSION timescaledb DROP TABLE _timescaledb_catalog.dimension_slice;
7858
ALTER EXTENSION timescaledb DROP SEQUENCE _timescaledb_catalog.dimension_slice_id_seq;
7959

@@ -163,7 +143,6 @@ DROP FUNCTION _timescaledb_functions.chunk_constraint_add_table_constraint(
163143
_timescaledb_catalog.chunk_constraint);
164144
DROP FUNCTION IF EXISTS _timescaledb_internal.chunk_constraint_add_table_constraint(
165145
_timescaledb_catalog.chunk_constraint);
166-
DROP VIEW IF EXISTS timescaledb_information.chunks;
167146

168147
ALTER EXTENSION timescaledb DROP TABLE _timescaledb_catalog.chunk_constraint;
169148
ALTER EXTENSION timescaledb DROP SEQUENCE _timescaledb_catalog.chunk_constraint_name;
@@ -181,3 +160,100 @@ DROP FUNCTION IF EXISTS _timescaledb_functions.calculate_chunk_interval(integer,
181160
-- chunk_target_size is no longer used, so its check constraint is dropped.
182161
ALTER TABLE _timescaledb_catalog.hypertable
183162
DROP CONSTRAINT IF EXISTS hypertable_chunk_target_size_check;
163+
164+
-- Rebuild the catalog table `_timescaledb_catalog.continuous_agg` to add the
165+
-- `schema_change_timestamp` column.
166+
167+
-- Drop views and foreign keys that depend on the catalog table.
168+
DROP VIEW IF EXISTS timescaledb_experimental.policies;
169+
170+
ALTER TABLE _timescaledb_catalog.continuous_aggs_watermark
171+
DROP CONSTRAINT continuous_aggs_watermark_mat_hypertable_id_fkey;
172+
ALTER TABLE _timescaledb_catalog.continuous_aggs_materialization_invalidation_log
173+
DROP CONSTRAINT continuous_aggs_materialization_invalid_materialization_id_fkey;
174+
ALTER TABLE _timescaledb_catalog.continuous_aggs_materialization_ranges
175+
DROP CONSTRAINT continuous_aggs_materialization_ranges_materialization_id_fkey;
176+
ALTER TABLE _timescaledb_catalog.continuous_aggs_jobs_refresh_ranges
177+
DROP CONSTRAINT continuous_aggs_jobs_refresh_ranges_materialization_id_fkey;
178+
179+
ALTER EXTENSION timescaledb
180+
DROP TABLE _timescaledb_catalog.continuous_agg;
181+
182+
CREATE TABLE _timescaledb_catalog._tmp_continuous_agg AS
183+
SELECT
184+
mat_hypertable_id,
185+
raw_hypertable_id,
186+
parent_mat_hypertable_id,
187+
user_view_schema,
188+
user_view_name,
189+
partial_view_schema,
190+
partial_view_name,
191+
direct_view_schema,
192+
direct_view_name,
193+
materialized_only
194+
FROM
195+
_timescaledb_catalog.continuous_agg
196+
ORDER BY
197+
mat_hypertable_id;
198+
199+
DROP TABLE _timescaledb_catalog.continuous_agg;
200+
201+
CREATE TABLE _timescaledb_catalog.continuous_agg (
202+
mat_hypertable_id integer NOT NULL,
203+
raw_hypertable_id integer NOT NULL,
204+
parent_mat_hypertable_id integer,
205+
user_view_schema name NOT NULL,
206+
user_view_name name NOT NULL,
207+
partial_view_schema name NOT NULL,
208+
partial_view_name name NOT NULL,
209+
direct_view_schema name NOT NULL,
210+
direct_view_name name NOT NULL,
211+
materialized_only bool NOT NULL DEFAULT FALSE,
212+
schema_change_timestamp bigint,
213+
-- table constraints
214+
CONSTRAINT continuous_agg_pkey PRIMARY KEY (mat_hypertable_id),
215+
CONSTRAINT continuous_agg_partial_view_schema_partial_view_name_key UNIQUE (partial_view_schema, partial_view_name),
216+
CONSTRAINT continuous_agg_user_view_schema_user_view_name_key UNIQUE (user_view_schema, user_view_name),
217+
CONSTRAINT continuous_agg_mat_hypertable_id_fkey FOREIGN KEY (mat_hypertable_id) REFERENCES _timescaledb_catalog.hypertable (id) ON DELETE CASCADE,
218+
CONSTRAINT continuous_agg_raw_hypertable_id_fkey FOREIGN KEY (raw_hypertable_id) REFERENCES _timescaledb_catalog.hypertable (id) ON DELETE CASCADE,
219+
CONSTRAINT continuous_agg_parent_mat_hypertable_id_fkey FOREIGN KEY (parent_mat_hypertable_id)
220+
REFERENCES _timescaledb_catalog.continuous_agg (mat_hypertable_id) ON DELETE CASCADE
221+
);
222+
223+
INSERT INTO _timescaledb_catalog.continuous_agg
224+
(mat_hypertable_id, raw_hypertable_id, parent_mat_hypertable_id, user_view_schema,
225+
user_view_name, partial_view_schema, partial_view_name, direct_view_schema,
226+
direct_view_name, materialized_only)
227+
SELECT * FROM _timescaledb_catalog._tmp_continuous_agg;
228+
DROP TABLE _timescaledb_catalog._tmp_continuous_agg;
229+
230+
CREATE INDEX continuous_agg_raw_hypertable_id_idx ON _timescaledb_catalog.continuous_agg (raw_hypertable_id);
231+
232+
SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.continuous_agg', '');
233+
234+
GRANT SELECT ON TABLE _timescaledb_catalog.continuous_agg TO PUBLIC;
235+
236+
ALTER TABLE _timescaledb_catalog.continuous_aggs_watermark
237+
ADD CONSTRAINT continuous_aggs_watermark_mat_hypertable_id_fkey
238+
FOREIGN KEY (mat_hypertable_id)
239+
REFERENCES _timescaledb_catalog.continuous_agg (mat_hypertable_id) ON DELETE CASCADE;
240+
ALTER TABLE _timescaledb_catalog.continuous_aggs_materialization_invalidation_log
241+
ADD CONSTRAINT continuous_aggs_materialization_invalid_materialization_id_fkey
242+
FOREIGN KEY (materialization_id)
243+
REFERENCES _timescaledb_catalog.continuous_agg (mat_hypertable_id) ON DELETE CASCADE;
244+
ALTER TABLE _timescaledb_catalog.continuous_aggs_materialization_ranges
245+
ADD CONSTRAINT continuous_aggs_materialization_ranges_materialization_id_fkey
246+
FOREIGN KEY (materialization_id)
247+
REFERENCES _timescaledb_catalog.continuous_agg (mat_hypertable_id) ON DELETE CASCADE;
248+
ALTER TABLE _timescaledb_catalog.continuous_aggs_jobs_refresh_ranges
249+
ADD CONSTRAINT continuous_aggs_jobs_refresh_ranges_materialization_id_fkey
250+
FOREIGN KEY (materialization_id)
251+
REFERENCES _timescaledb_catalog.continuous_agg (mat_hypertable_id) ON DELETE CASCADE;
252+
253+
ANALYZE _timescaledb_catalog.continuous_agg;
254+
-- end rebuild _timescaledb_catalog.continuous_agg --
255+
256+
-- drop telemetry_event
257+
ALTER EXTENSION timescaledb DROP TABLE _timescaledb_catalog.telemetry_event;
258+
DROP TABLE _timescaledb_catalog.telemetry_event;
259+

0 commit comments

Comments
 (0)