Skip to content

Commit 5c1803e

Browse files
committed
Refactor more tests to use compression_settings for compressed relation lookup
1 parent 31f7b58 commit 5c1803e

31 files changed

Lines changed: 724 additions & 531 deletions

tsl/test/expected/cagg_add_column.out

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -392,16 +392,19 @@ WHERE c.hypertable_id = :mat_ht_id
392392
-----------------------------
393393
3
394394

395-
-- every compressed chunk has min_temp
396-
SELECT count(*) AS compressed_chunks_with_min_temp
397-
FROM information_schema.columns ic, _timescaledb_catalog.chunk c
398-
WHERE c.hypertable_id = :compressed_ht_id
399-
AND ic.table_schema = c.schema_name
400-
AND ic.table_name = c.table_name
395+
-- every mat HT chunk has min_temp
396+
SELECT count(*) AS compressed_relations_with_min_temp
397+
FROM information_schema.columns ic,
398+
_timescaledb_catalog.chunk c,_timescaledb_catalog.compression_settings cs, pg_class
399+
WHERE c.hypertable_id = :mat_ht_id
400+
AND cs.relid = format('%I.%I', c.schema_name, c.table_name)::regclass
401+
AND pg_class.oid = cs.compress_relid
402+
AND ic.table_schema = pg_class.relnamespace::regnamespace::text
403+
AND ic.table_name = pg_class.relname
401404
AND ic.column_name = 'min_temp';
402-
compressed_chunks_with_min_temp
403-
---------------------------------
404-
3
405+
compressed_relations_with_min_temp
406+
------------------------------------
407+
3
405408

406409
-- before any further refresh, every row's min_temp is NULL
407410
SELECT count(*) AS rows_with_non_null_min_temp FROM cagg_compressed WHERE min_temp IS NOT NULL;

tsl/test/expected/compress_bgw_reorder_drop_chunks.out

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ WHERE hypertable.table_name like 'test_retention_table';
101101

102102
SELECT count(*) as count_chunks_compressed
103103
FROM _timescaledb_catalog.chunk chunk
104-
INNER JOIN _timescaledb_catalog.hypertable comp_hyper ON (chunk.hypertable_id = comp_hyper.id)
105-
INNER JOIN _timescaledb_catalog.hypertable uncomp_hyper ON (comp_hyper.id = uncomp_hyper.compressed_hypertable_id)
106-
WHERE uncomp_hyper.table_name like 'test_retention_table';
104+
INNER JOIN _timescaledb_catalog.hypertable hypertable ON (chunk.hypertable_id = hypertable.id)
105+
INNER JOIN _timescaledb_catalog.compression_settings cs ON cs.relid = to_regclass(format('%I.%I', chunk.schema_name, chunk.table_name)) AND cs.compress_relid IS NOT NULL
106+
WHERE hypertable.table_name like 'test_retention_table';
107107
count_chunks_compressed
108108
-------------------------
109109
5
@@ -140,9 +140,9 @@ WHERE hypertable.table_name like 'test_retention_table';
140140

141141
SELECT count(*) as count_chunks_compressed
142142
FROM _timescaledb_catalog.chunk chunk
143-
INNER JOIN _timescaledb_catalog.hypertable comp_hyper ON (chunk.hypertable_id = comp_hyper.id)
144-
INNER JOIN _timescaledb_catalog.hypertable uncomp_hyper ON (comp_hyper.id = uncomp_hyper.compressed_hypertable_id)
145-
WHERE uncomp_hyper.table_name like 'test_retention_table';
143+
INNER JOIN _timescaledb_catalog.hypertable hypertable ON (chunk.hypertable_id = hypertable.id)
144+
INNER JOIN _timescaledb_catalog.compression_settings cs ON cs.relid = to_regclass(format('%I.%I', chunk.schema_name, chunk.table_name)) AND cs.compress_relid IS NOT NULL
145+
WHERE hypertable.table_name like 'test_retention_table';
146146
count_chunks_compressed
147147
-------------------------
148148
3
@@ -187,9 +187,9 @@ WHERE hypertable.table_name like 'test_reorder_chunks_table';
187187
-- and 2 compressed ones:
188188
SELECT count(*) as count_chunks_compressed
189189
FROM _timescaledb_catalog.chunk chunk
190-
INNER JOIN _timescaledb_catalog.hypertable comp_hyper ON (chunk.hypertable_id = comp_hyper.id)
191-
INNER JOIN _timescaledb_catalog.hypertable uncomp_hyper ON (comp_hyper.id = uncomp_hyper.compressed_hypertable_id)
192-
WHERE uncomp_hyper.table_name like 'test_reorder_chunks_table';
190+
INNER JOIN _timescaledb_catalog.hypertable hypertable ON (chunk.hypertable_id = hypertable.id)
191+
INNER JOIN _timescaledb_catalog.compression_settings cs ON cs.relid = to_regclass(format('%I.%I', chunk.schema_name, chunk.table_name)) AND cs.compress_relid IS NOT NULL
192+
WHERE hypertable.table_name like 'test_reorder_chunks_table';
193193
count_chunks_compressed
194194
-------------------------
195195
2

tsl/test/expected/compress_compbloom_basics.out

Lines changed: 330 additions & 177 deletions
Large diffs are not rendered by default.

tsl/test/expected/compress_compbloom_config.out

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
-- Config tests
66
-------------------------------------------------------------------
77
CREATE VIEW settings AS SELECT * FROM _timescaledb_catalog.compression_settings ORDER BY upper(relid::text) COLLATE "C";
8-
CREATE VIEW compressedcols AS select relname,attname,c.oid as reloid,attnum from pg_attribute a, pg_class c where c.oid=a.attrelid and relname like '%compress_hyper_%chunk' order by c.oid asc, a.attnum asc;
8+
CREATE VIEW compressedcols AS select h.table_name as relname, a.attname, cs.compress_relid as reloid, a.attnum from _timescaledb_catalog.compression_settings cs join _timescaledb_catalog.chunk ch on cs.relid = format('%I.%I', ch.schema_name, ch.table_name)::regclass join _timescaledb_catalog.hypertable h on ch.hypertable_id = h.id join pg_attribute a on a.attrelid = cs.compress_relid order by cs.compress_relid asc, a.attnum asc;
99
CREATE TABLE t(a int, b int, c int, d int, e int, f int, g int, h int, i int);
1010
SELECT create_hypertable('t', 'a');
1111
create_hypertable
@@ -74,29 +74,29 @@ select relid,compress_relid,segmentby,orderby,orderby_desc,orderby_nullsfirst,in
7474

7575
-- Check the auto generated compressed columns
7676
select relname,attname from compressedcols order by 1,2;
77-
relname | attname
78-
--------------------------+-------------------------------
79-
compress_hyper_4_2_chunk | _ts_meta_count
80-
compress_hyper_4_2_chunk | _ts_meta_max_1
81-
compress_hyper_4_2_chunk | _ts_meta_max_2
82-
compress_hyper_4_2_chunk | _ts_meta_min_1
83-
compress_hyper_4_2_chunk | _ts_meta_min_2
84-
compress_hyper_4_2_chunk | regress-test-bloom_c
85-
compress_hyper_4_2_chunk | regress-test-bloom_ed4b_a_b_c
86-
compress_hyper_4_2_chunk | _ts_meta_v2_first_a
87-
compress_hyper_4_2_chunk | _ts_meta_v2_first_b
88-
compress_hyper_4_2_chunk | _ts_meta_v2_last_a
89-
compress_hyper_4_2_chunk | _ts_meta_v2_last_b
90-
compress_hyper_4_2_chunk | a
91-
compress_hyper_4_2_chunk | b
92-
compress_hyper_4_2_chunk | c
93-
compress_hyper_4_2_chunk | cmax
94-
compress_hyper_4_2_chunk | cmin
95-
compress_hyper_4_2_chunk | ctid
96-
compress_hyper_4_2_chunk | d
97-
compress_hyper_4_2_chunk | tableoid
98-
compress_hyper_4_2_chunk | xmax
99-
compress_hyper_4_2_chunk | xmin
77+
relname | attname
78+
---------+-------------------------------
79+
u | _ts_meta_count
80+
u | _ts_meta_max_1
81+
u | _ts_meta_max_2
82+
u | _ts_meta_min_1
83+
u | _ts_meta_min_2
84+
u | regress-test-bloom_c
85+
u | regress-test-bloom_ed4b_a_b_c
86+
u | _ts_meta_v2_first_a
87+
u | _ts_meta_v2_first_b
88+
u | _ts_meta_v2_last_a
89+
u | _ts_meta_v2_last_b
90+
u | a
91+
u | b
92+
u | c
93+
u | cmax
94+
u | cmin
95+
u | ctid
96+
u | d
97+
u | tableoid
98+
u | xmax
99+
u | xmin
100100

101101
ALTER TABLE u SET (timescaledb.compress_index = 'bloom("a","b","c")');
102102
NOTICE: updated compression settings will only apply to future compressions
@@ -145,36 +145,36 @@ select relid,compress_relid,segmentby,orderby,orderby_desc,orderby_nullsfirst,in
145145
_timescaledb_internal._hyper_5_3_chunk | _timescaledb_internal.compress_hyper_6_4_chunk | | {b_01234567890123456789,a_01234567890123456789} | {f,t} | {f,t} | [{"type": "bloom", "column": ["a_01234567890123456789", "b_01234567890123456789", "c_01234567890123456789", "d_01234567890123456789", "e_01234567890123456789"], "source": "default"}, {"type": "bloom", "column": "c_01234567890123456789", "source": "default"}, {"type": "bloom", "column": "d_01234567890123456789", "source": "default"}, {"type": "bloom", "column": "e_01234567890123456789", "source": "default"}, {"type": "minmax", "column": "b_01234567890123456789", "source": "orderby"}, {"type": "firstlast", "column": "b_01234567890123456789", "source": "orderby"}, {"type": "minmax", "column": "a_01234567890123456789", "source": "orderby"}, {"type": "firstlast", "column": "a_01234567890123456789", "source": "orderby"}]
146146

147147
select relname,attname from compressedcols order by 1,2;
148-
relname | attname
149-
--------------------------+-----------------------------------------------------------------
150-
compress_hyper_6_4_chunk | _ts_meta_count
151-
compress_hyper_6_4_chunk | _ts_meta_max_1
152-
compress_hyper_6_4_chunk | _ts_meta_max_2
153-
compress_hyper_6_4_chunk | _ts_meta_min_1
154-
compress_hyper_6_4_chunk | _ts_meta_min_2
155-
compress_hyper_6_4_chunk | regress-test-bloom_76d9_a_01234567890123456789_b_01234567890123
156-
compress_hyper_6_4_chunk | regress-test-bloom_c_01234567890123456789
157-
compress_hyper_6_4_chunk | regress-test-bloom_d_01234567890123456789
158-
compress_hyper_6_4_chunk | regress-test-bloom_e_01234567890123456789
159-
compress_hyper_6_4_chunk | _ts_meta_v2_first_a_01234567890123456789
160-
compress_hyper_6_4_chunk | _ts_meta_v2_first_b_01234567890123456789
161-
compress_hyper_6_4_chunk | _ts_meta_v2_last_a_01234567890123456789
162-
compress_hyper_6_4_chunk | _ts_meta_v2_last_b_01234567890123456789
163-
compress_hyper_6_4_chunk | a_01234567890123456789
164-
compress_hyper_6_4_chunk | b_01234567890123456789
165-
compress_hyper_6_4_chunk | c_01234567890123456789
166-
compress_hyper_6_4_chunk | cmax
167-
compress_hyper_6_4_chunk | cmin
168-
compress_hyper_6_4_chunk | ctid
169-
compress_hyper_6_4_chunk | d_01234567890123456789
170-
compress_hyper_6_4_chunk | e_01234567890123456789
171-
compress_hyper_6_4_chunk | f_01234567890123456789
172-
compress_hyper_6_4_chunk | g_01234567890123456789
173-
compress_hyper_6_4_chunk | h_01234567890123456789
174-
compress_hyper_6_4_chunk | i_01234567890123456789
175-
compress_hyper_6_4_chunk | tableoid
176-
compress_hyper_6_4_chunk | xmax
177-
compress_hyper_6_4_chunk | xmin
148+
relname | attname
149+
---------+-----------------------------------------------------------------
150+
v | _ts_meta_count
151+
v | _ts_meta_max_1
152+
v | _ts_meta_max_2
153+
v | _ts_meta_min_1
154+
v | _ts_meta_min_2
155+
v | regress-test-bloom_76d9_a_01234567890123456789_b_01234567890123
156+
v | regress-test-bloom_c_01234567890123456789
157+
v | regress-test-bloom_d_01234567890123456789
158+
v | regress-test-bloom_e_01234567890123456789
159+
v | _ts_meta_v2_first_a_01234567890123456789
160+
v | _ts_meta_v2_first_b_01234567890123456789
161+
v | _ts_meta_v2_last_a_01234567890123456789
162+
v | _ts_meta_v2_last_b_01234567890123456789
163+
v | a_01234567890123456789
164+
v | b_01234567890123456789
165+
v | c_01234567890123456789
166+
v | cmax
167+
v | cmin
168+
v | ctid
169+
v | d_01234567890123456789
170+
v | e_01234567890123456789
171+
v | f_01234567890123456789
172+
v | g_01234567890123456789
173+
v | h_01234567890123456789
174+
v | i_01234567890123456789
175+
v | tableoid
176+
v | xmax
177+
v | xmin
178178

179179
-- Make sure the duplicate column detection works for long column names
180180
\set ON_ERROR_STOP 0

tsl/test/expected/compress_compbloom_naming.out

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,22 @@ SELECT compress_chunk(c) FROM show_chunks('t') c;
3030
-- ERROR: column regress-test-bloom_a_b_c specified more than once
3131
-- Check the bloom column names in the compressed chunk
3232
SELECT
33-
relname,
34-
attname
33+
h.table_name AS relname,
34+
a.attname
3535
FROM
36-
pg_attribute a,
37-
pg_class c
36+
_timescaledb_catalog.compression_settings cs
37+
JOIN _timescaledb_catalog.chunk ch ON cs.relid = format('%I.%I', ch.schema_name, ch.table_name)::regclass
38+
JOIN _timescaledb_catalog.hypertable h ON ch.hypertable_id = h.id
39+
JOIN pg_attribute a ON a.attrelid = cs.compress_relid
3840
WHERE
39-
c.oid=a.attrelid AND
40-
attname LIKE '%_ts_meta%bloom%a_b_c%' AND
41-
relname LIKE '%chunk'
41+
a.attname LIKE '%_ts_meta%bloom%a_b_c%'
4242
ORDER BY
43-
relname::text COLLATE "C",
44-
attname::text COLLATE "C";
45-
relname | attname
46-
--------------------------+-------------------------------
47-
compress_hyper_2_2_chunk | regress-test-bloom_c66a_a_b_c
48-
compress_hyper_2_2_chunk | regress-test-bloom_ee9c_a_b_c
43+
h.table_name COLLATE "C",
44+
a.attname::text COLLATE "C";
45+
relname | attname
46+
---------+-------------------------------
47+
t | regress-test-bloom_c66a_a_b_c
48+
t | regress-test-bloom_ee9c_a_b_c
4949

5050
-- Verify the assumption that the zero byte separator used in the
5151
-- bloom column names is not allowed in Postgres column names:

tsl/test/expected/compression.out

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ numrows_post_compression | 1
152152
numrows_frozen_immediately | 1
153153

154154
\x
155-
select ch1.id, ch1.schema_name, ch1.table_name , ch2.table_name as compress_table
155+
select ch1.id, ch1.schema_name, ch1.table_name , compress.relname as compress_table
156156
from
157-
_timescaledb_catalog.chunk ch1, _timescaledb_catalog.chunk ch2, _timescaledb_catalog.compression_settings cs
158-
where cs.relid = format('%I.%I', ch1.schema_name, ch1.table_name)::regclass AND cs.compress_relid = format('%I.%I', ch2.schema_name, ch2.table_name)::regclass;
157+
_timescaledb_catalog.chunk ch1, _timescaledb_catalog.compression_settings cs, pg_class compress
158+
where cs.relid = format('%I.%I', ch1.schema_name, ch1.table_name)::regclass AND cs.compress_relid = compress.oid;
159159
id | schema_name | table_name | compress_table
160160
----+-----------------------+------------------+--------------------------
161161
2 | _timescaledb_internal | _hyper_1_2_chunk | compress_hyper_2_5_chunk
@@ -1178,11 +1178,11 @@ SELECT relpages, CASE WHEN reltuples > 0 THEN reltuples ELSE 0 END as reltuples
11781178
----------+-----------
11791179
0 | 0
11801180

1181-
SELECT compch.table_name as "STAT_COMP_CHUNK_NAME"
1181+
SELECT compch.relname as "STAT_COMP_CHUNK_NAME"
11821182
FROM _timescaledb_catalog.hypertable ht, _timescaledb_catalog.chunk ch
1183-
, _timescaledb_catalog.chunk compch, _timescaledb_catalog.compression_settings cs
1183+
, pg_class compch, _timescaledb_catalog.compression_settings cs
11841184
WHERE ht.table_name = 'stattest' AND ch.hypertable_id = ht.id
1185-
AND cs.relid = format('%I.%I', ch.schema_name, ch.table_name)::regclass AND cs.compress_relid = format('%I.%I', compch.schema_name, compch.table_name)::regclass \gset
1185+
AND cs.relid = format('%I.%I', ch.schema_name, ch.table_name)::regclass AND cs.compress_relid = compch.oid \gset
11861186
-- reltuples is initially -1 on PG14 before VACUUM/ANALYZE was run
11871187
SELECT relpages, CASE WHEN reltuples > 0 THEN reltuples ELSE 0 END as reltuples FROM pg_class WHERE relname = :'STAT_COMP_CHUNK_NAME';
11881188
relpages | reltuples

0 commit comments

Comments
 (0)