Skip to content

Commit 35016f8

Browse files
committed
Normalize chunk names in updates/downgrade test
With the removal of compressed chunks as separate chunk entry all chunks will have different numbering between fresh install/upgrade. Prepare for this by ignoring chunk numbering in update test.
1 parent 2195c06 commit 35016f8

7 files changed

Lines changed: 65 additions & 43 deletions

test/sql/updates/post.catalog.sql

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
-- Please see the included NOTICE for copyright information and
33
-- LICENSE-APACHE for a copy of the license.
44

5+
-- Chunk relation names are not deterministic between a fresh install and a post-upgrade catalog.
6+
CREATE OR REPLACE FUNCTION pg_temp.normalize_chunk(t text) RETURNS text
7+
LANGUAGE sql IMMUTABLE AS $$
8+
SELECT regexp_replace(
9+
regexp_replace(t,
10+
'compress_hyper_[0-9]+_[0-9]+_chunk|_hyper_[0-9]+_[0-9]+_chunk_compressed',
11+
'compressed_chunk', 'g'),
12+
'(_hyper_[0-9]+)_[0-9]+_chunk', '\1_X_chunk', 'g')
13+
$$;
14+
515
SELECT NOT (extversion >= '2.19.0' AND extversion <= '2.20.3') AS has_fixed_compression_algorithms
616
FROM pg_extension
717
WHERE extname = 'timescaledb' \gset
@@ -161,10 +171,10 @@ ORDER BY conrelid::regclass::text, contype, conname, confrelid::regclass::text;
161171

162172
-- child tables
163173
SELECT parent.relname AS table_name,
164-
i.inhrelid::regclass AS child_table
174+
pg_temp.normalize_chunk(i.inhrelid::regclass::text) AS child_table
165175
FROM pg_catalog.pg_inherits i
166176
JOIN pg_catalog.pg_class parent ON parent.oid = i.inhparent AND parent.relnamespace = 'public'::regnamespace
167-
ORDER BY parent.relname, i.inhrelid::regclass::text;
177+
ORDER BY parent.relname, pg_temp.normalize_chunk(i.inhrelid::regclass::text);
168178

169179
-- Keep the output backward compatible
170180
\if :PG_UPGRADE_TEST
@@ -199,24 +209,25 @@ ORDER BY parent.relname, i.inhrelid::regclass::text;
199209
-- The list of tables configured to be dumped.
200210
SELECT unnest(extconfig)::regclass::text, unnest(extcondition) FROM pg_extension WHERE extname = 'timescaledb' ORDER BY 1;
201211

202-
-- Show chunks that include owner in the output
203-
SELECT c.id, c.hypertable_id, c.schema_name, c.table_name, cl.relowner::regrole
212+
-- Show chunks that include owner in the output. The chunk id is not
213+
-- deterministic post-upgrade, so drop it and normalize the chunk relation name.
214+
SELECT c.hypertable_id, c.schema_name, pg_temp.normalize_chunk(c.table_name) AS table_name, cl.relowner::regrole
204215
FROM _timescaledb_catalog.chunk c
205216
INNER JOIN pg_class cl ON (cl.oid=format('%I.%I', schema_name, table_name)::regclass)
206-
ORDER BY c.id, c.hypertable_id;
217+
ORDER BY c.hypertable_id, pg_temp.normalize_chunk(c.table_name);
207218

208-
-- Per-chunk dimensional ranges. Slice ids are assigned by SERIAL and differ
209-
-- between a fresh install and a post-upgrade catalog, so dump path-stable
210-
-- columns only.
219+
-- Per-chunk dimensional ranges. Slice ids are assigned by SERIAL and chunk ids
220+
-- are renumbered, so both differ between a fresh install and a post-upgrade
221+
-- catalog. Dump and order by the dimensional range only.
211222
\if :has_chunk_owned_slices
212-
SELECT ds.chunk_id, ds.dimension_id, ds.range_start, ds.range_end
223+
SELECT ds.dimension_id, ds.range_start, ds.range_end
213224
FROM _timescaledb_catalog.dimension_slice ds
214-
ORDER BY ds.chunk_id, ds.dimension_id;
225+
ORDER BY ds.dimension_id, ds.range_start, ds.range_end;
215226
\else
216-
SELECT cc.chunk_id, ds.dimension_id, ds.range_start, ds.range_end
227+
SELECT ds.dimension_id, ds.range_start, ds.range_end
217228
FROM _timescaledb_catalog.chunk_constraint cc
218229
JOIN _timescaledb_catalog.dimension_slice ds ON ds.id = cc.dimension_slice_id
219-
ORDER BY cc.chunk_id, ds.dimension_id;
230+
ORDER BY ds.dimension_id, ds.range_start, ds.range_end;
220231
\endif
221232

222233
-- Show attributes of all regclass objects belonging to our extension
@@ -240,7 +251,7 @@ ORDER BY attrelid::regclass::text COLLATE "C", a.attnum;
240251
-- form (2.28.0) compare equal. The dimensional CHECKs are named
241252
-- "constraint_<slice_id>" and slice ids are not deterministic between a
242253
-- fresh install and a post-upgrade catalog, so collapse the suffix too.
243-
SELECT conrelid::regclass::text,
254+
SELECT pg_temp.normalize_chunk(conrelid::regclass::text) AS conrelid,
244255
regexp_replace(
245256
regexp_replace(conname, '^([0-9]+_){1,2}', ''),
246257
'^constraint_[0-9]+$', 'constraint_dim') AS conname,
@@ -256,4 +267,8 @@ ORDER BY 1, 2, 3;
256267
-- orderby sparse index type changed across releases and existing chunks are
257268
-- not rewritten on upgrade), so it differs between a fresh install and a
258269
-- post-upgrade catalog. Skip it and compare the remaining columns.
259-
SELECT relid, compress_relid, segmentby, orderby, orderby_desc, orderby_nullsfirst FROM _timescaledb_catalog.compression_settings ORDER BY relid::regclass::text;
270+
SELECT pg_temp.normalize_chunk(relid::regclass::text) AS relid,
271+
pg_temp.normalize_chunk(compress_relid::regclass::text) AS compress_relid,
272+
segmentby, orderby, orderby_desc, orderby_nullsfirst
273+
FROM _timescaledb_catalog.compression_settings
274+
ORDER BY pg_temp.normalize_chunk(relid::regclass::text), segmentby, orderby;

test/sql/updates/post.chunk_skipping.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
-- exclude the rows with chunk_id = 0 because we cannot keep those on
77
-- downgrade due to FK constraint. Showing them would mean a diff in
88
-- the output. We can still test that 0 chunk_ids are converted to
9-
-- NULL values during upgrades, however.
10-
SELECT * FROM _timescaledb_catalog.chunk_column_stats
9+
-- NULL values during upgrades, however. The chunk id itself is renumbered
10+
-- across the upgrade, so report only whether it is set instead of its value.
11+
SELECT id, hypertable_id, (chunk_id IS NOT NULL) AS chunk_id_set, column_name, range_start, range_end, valid
12+
FROM _timescaledb_catalog.chunk_column_stats
1113
WHERE chunk_id IS NULL OR chunk_id > 0 ORDER BY id;

test/sql/updates/post.compression.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ SELECT hypertable_name,
4343
(SELECT relacl FROM pg_class WHERE oid = hypertable_name::regclass) AS hypertable_acl,
4444
compressed_hypertable_name,
4545
(SELECT relacl FROM pg_class WHERE oid = compressed_hypertable_name::regclass) AS compressed_hypertable_acl,
46-
compressed_chunk_name,
46+
-- the compressed relation keeps its pre-upgrade name across a downgrade,
47+
-- so normalize it; the acl is still looked up by the real name
48+
pg_temp.normalize_chunk(compressed_chunk_name) AS compressed_chunk_name,
4749
(SELECT relacl FROM pg_class WHERE oid = compressed_chunk_name::regclass) AS compressed_chunk_acl
4850
FROM table_summary
49-
ORDER BY hypertable_name, compressed_hypertable_name, compressed_chunk_name;
51+
ORDER BY hypertable_name, compressed_hypertable_name, pg_temp.normalize_chunk(compressed_chunk_name);
5052
\x off
5153

test/sql/updates/post.continuous_aggs.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ ON (cl.oid IN (format('%I.%I', h.schema_name, h.table_name)::regclass,
5151
format('%I.%I', partial_view_schema, partial_view_name)::regclass))
5252
ORDER BY reloid, relacl;
5353

54-
-- Output ACLs for chunks on materialized hypertables
54+
-- Output ACLs for chunks on materialized hypertables. Chunk relation names are
55+
-- renumbered across the upgrade, so normalize them.
5556
SELECT inhparent::regclass::text AS parent,
56-
cl.oid::regclass::text AS chunk,
57+
pg_temp.normalize_chunk(cl.oid::regclass::text) AS chunk,
5758
unnest(relacl)::text AS acl
5859
FROM _timescaledb_catalog.continuous_agg ca
5960
JOIN _timescaledb_catalog.hypertable h

test/sql/updates/post.integrity_test.sql

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,17 @@
55
-- We do not dump the size of the tables here since that might differ
66
-- between an updated node and a restored node. For examples, stats
77
-- tables can have different sizes, and this is not relevant for an
8-
-- update test.
9-
\dt _timescaledb_internal.*
8+
-- update test. This mirrors \dt _timescaledb_internal.* but normalizes the
9+
-- chunk relation names, which are renumbered and renamed across the upgrade.
10+
SELECT n.nspname AS "Schema",
11+
pg_temp.normalize_chunk(c.relname) AS "Name",
12+
'table' AS "Type",
13+
pg_catalog.pg_get_userbyid(c.relowner) AS "Owner"
14+
FROM pg_catalog.pg_class c
15+
JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
16+
WHERE n.nspname = '_timescaledb_internal'
17+
AND c.relkind = 'r'
18+
ORDER BY 1, 2, 4;
1019

1120
CREATE OR REPLACE FUNCTION timescaledb_integrity_test()
1221
RETURNS VOID LANGUAGE PLPGSQL STABLE AS

test/sql/updates/post.sequences.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
-- burned ids for slices of chunks dropped before the upgrade. Those dropped
1010
-- slices leave no trace to reconstruct, so the next id legitimately differs
1111
-- from a clean install even though the slice rows match.
12+
-- chunk_id_seq is excluded too: a fresh install no longer burns chunk ids for
13+
-- compressed relations, so the next id is lower than in a pre-upgrade catalog.
1214
SELECT seqrelid::regclass,
1315
CASE WHEN seqrelid::regclass::text IN ('_timescaledb_catalog.chunk_constraint_name',
14-
'_timescaledb_catalog.dimension_slice_id_seq')
16+
'_timescaledb_catalog.dimension_slice_id_seq',
17+
'_timescaledb_catalog.chunk_id_seq')
1518
THEN NULL ELSE nextval(seqrelid) END AS nextval,
1619
seqstart,
1720
seqincrement,

test/sql/updates/post.sparse_index.sql

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,25 @@
22
-- Please see the included NOTICE for copyright information and
33
-- LICENSE-APACHE for a copy of the license.
44

5-
-- Show chunk column stats after updating the extension. We need to
6-
-- exclude the rows with chunk_id = 0 because we cannot keep those on
7-
-- downgrade due to FK constraint. Showing them would mean a diff in
8-
-- the output. We can still test that 0 chunk_ids are converted to
9-
-- NULL values during upgrades, however.
10-
11-
SELECT
12-
cs.compress_relid::text AS chunk
13-
FROM _timescaledb_catalog.chunk ch
14-
JOIN _timescaledb_catalog.compression_settings cs
15-
ON cs.relid = format('%I.%I', ch.schema_name, ch.table_name)::regclass
16-
WHERE ch.hypertable_id = (
17-
SELECT id
18-
FROM _timescaledb_catalog.hypertable
19-
WHERE table_name = 'bloom'
20-
)
21-
LIMIT 1
22-
\gset
23-
245
-- This test checks that the bloom sparse indexes survive the upgrade, so only
256
-- look at the bloom columns of the compressed chunk. Dumping the whole chunk
267
-- would also pull in the orderby sparse metadata, whose layout depends on the
278
-- version that compressed the chunk (minmax vs firstlast) and is not rewritten
289
-- on upgrade, which would cause a spurious diff unrelated to bloom indexes.
10+
-- look at the bloom columns of one compressed chunk of the bloom hypertable.
2911
\a
3012
SELECT a.attname, format_type(a.atttypid, a.atttypmod) AS type
3113
FROM pg_attribute a
3214
JOIN pg_type t ON t.oid = a.atttypid
33-
WHERE a.attrelid = :'chunk'::regclass
15+
WHERE a.attrelid = (
16+
SELECT cs.compress_relid
17+
FROM _timescaledb_catalog.chunk ch
18+
JOIN _timescaledb_catalog.compression_settings cs
19+
ON cs.relid = format('%I.%I', ch.schema_name, ch.table_name)::regclass
20+
WHERE ch.hypertable_id = (SELECT id FROM _timescaledb_catalog.hypertable WHERE table_name = 'bloom')
21+
ORDER BY ch.id
22+
LIMIT 1
23+
)
3424
AND a.attnum > 0
3525
AND NOT a.attisdropped
3626
AND t.typname = 'bloom1'

0 commit comments

Comments
 (0)