Skip to content

Commit a1d7218

Browse files
committed
Separate chunk skipping update test
1 parent e9882c0 commit a1d7218

13 files changed

+98
-36
lines changed

scripts/test_update_from_version.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ FROM_VERSION=${FROM_VERSION:-$(grep '^previous_version ' version.config | awk '{
1212
TO_VERSION=${TO_VERSION:-$(grep '^version ' version.config | awk '{ print $3 }')}
1313

1414
TEST_REPAIR=${TEST_REPAIR:-false}
15-
TEST_VERSION=${TEST_VERSION:-v8}
15+
TEST_VERSION=${TEST_VERSION:-v9}
1616

1717
OUTPUT_DIR=${OUTPUT_DIR:-update_test/${FROM_VERSION}_to_${TO_VERSION}}
1818
PGDATA="${OUTPUT_DIR}/data"
@@ -135,5 +135,3 @@ if [ -f "${OUTPUT_DIR}/baseline_vs_updated.diff" ] || [ -f "${OUTPUT_DIR}/baseli
135135
echo "Update test for ${FROM_VERSION} -> ${TO_VERSION} failed"
136136
exit 1
137137
fi
138-
139-

scripts/test_updates.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,19 @@ if [ -n "${VERSIONS}" ]; then
8787
for version in ${VERSIONS}; do
8888
ts_minor_version=$(echo "${version}" | awk -F. '{print $2}')
8989

90-
TEST_VERSION=v8
91-
9290
if [ "${ts_minor_version}" -ge 10 ]; then
9391
TEST_REPAIR=true
9492
else
9593
TEST_REPAIR=false
9694
fi
9795

96+
97+
if [ "${ts_minor_version}" -ge 16 ]; then
98+
TEST_VERSION=v9
99+
else
100+
TEST_VERSION=v8
101+
fi
102+
98103
export TEST_VERSION TEST_REPAIR
99104

100105
FROM_VERSION=${version} "${SCRIPT_DIR}/test_update_from_version.sh"
@@ -115,4 +120,3 @@ else
115120
fi
116121

117122
exit $FAIL_COUNT
118-
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- This file and its contents are licensed under the Apache License 2.0.
2+
-- Please see the included NOTICE for copyright information and
3+
-- LICENSE-APACHE for a copy of the license.
4+
5+
DROP TABLE skip;

test/sql/updates/cleanup.v7.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@
88
\ir cleanup.continuous_aggs.v2.sql
99
\ir cleanup.compression.sql
1010
\ir cleanup.policies.sql
11-

test/sql/updates/cleanup.v8.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- This file and its contents are licensed under the Apache License 2.0.
2+
-- Please see the included NOTICE for copyright information and
3+
-- LICENSE-APACHE for a copy of the license.
4+
5+
\ir cleanup.v7.sql
6+

test/sql/updates/cleanup.v9.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- This file and its contents are licensed under the Apache License 2.0.
2+
-- Please see the included NOTICE for copyright information and
3+
-- LICENSE-APACHE for a copy of the license.
4+
5+
\ir cleanup.v8.sql
6+
\ir cleanup.chunk_skipping.sql
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- This file and its contents are licensed under the Apache License 2.0.
2+
-- Please see the included NOTICE for copyright information and
3+
-- LICENSE-APACHE for a copy of the license.
4+
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+
SELECT * FROM _timescaledb_catalog.chunk_column_stats
11+
WHERE chunk_id IS NULL OR chunk_id > 0 ORDER BY id;

test/sql/updates/post.compression.sql

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ SELECT * FROM compress ORDER BY time DESC, small_cardinality, large_cardinality,
2525
\x on
2626
WITH hypertables AS (
2727
SELECT ht.id hypertable_id,
28-
ht.schema_name,
29-
ht.table_name,
30-
ht.compressed_hypertable_id
28+
ht.schema_name,
29+
ht.table_name,
30+
ht.compressed_hypertable_id
3131
FROM pg_class cl JOIN pg_namespace ns ON ns.oid = relnamespace
32-
JOIN _timescaledb_catalog.hypertable ht ON relname = ht.table_name AND nspname = ht.schema_name
32+
JOIN _timescaledb_catalog.hypertable ht ON relname = ht.table_name AND nspname = ht.schema_name
3333
),
3434
table_summary AS (
35-
SELECT format('%I.%I', ht1.schema_name, ht1.table_name) AS hypertable_name,
36-
format('%I.%I', ht2.schema_name, ht2.table_name) AS compressed_hypertable_name,
37-
format('%I.%I', ch2.schema_name, ch2.table_name) AS compressed_chunk_name
38-
FROM hypertables ht1
39-
JOIN hypertables ht2 ON ht1.compressed_hypertable_id = ht2.hypertable_id
35+
SELECT format('%I.%I', ht1.schema_name, ht1.table_name) AS hypertable_name,
36+
format('%I.%I', ht2.schema_name, ht2.table_name) AS compressed_hypertable_name,
37+
format('%I.%I', ch2.schema_name, ch2.table_name) AS compressed_chunk_name
38+
FROM hypertables ht1
39+
JOIN hypertables ht2 ON ht1.compressed_hypertable_id = ht2.hypertable_id
4040
JOIN _timescaledb_catalog.chunk ch2 ON ch2.hypertable_id = ht2.hypertable_id
4141
)
4242
SELECT hypertable_name,
@@ -49,10 +49,3 @@ SELECT hypertable_name,
4949
ORDER BY hypertable_name, compressed_hypertable_name, compressed_chunk_name;
5050
\x off
5151

52-
-- Show chunk column stats after updating the extension. We need to
53-
-- exclude the rows with chunk_id = 0 because we cannot keep those on
54-
-- downgrade due to FK constraint. Showing them would mean a diff in
55-
-- the output. We can still test that 0 chunk_ids are converted to
56-
-- NULL values during upgrades, however.
57-
SELECT * FROM _timescaledb_catalog.chunk_column_stats
58-
WHERE chunk_id IS NULL OR chunk_id > 0 ORDER BY id;

test/sql/updates/post.v9.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- This file and its contents are licensed under the Apache License 2.0.
2+
-- Please see the included NOTICE for copyright information and
3+
-- LICENSE-APACHE for a copy of the license.
4+
5+
\ir post.v8.sql
6+
\ir post.chunk_skipping.sql

test/sql/updates/pre.cleanup.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ DROP TABLE IF EXISTS repair_test_extra;
3030
DROP TABLE IF EXISTS repair_test_timestamp;
3131
DROP TABLE IF EXISTS repair_test_date;
3232
DROP TABLE IF EXISTS compress;
33+
DROP TABLE IF EXISTS skip;
3334
DROP TABLE IF EXISTS devices;
3435
DROP TABLE IF EXISTS disthyper;
3536
DROP TABLE IF EXISTS policy_test_timestamptz;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
-- This file and its contents are licensed under the Apache License 2.0.
2+
-- Please see the included NOTICE for copyright information and
3+
-- LICENSE-APACHE for a copy of the license.
4+
5+
6+
CREATE TABLE skip (
7+
time TIMESTAMPTZ NOT NULL,
8+
updated_at TIMESTAMPTZ NOT NULL,
9+
location INT,
10+
temp FLOAT
11+
);
12+
13+
SELECT setseed(0.1);
14+
SELECT table_name FROM create_hypertable( 'skip', 'time');
15+
16+
INSERT INTO skip
17+
SELECT g, g+interval '1 hour', ceil(random()*20), random()*30
18+
FROM generate_series('2018-12-01 00:00'::timestamp, '2018-12-31 00:00'::timestamp, '1 day') g;
19+
20+
ALTER TABLE skip SET (timescaledb.compress, timescaledb.compress_segmentby='location');
21+
SELECT count(compress_chunk(ch, true)) FROM show_chunks('skip') ch;
22+
23+
DO $$
24+
DECLARE
25+
version text[] := (SELECT regexp_split_to_array(extversion,'(\.|-)') FROM pg_extension WHERE extname = 'timescaledb');
26+
BEGIN
27+
28+
-- Enable chunk skipping. Doing this after compression to have a
29+
-- "special" chunk_id entry of 0. We check that this is changed to
30+
-- NULL during upgrade.
31+
IF version[1]::int >= 2 AND version[2]::int >= 17 AND (version[2]::int > 17 OR version[3]::int > 0) THEN
32+
SET timescaledb.enable_chunk_skipping = true;
33+
END IF;
34+
END
35+
$$;
36+
37+
SELECT enable_chunk_skipping('skip', 'updated_at');

test/sql/updates/setup.compression.sql

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,33 +29,23 @@ INSERT INTO compress
2929
SELECT g, 'POR', g::text, 'lint', 94.0, 45, (3,4)::custom_type_for_compression, true
3030
FROM generate_series('2018-11-01 00:00'::timestamp, '2018-12-15 00:00'::timestamp, '1 day') g;
3131

32-
SELECT regexp_split_to_array(extversion,'(\.|-)') FROM pg_extension WHERE extname = 'timescaledb';
33-
3432
DO $$
3533
DECLARE
36-
version text[] := (SELECT regexp_split_to_array(extversion,'(\.|-)') FROM pg_extension WHERE extname = 'timescaledb');
34+
ts_minor int := (SELECT (string_to_array(extversion,'.'))[2]::int FROM pg_extension WHERE extname = 'timescaledb');
3735
BEGIN
3836

3937
-- support for dropping columns on compressed hypertables was added in 2.10.0
4038
-- so we drop before compressing if the version is before 2.10.0
41-
IF version[1]::int = 2 AND version[2]::int < 10 THEN
39+
IF ts_minor < 10 THEN
4240
ALTER TABLE compress DROP COLUMN dropped;
4341
END IF;
4442

4543
ALTER TABLE compress SET (timescaledb.compress, timescaledb.compress_segmentby='small_cardinality');
4644
PERFORM count(compress_chunk(ch, true)) FROM show_chunks('compress') ch;
4745

48-
IF version[1]::int >= 2 AND version[2]::int >= 10 THEN
46+
IF ts_minor >= 10 THEN
4947
ALTER TABLE compress DROP COLUMN dropped;
5048
END IF;
51-
52-
-- Enable chunk skipping. Doing this after compression to have a
53-
-- "special" chunk_id entry of 0. We check that this is changed to
54-
-- NULL during upgrade.
55-
IF version[1]::int >= 2 AND version[2]::int >= 17 AND (version[2]::int > 17 OR version[3]::int > 0) THEN
56-
SET timescaledb.enable_chunk_skipping = true;
57-
END IF;
58-
PERFORM enable_chunk_skipping('compress', 'some_int');
5949
END
6050
$$;
6151

test/sql/updates/setup.v9.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- This file and its contents are licensed under the Apache License 2.0.
2+
-- Please see the included NOTICE for copyright information and
3+
-- LICENSE-APACHE for a copy of the license.
4+
5+
\ir setup.v8.sql
6+
\ir setup.chunk_skipping.sql

0 commit comments

Comments
 (0)