forked from timescale/timescaledb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrebuild_sparse_index.out
More file actions
637 lines (565 loc) · 25.5 KB
/
Copy pathrebuild_sparse_index.out
File metadata and controls
637 lines (565 loc) · 25.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
-- This file and its contents are licensed under the Timescale License.
-- Please see the included NOTICE for copyright information and
-- LICENSE-TIMESCALE for a copy of the license.
-- Test rebuild_sparse_index function
CREATE OR REPLACE FUNCTION show_compressed_columns(chunk_regclass regclass)
RETURNS TABLE(attname name, typname name) AS $$
SELECT a.attname, t.typname
FROM pg_attribute a
JOIN pg_type t ON a.atttypid = t.oid
WHERE a.attrelid = (
SELECT cs.compress_relid
FROM _timescaledb_catalog.compression_settings cs
WHERE cs.relid = chunk_regclass
)
AND a.attname LIKE '_ts_meta_%'
AND a.attnum > 0
AND NOT a.attisdropped
ORDER BY a.attname;
$$ LANGUAGE sql;
CREATE OR REPLACE FUNCTION show_chunk_index(chunk_regclass regclass)
RETURNS jsonb AS $$
SELECT cs.index
FROM _timescaledb_catalog.compression_settings cs
WHERE cs.relid = chunk_regclass;
$$ LANGUAGE sql;
CREATE TABLE rsi_test(
time timestamptz NOT NULL,
device int,
sensor int,
temp float8,
val int
);
SELECT create_hypertable('rsi_test', 'time', chunk_time_interval => INTERVAL '1 day');
create_hypertable
-----------------------
(1,public,rsi_test,t)
INSERT INTO rsi_test
SELECT t, (i % 5) + 1, (i % 3) + 1, random() * 100, (i * 7) % 13
FROM generate_series('2024-01-01 01:00'::timestamptz, '2024-01-01 23:59', '1 minute') t,
generate_series(1, 3) i;
SELECT relid::text AS chunk1
FROM _timescaledb_catalog.chunk
WHERE hypertable_id = (SELECT id FROM _timescaledb_catalog.hypertable
WHERE table_name = 'rsi_test')
ORDER BY id LIMIT 1 \gset
-- Test 1: initial compression with bloom + minmax
ALTER TABLE rsi_test SET (
timescaledb.compress,
timescaledb.compress_orderby = 'time',
timescaledb.compress_index = 'bloom("device"), minmax("temp")'
);
SELECT compress_chunk(:'chunk1');
compress_chunk
----------------------------------------
_timescaledb_internal._hyper_1_1_chunk
SELECT show_chunk_index(:'chunk1'::regclass);
show_chunk_index
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[{"type": "bloom", "column": "device", "source": "config"}, {"type": "minmax", "column": "temp", "source": "config"}, {"type": "minmax", "column": "time", "source": "orderby"}, {"type": "firstlast", "column": "time", "source": "orderby"}]
SELECT * FROM show_compressed_columns(:'chunk1'::regclass);
attname | typname
---------------------------+-------------
_ts_meta_count | int4
_ts_meta_max_1 | timestamptz
_ts_meta_min_1 | timestamptz
regress-test-bloom_device | bloom1
_ts_meta_v2_first_time | timestamptz
_ts_meta_v2_last_time | timestamptz
_ts_meta_v2_max_temp | float8
_ts_meta_v2_min_temp | float8
-- Test 2: settings match, should skip
SELECT _timescaledb_functions.rebuild_sparse_index(:'chunk1'::regclass);
NOTICE: sparse index settings for chunk "_timescaledb_internal._hyper_1_1_chunk" already match hypertable, skipping (use force => true to override)
rebuild_sparse_index
----------------------
-- Test 3: swap bloom("device") for bloom("device","sensor"), keep minmax("temp")
ALTER TABLE rsi_test SET (
timescaledb.compress,
timescaledb.compress_orderby = 'time',
timescaledb.compress_index = 'bloom("device","sensor"), minmax("temp")'
);
NOTICE: updated compression settings will only apply to future compressions
SELECT show_chunk_index(:'chunk1'::regclass);
show_chunk_index
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[{"type": "bloom", "column": "device", "source": "config"}, {"type": "minmax", "column": "temp", "source": "config"}, {"type": "minmax", "column": "time", "source": "orderby"}, {"type": "firstlast", "column": "time", "source": "orderby"}]
SELECT _timescaledb_functions.rebuild_sparse_index(:'chunk1'::regclass);
rebuild_sparse_index
----------------------
SELECT * FROM show_compressed_columns(:'chunk1'::regclass);
attname | typname
---------------------------------------+-------------
_ts_meta_count | int4
_ts_meta_max_1 | timestamptz
_ts_meta_min_1 | timestamptz
regress-test-bloom_2b4d_device_sensor | bloom1
_ts_meta_v2_first_time | timestamptz
_ts_meta_v2_last_time | timestamptz
_ts_meta_v2_max_temp | float8
_ts_meta_v2_min_temp | float8
-- Test 4: remove all sparse indexes
ALTER TABLE rsi_test SET (
timescaledb.compress,
timescaledb.compress_orderby = 'time',
timescaledb.compress_index = ''
);
NOTICE: updated compression settings will only apply to future compressions
SELECT _timescaledb_functions.rebuild_sparse_index(:'chunk1'::regclass);
rebuild_sparse_index
----------------------
SELECT * FROM show_compressed_columns(:'chunk1'::regclass);
attname | typname
------------------------+-------------
_ts_meta_count | int4
_ts_meta_max_1 | timestamptz
_ts_meta_min_1 | timestamptz
_ts_meta_v2_first_time | timestamptz
_ts_meta_v2_last_time | timestamptz
-- Test 5: add back bloom + minmax + composite bloom
ALTER TABLE rsi_test SET (
timescaledb.compress,
timescaledb.compress_orderby = 'time',
timescaledb.compress_index = 'bloom("device"), minmax("temp"), bloom("device","val")'
);
NOTICE: updated compression settings will only apply to future compressions
SELECT _timescaledb_functions.rebuild_sparse_index(:'chunk1'::regclass);
rebuild_sparse_index
----------------------
SELECT * FROM show_compressed_columns(:'chunk1'::regclass);
attname | typname
------------------------------------+-------------
_ts_meta_count | int4
_ts_meta_max_1 | timestamptz
_ts_meta_min_1 | timestamptz
regress-test-bloom_device | bloom1
regress-test-bloom_e076_device_val | bloom1
_ts_meta_v2_first_time | timestamptz
_ts_meta_v2_last_time | timestamptz
_ts_meta_v2_max_temp | float8
_ts_meta_v2_min_temp | float8
-- Test 6: force rebuild when settings already match
SELECT _timescaledb_functions.rebuild_sparse_index(:'chunk1'::regclass, force => true);
rebuild_sparse_index
----------------------
SELECT * FROM show_compressed_columns(:'chunk1'::regclass);
attname | typname
------------------------------------+-------------
_ts_meta_count | int4
_ts_meta_max_1 | timestamptz
_ts_meta_min_1 | timestamptz
regress-test-bloom_device | bloom1
regress-test-bloom_e076_device_val | bloom1
_ts_meta_v2_first_time | timestamptz
_ts_meta_v2_last_time | timestamptz
_ts_meta_v2_max_temp | float8
_ts_meta_v2_min_temp | float8
-- Test 7: uncompressed chunk, should skip
SELECT decompress_chunk(:'chunk1');
decompress_chunk
----------------------------------------
_timescaledb_internal._hyper_1_1_chunk
SELECT _timescaledb_functions.rebuild_sparse_index(:'chunk1'::regclass);
NOTICE: chunk "_timescaledb_internal._hyper_1_1_chunk" is uncompressed or frozen, skipping
rebuild_sparse_index
----------------------
DROP TABLE rsi_test CASCADE;
-- Data integrity tests: verify rebuilt sparse index values match the
-- original compression output (file diff) and that bloom filters
-- correctly identify present and absent values.
\set TEST_BASE_NAME rebuild_sparse_index
CREATE TABLE rsi_integrity(
time timestamptz NOT NULL,
device text NOT NULL,
temp float8,
humidity int,
label text,
reading uuid
);
SELECT create_hypertable('rsi_integrity', 'time', chunk_time_interval => INTERVAL '1 day');
create_hypertable
----------------------------
(2,public,rsi_integrity,t)
-- NULLs at row 5000/5001 to stress firstlast NULL handling at batch boundaries
SELECT setseed(0.42);
setseed
---------
INSERT INTO rsi_integrity
SELECT
'2024-01-01'::timestamptz + ((row_num - 1) * interval '10 seconds'),
'd' || ((row_num % 5) + 1),
CASE WHEN row_num % 5000 IN (0, 1) THEN NULL ELSE random() * 100 END,
CASE WHEN row_num % 5000 IN (0, 1) THEN NULL ELSE (random() * 200)::int END,
CASE WHEN row_num % 5000 IN (0, 1) THEN NULL ELSE 'label_' || (row_num % 7) END,
CASE WHEN row_num % 5000 IN (0, 1) THEN NULL ELSE gen_random_uuid() END
FROM generate_series(1, 15000) row_num;
SELECT relid::text AS ichunk1
FROM _timescaledb_catalog.chunk
WHERE hypertable_id = (SELECT id FROM _timescaledb_catalog.hypertable WHERE table_name = 'rsi_integrity')
ORDER BY id LIMIT 1 \gset
SELECT relid::text AS ichunk2
FROM _timescaledb_catalog.chunk
WHERE hypertable_id = (SELECT id FROM _timescaledb_catalog.hypertable WHERE table_name = 'rsi_integrity')
ORDER BY id LIMIT 1 OFFSET 1 \gset
SELECT format('%s/results/%s_original.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') AS "ORIGINAL",
format('%s/results/%s_rebuilt.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') AS "REBUILT"
\gset
-- Dump _ts_meta_v2_* columns sorted by name (avoids column reorder after drop+add)
CREATE OR REPLACE FUNCTION dump_sparse_metadata(chunk_regclass regclass)
RETURNS SETOF text AS $$
DECLARE
compressed_relid oid;
col_list text;
BEGIN
SELECT cs.compress_relid INTO compressed_relid
FROM _timescaledb_catalog.compression_settings cs
WHERE cs.relid = chunk_regclass;
SELECT string_agg(quote_ident(a.attname), ', ' ORDER BY a.attname) INTO col_list
FROM pg_attribute a
WHERE a.attrelid = compressed_relid
AND a.attname LIKE '_ts_meta_v2_%'
AND a.attnum > 0
AND NOT a.attisdropped;
RETURN QUERY EXECUTE format(
'SELECT row(%s)::text FROM %s ORDER BY _ts_meta_min_1',
col_list, compressed_relid::regclass);
END;
$$ LANGUAGE plpgsql;
-- Test 8: minmax integrity (compress, save, drop+rebuild, save, diff)
ALTER TABLE rsi_integrity SET (
timescaledb.compress,
timescaledb.compress_segmentby = 'device',
timescaledb.compress_orderby = 'time',
timescaledb.compress_index = 'minmax("temp"), minmax("humidity"), minmax("label"), minmax("reading")'
);
SELECT compress_chunk(:'ichunk1');
compress_chunk
----------------------------------------
_timescaledb_internal._hyper_2_3_chunk
SELECT compress_chunk(:'ichunk2');
compress_chunk
----------------------------------------
_timescaledb_internal._hyper_2_4_chunk
SELECT comp_ns.nspname AS ic_schema1, comp_cl.relname AS ic_table1
FROM _timescaledb_catalog.compression_settings cs
JOIN pg_class comp_cl ON cs.compress_relid = comp_cl.oid
JOIN pg_namespace comp_ns ON comp_cl.relnamespace = comp_ns.oid
WHERE cs.relid = :'ichunk1'::regclass \gset
SELECT comp_ns.nspname AS ic_schema2, comp_cl.relname AS ic_table2
FROM _timescaledb_catalog.compression_settings cs
JOIN pg_class comp_cl ON cs.compress_relid = comp_cl.oid
JOIN pg_namespace comp_ns ON comp_cl.relnamespace = comp_ns.oid
WHERE cs.relid = :'ichunk2'::regclass \gset
\o :ORIGINAL
SELECT * FROM dump_sparse_metadata(:'ichunk1'::regclass);
SELECT * FROM dump_sparse_metadata(:'ichunk2'::regclass);
\o
ALTER TABLE rsi_integrity SET (
timescaledb.compress,
timescaledb.compress_segmentby = 'device',
timescaledb.compress_orderby = 'time',
timescaledb.compress_index = ''
);
NOTICE: updated compression settings will only apply to future compressions
SELECT _timescaledb_functions.rebuild_sparse_index(:'ichunk1'::regclass);
rebuild_sparse_index
----------------------
SELECT _timescaledb_functions.rebuild_sparse_index(:'ichunk2'::regclass);
rebuild_sparse_index
----------------------
ALTER TABLE rsi_integrity SET (
timescaledb.compress,
timescaledb.compress_segmentby = 'device',
timescaledb.compress_orderby = 'time',
timescaledb.compress_index = 'minmax("temp"), minmax("humidity"), minmax("label"), minmax("reading")'
);
NOTICE: updated compression settings will only apply to future compressions
SELECT _timescaledb_functions.rebuild_sparse_index(:'ichunk1'::regclass);
rebuild_sparse_index
----------------------
SELECT _timescaledb_functions.rebuild_sparse_index(:'ichunk2'::regclass);
rebuild_sparse_index
----------------------
\o :REBUILT
SELECT * FROM dump_sparse_metadata(:'ichunk1'::regclass);
SELECT * FROM dump_sparse_metadata(:'ichunk2'::regclass);
\o
SELECT format('\! diff -u --label "minmax original" --label "minmax rebuilt" %s %s',
:'ORIGINAL', :'REBUILT') AS "DIFF_CMD" \gset
:DIFF_CMD
SELECT decompress_chunk(:'ichunk1');
decompress_chunk
----------------------------------------
_timescaledb_internal._hyper_2_3_chunk
SELECT decompress_chunk(:'ichunk2');
decompress_chunk
----------------------------------------
_timescaledb_internal._hyper_2_4_chunk
-- Test 9: firstlast integrity (compress, save, drop+rebuild, save, diff)
ALTER TABLE rsi_integrity SET (
timescaledb.compress,
timescaledb.compress_segmentby = 'device',
timescaledb.compress_orderby = 'time',
timescaledb.compress_index = 'firstlast("temp"), firstlast("humidity"), firstlast("label"), firstlast("reading")'
);
NOTICE: updated compression settings will only apply to future compressions
SELECT compress_chunk(:'ichunk1');
compress_chunk
----------------------------------------
_timescaledb_internal._hyper_2_3_chunk
SELECT compress_chunk(:'ichunk2');
compress_chunk
----------------------------------------
_timescaledb_internal._hyper_2_4_chunk
-- re-fetch compressed chunk names after recompress
SELECT comp_ns.nspname AS ic_schema1, comp_cl.relname AS ic_table1
FROM _timescaledb_catalog.compression_settings cs
JOIN pg_class comp_cl ON cs.compress_relid = comp_cl.oid
JOIN pg_namespace comp_ns ON comp_cl.relnamespace = comp_ns.oid
WHERE cs.relid = :'ichunk1'::regclass \gset
SELECT comp_ns.nspname AS ic_schema2, comp_cl.relname AS ic_table2
FROM _timescaledb_catalog.compression_settings cs
JOIN pg_class comp_cl ON cs.compress_relid = comp_cl.oid
JOIN pg_namespace comp_ns ON comp_cl.relnamespace = comp_ns.oid
WHERE cs.relid = :'ichunk2'::regclass \gset
\o :ORIGINAL
SELECT * FROM dump_sparse_metadata(:'ichunk1'::regclass);
SELECT * FROM dump_sparse_metadata(:'ichunk2'::regclass);
\o
ALTER TABLE rsi_integrity SET (
timescaledb.compress,
timescaledb.compress_segmentby = 'device',
timescaledb.compress_orderby = 'time',
timescaledb.compress_index = ''
);
NOTICE: updated compression settings will only apply to future compressions
SELECT _timescaledb_functions.rebuild_sparse_index(:'ichunk1'::regclass);
rebuild_sparse_index
----------------------
SELECT _timescaledb_functions.rebuild_sparse_index(:'ichunk2'::regclass);
rebuild_sparse_index
----------------------
ALTER TABLE rsi_integrity SET (
timescaledb.compress,
timescaledb.compress_segmentby = 'device',
timescaledb.compress_orderby = 'time',
timescaledb.compress_index = 'firstlast("temp"), firstlast("humidity"), firstlast("label"), firstlast("reading")'
);
NOTICE: updated compression settings will only apply to future compressions
SELECT _timescaledb_functions.rebuild_sparse_index(:'ichunk1'::regclass);
rebuild_sparse_index
----------------------
SELECT _timescaledb_functions.rebuild_sparse_index(:'ichunk2'::regclass);
rebuild_sparse_index
----------------------
\o :REBUILT
SELECT * FROM dump_sparse_metadata(:'ichunk1'::regclass);
SELECT * FROM dump_sparse_metadata(:'ichunk2'::regclass);
\o
SELECT format('\! diff -u --label "firstlast original" --label "firstlast rebuilt" %s %s',
:'ORIGINAL', :'REBUILT') AS "DIFF_CMD" \gset
:DIFF_CMD
SELECT decompress_chunk(:'ichunk1');
decompress_chunk
----------------------------------------
_timescaledb_internal._hyper_2_3_chunk
SELECT decompress_chunk(:'ichunk2');
decompress_chunk
----------------------------------------
_timescaledb_internal._hyper_2_4_chunk
-- Test 10: single-column bloom integrity (drop, rebuild, check contains)
ALTER TABLE rsi_integrity SET (
timescaledb.compress,
timescaledb.compress_segmentby = 'device',
timescaledb.compress_orderby = 'time',
timescaledb.compress_index = 'bloom("humidity"), bloom("label")'
);
NOTICE: updated compression settings will only apply to future compressions
SELECT compress_chunk(:'ichunk1');
compress_chunk
----------------------------------------
_timescaledb_internal._hyper_2_3_chunk
SELECT comp_ns.nspname AS ic_schema1, comp_cl.relname AS ic_table1
FROM _timescaledb_catalog.compression_settings cs
JOIN pg_class comp_cl ON cs.compress_relid = comp_cl.oid
JOIN pg_namespace comp_ns ON comp_cl.relnamespace = comp_ns.oid
WHERE cs.relid = :'ichunk1'::regclass \gset
ALTER TABLE rsi_integrity SET (
timescaledb.compress,
timescaledb.compress_segmentby = 'device',
timescaledb.compress_orderby = 'time',
timescaledb.compress_index = ''
);
NOTICE: updated compression settings will only apply to future compressions
SELECT _timescaledb_functions.rebuild_sparse_index(:'ichunk1'::regclass);
rebuild_sparse_index
----------------------
SELECT * FROM show_compressed_columns(:'ichunk1'::regclass);
attname | typname
------------------------+-------------
_ts_meta_count | int4
_ts_meta_max_1 | timestamptz
_ts_meta_min_1 | timestamptz
_ts_meta_v2_first_time | timestamptz
_ts_meta_v2_last_time | timestamptz
ALTER TABLE rsi_integrity SET (
timescaledb.compress,
timescaledb.compress_segmentby = 'device',
timescaledb.compress_orderby = 'time',
timescaledb.compress_index = 'bloom("humidity"), bloom("label")'
);
NOTICE: updated compression settings will only apply to future compressions
SELECT _timescaledb_functions.rebuild_sparse_index(:'ichunk1'::regclass);
rebuild_sparse_index
----------------------
-- look up bloom column names (prefix varies between test/production builds)
SELECT a.attname AS bloom_humidity
FROM pg_attribute a
JOIN pg_type t ON a.atttypid = t.oid
WHERE a.attrelid = (:'ic_schema1' || '.' || :'ic_table1')::regclass
AND t.typname = 'bloom1' AND a.attname LIKE '%humidity'
AND NOT a.attisdropped LIMIT 1 \gset
SELECT a.attname AS bloom_label
FROM pg_attribute a
JOIN pg_type t ON a.atttypid = t.oid
WHERE a.attrelid = (:'ic_schema1' || '.' || :'ic_table1')::regclass
AND t.typname = 'bloom1' AND a.attname LIKE '%label'
AND NOT a.attisdropped LIMIT 1 \gset
-- present values (expect true)
SELECT _timescaledb_functions.bloom1_contains(:"bloom_humidity", 42) AS val_42,
_timescaledb_functions.bloom1_contains(:"bloom_humidity", 100) AS val_100,
_timescaledb_functions.bloom1_contains(:"bloom_humidity", 7) AS val_7
FROM :ic_schema1.:ic_table1 WHERE device = 'd1' LIMIT 1;
val_42 | val_100 | val_7
--------+---------+-------
t | t | t
-- absent values (expect false)
SELECT _timescaledb_functions.bloom1_contains(:"bloom_humidity", -999) AS val_neg999,
_timescaledb_functions.bloom1_contains(:"bloom_humidity", 999) AS val_999,
_timescaledb_functions.bloom1_contains(:"bloom_humidity", 12345) AS val_12345
FROM :ic_schema1.:ic_table1 WHERE device = 'd1' LIMIT 1;
val_neg999 | val_999 | val_12345
------------+---------+-----------
f | f | f
-- present labels (expect true)
SELECT _timescaledb_functions.bloom1_contains(:"bloom_label", 'label_0'::text) AS label_0,
_timescaledb_functions.bloom1_contains(:"bloom_label", 'label_3'::text) AS label_3,
_timescaledb_functions.bloom1_contains(:"bloom_label", 'label_6'::text) AS label_6
FROM :ic_schema1.:ic_table1 WHERE device = 'd2' LIMIT 1;
label_0 | label_3 | label_6
---------+---------+---------
t | t | t
-- absent labels (expect false)
SELECT _timescaledb_functions.bloom1_contains(:"bloom_label", 'nonexistent'::text) AS nope1,
_timescaledb_functions.bloom1_contains(:"bloom_label", 'zzz_never'::text) AS nope2,
_timescaledb_functions.bloom1_contains(:"bloom_label", 'NOPE'::text) AS nope3
FROM :ic_schema1.:ic_table1 WHERE device = 'd2' LIMIT 1;
nope1 | nope2 | nope3
-------+-------+-------
f | f | f
-- Sparse index integrity: the (device, first_time, last_time) btree must be
-- able to find every batch for every device after rebuild_sparse_index, not
-- just the ones whose metadata rewrite happened to be a HOT update. Forced
-- index/bitmap scans must return the same per-device batch counts as an
-- unindexed scan.
SET enable_indexscan = off;
SET enable_bitmapscan = off;
SELECT device, count(*) FROM :ic_schema1.:ic_table1 GROUP BY device ORDER BY device;
device | count
--------+-------
d1 | 2
d2 | 2
d3 | 2
d4 | 2
d5 | 2
RESET enable_indexscan;
RESET enable_bitmapscan;
SET enable_seqscan = off;
SELECT device, count(*) FROM :ic_schema1.:ic_table1 GROUP BY device ORDER BY device;
device | count
--------+-------
d1 | 2
d2 | 2
d3 | 2
d4 | 2
d5 | 2
RESET enable_seqscan;
SELECT decompress_chunk(:'ichunk1');
decompress_chunk
----------------------------------------
_timescaledb_internal._hyper_2_3_chunk
-- Test 11: composite bloom integrity (drop, rebuild, verify via explain)
ALTER TABLE rsi_integrity SET (
timescaledb.compress,
timescaledb.compress_segmentby = 'device',
timescaledb.compress_orderby = 'time',
timescaledb.compress_index = 'bloom("humidity","label")'
);
NOTICE: updated compression settings will only apply to future compressions
SELECT compress_chunk(:'ichunk1');
compress_chunk
----------------------------------------
_timescaledb_internal._hyper_2_3_chunk
SELECT comp_ns.nspname AS ic_schema1, comp_cl.relname AS ic_table1
FROM _timescaledb_catalog.compression_settings cs
JOIN pg_class comp_cl ON cs.compress_relid = comp_cl.oid
JOIN pg_namespace comp_ns ON comp_cl.relnamespace = comp_ns.oid
WHERE cs.relid = :'ichunk1'::regclass \gset
ALTER TABLE rsi_integrity SET (
timescaledb.compress,
timescaledb.compress_segmentby = 'device',
timescaledb.compress_orderby = 'time',
timescaledb.compress_index = ''
);
NOTICE: updated compression settings will only apply to future compressions
SELECT _timescaledb_functions.rebuild_sparse_index(:'ichunk1'::regclass);
rebuild_sparse_index
----------------------
SELECT * FROM show_compressed_columns(:'ichunk1'::regclass);
attname | typname
------------------------+-------------
_ts_meta_count | int4
_ts_meta_max_1 | timestamptz
_ts_meta_min_1 | timestamptz
_ts_meta_v2_first_time | timestamptz
_ts_meta_v2_last_time | timestamptz
ALTER TABLE rsi_integrity SET (
timescaledb.compress,
timescaledb.compress_segmentby = 'device',
timescaledb.compress_orderby = 'time',
timescaledb.compress_index = 'bloom("humidity","label")'
);
NOTICE: updated compression settings will only apply to future compressions
SELECT _timescaledb_functions.rebuild_sparse_index(:'ichunk1'::regclass);
rebuild_sparse_index
----------------------
SELECT * FROM show_compressed_columns(:'ichunk1'::regclass);
attname | typname
----------------------------------------+-------------
_ts_meta_count | int4
_ts_meta_max_1 | timestamptz
_ts_meta_min_1 | timestamptz
regress-test-bloom_577c_humidity_label | bloom1
_ts_meta_v2_first_time | timestamptz
_ts_meta_v2_last_time | timestamptz
-- composite bloom should appear in the plan filter
EXPLAIN (ANALYZE, BUFFERS OFF, COSTS OFF, TIMING OFF, SUMMARY OFF)
SELECT * FROM rsi_integrity WHERE device = 'd1' AND humidity = 42 AND label = 'label_0';
--- QUERY PLAN ---
Append (actual rows=0.00 loops=1)
-> Custom Scan (ColumnarScan) on _hyper_2_3_chunk (actual rows=0.00 loops=1)
Vectorized Filter: ((humidity = 42) AND (label = 'label_0'::text))
-> Index Scan using _hyper_2_3_chunk_compressed_device__ts_meta_v2_first_time___idx on _hyper_2_3_chunk_compressed (actual rows=0.00 loops=1)
Index Cond: (device = 'd1'::text)
Filter: _timescaledb_functions.bloom1_contains_any_hashes(regress-test-bloom_577c_humidity_label, TEST-HASHES::bigint[])
Rows Removed by Filter: 2
-> Seq Scan on _hyper_2_4_chunk (actual rows=0.00 loops=1)
Filter: ((device = 'd1'::text) AND (humidity = 42) AND (label = 'label_0'::text))
Rows Removed by Filter: 8640
-> Seq Scan on _hyper_2_5_chunk (actual rows=0.00 loops=1)
Filter: ((device = 'd1'::text) AND (humidity = 42) AND (label = 'label_0'::text))
Rows Removed by Filter: 600
DROP TABLE rsi_integrity CASCADE;
DROP FUNCTION show_compressed_columns(regclass);
DROP FUNCTION show_chunk_index(regclass);
DROP FUNCTION dump_sparse_metadata(regclass);