@@ -283,7 +283,20 @@ select * from chunk_info;
283
283
_hyper_1_5_chunk | heap | (("time" >= 'Wed Jan 03 16:00:00 2024 PST'::timestamp with time zone) AND ("time" < 'Thu Jan 04 16:00:00 2024 PST'::timestamp with time zone))
284
284
(10 rows)
285
285
286
+ select * from _timescaledb_catalog.compression_chunk_size order by chunk_id;
287
+ chunk_id | compressed_chunk_id | uncompressed_heap_size | uncompressed_toast_size | uncompressed_index_size | compressed_heap_size | compressed_toast_size | compressed_index_size | numrows_pre_compression | numrows_post_compression | numrows_frozen_immediately
288
+ ----------+---------------------+------------------------+-------------------------+-------------------------+----------------------+-----------------------+-----------------------+-------------------------+--------------------------+----------------------------
289
+ 1 | 6 | 8192 | 0 | 32768 | 16384 | 8192 | 16384 | 1 | 1 | 1
290
+ 3 | 7 | 8192 | 0 | 32768 | 16384 | 8192 | 16384 | 1 | 1 | 1
291
+ (2 rows)
292
+
286
293
call merge_chunks('{_timescaledb_internal._hyper_1_1_chunk, _timescaledb_internal._hyper_1_2_chunk, _timescaledb_internal._hyper_1_3_chunk}');
294
+ select * from _timescaledb_catalog.compression_chunk_size order by chunk_id;
295
+ chunk_id | compressed_chunk_id | uncompressed_heap_size | uncompressed_toast_size | uncompressed_index_size | compressed_heap_size | compressed_toast_size | compressed_index_size | numrows_pre_compression | numrows_post_compression | numrows_frozen_immediately
296
+ ----------+---------------------+------------------------+-------------------------+-------------------------+----------------------+-----------------------+-----------------------+-------------------------+--------------------------+----------------------------
297
+ 1 | 6 | 16384 | 0 | 65536 | 32768 | 16384 | 32768 | 2 | 2 | 2
298
+ (1 row)
299
+
287
300
select * from chunk_info;
288
301
chunk | tam | checkconstraint
289
302
------------------+------+------------------------------------------------------------------------------------------------------------------------------------------------
@@ -627,7 +640,65 @@ select * from partitions;
627
640
_hyper_1_14_chunk | device | 1431655764 | 9223372036854775807
628
641
(24 rows)
629
642
630
- -- Merge all chunks until only 1 remains
643
+ -- Show which chunks are compressed. Their compression_chunk_size
644
+ -- metadata should be merged.
645
+ select chunk_name from timescaledb_information.chunks
646
+ where is_compressed=true order by chunk_name;
647
+ chunk_name
648
+ ------------------
649
+ _hyper_1_1_chunk
650
+ _hyper_1_2_chunk
651
+ (2 rows)
652
+
653
+ --
654
+ -- Check that compression_chunk_size stats are also merged when we
655
+ -- merge compressed chunks.
656
+ --
657
+ -- Use a view to compare merged stats against the total sum of that
658
+ -- stats for all chunks. There are only two compressed chunks, 1 and
659
+ -- 2. Show each chunks stats as the fraction of the total size. This
660
+ -- is to make the test work across different architectures that show
661
+ -- slightly different absolute disk sizes.
662
+ ---
663
+ select
664
+ sum(ccs.uncompressed_heap_size) as total_uncompressed_heap_size,
665
+ sum(ccs.uncompressed_toast_size) as total_uncompressed_toast_size,
666
+ sum(ccs.uncompressed_index_size) as total_uncompressed_index_size,
667
+ sum(ccs.compressed_heap_size) as total_compressed_heap_size,
668
+ sum(ccs.compressed_toast_size) as total_compressed_toast_size,
669
+ sum(ccs.compressed_index_size) as total_compressed_index_size,
670
+ sum(ccs.numrows_pre_compression) as total_numrows_pre_compression,
671
+ sum(ccs.numrows_post_compression) as total_numrows_post_compression,
672
+ sum(ccs.numrows_frozen_immediately) as total_numrows_frozen_immediately
673
+ from _timescaledb_catalog.compression_chunk_size ccs \gset
674
+ -- View to show current chunk compression size stats as a fraction of
675
+ -- the totals.
676
+ create view compression_size_fraction as
677
+ select
678
+ ccs.chunk_id,
679
+ ccs.compressed_chunk_id,
680
+ round(ccs.uncompressed_heap_size::numeric / :total_uncompressed_heap_size, 1) as uncompressed_heap_size_fraction,
681
+ ccs.uncompressed_toast_size::numeric as uncompressed_toast_size_fraction,
682
+ round(ccs.uncompressed_index_size::numeric / :total_uncompressed_index_size, 1) as uncompressed_index_size_fraction,
683
+ round(ccs.compressed_heap_size::numeric / :total_compressed_heap_size, 1) as compressed_heap_size_fraction,
684
+ round(ccs.compressed_toast_size::numeric / :total_compressed_toast_size, 1) as compressed_toast_size_fraction,
685
+ round(ccs.compressed_index_size::numeric / :total_compressed_index_size, 1) as compressed_index_size_fraction,
686
+ round(ccs.numrows_pre_compression ::numeric/ :total_numrows_pre_compression, 1) as numrows_pre_compression_fraction,
687
+ round(ccs.numrows_post_compression::numeric / :total_numrows_post_compression, 1) as numrows_post_compression_fraction,
688
+ round(ccs.numrows_frozen_immediately::numeric / :total_numrows_frozen_immediately, 1) as numrows_frozen_immediately_fraction
689
+ from _timescaledb_catalog.compression_chunk_size ccs
690
+ order by chunk_id;
691
+ --
692
+ -- Merge all chunks until only 1 remains. Also check that metadata is
693
+ -- merged.
694
+ ---
695
+ select * from compression_size_fraction;
696
+ chunk_id | compressed_chunk_id | uncompressed_heap_size_fraction | uncompressed_toast_size_fraction | uncompressed_index_size_fraction | compressed_heap_size_fraction | compressed_toast_size_fraction | compressed_index_size_fraction | numrows_pre_compression_fraction | numrows_post_compression_fraction | numrows_frozen_immediately_fraction
697
+ ----------+---------------------+---------------------------------+----------------------------------+----------------------------------+-------------------------------+--------------------------------+--------------------------------+----------------------------------+-----------------------------------+-------------------------------------
698
+ 1 | 17 | 0.5 | 0 | 0.5 | 0.5 | 0.5 | 0.5 | 0.5 | 0.5 | 0.5
699
+ 2 | 18 | 0.5 | 0 | 0.5 | 0.5 | 0.5 | 0.5 | 0.5 | 0.5 | 0.5
700
+ (2 rows)
701
+
631
702
select count(*), sum(device), round(sum(temp)::numeric, 4) from mergeme;
632
703
count | sum | round
633
704
--------+---------+---------------
@@ -689,6 +760,15 @@ select * from partitions;
689
760
(12 rows)
690
761
691
762
call merge_chunks(ARRAY['_timescaledb_internal._hyper_1_3_chunk', '_timescaledb_internal._hyper_1_11_chunk','_timescaledb_internal._hyper_1_14_chunk', '_timescaledb_internal._hyper_1_16_chunk']);
763
+ -- Final merge, involving the two compressed chunks 1 and 2. The stats
764
+ -- should also be merged.
765
+ select * from compression_size_fraction;
766
+ chunk_id | compressed_chunk_id | uncompressed_heap_size_fraction | uncompressed_toast_size_fraction | uncompressed_index_size_fraction | compressed_heap_size_fraction | compressed_toast_size_fraction | compressed_index_size_fraction | numrows_pre_compression_fraction | numrows_post_compression_fraction | numrows_frozen_immediately_fraction
767
+ ----------+---------------------+---------------------------------+----------------------------------+----------------------------------+-------------------------------+--------------------------------+--------------------------------+----------------------------------+-----------------------------------+-------------------------------------
768
+ 1 | 17 | 0.5 | 0 | 0.5 | 0.5 | 0.5 | 0.5 | 0.5 | 0.5 | 0.5
769
+ 2 | 18 | 0.5 | 0 | 0.5 | 0.5 | 0.5 | 0.5 | 0.5 | 0.5 | 0.5
770
+ (2 rows)
771
+
692
772
select count(*), sum(device), round(sum(temp)::numeric, 4) from mergeme;
693
773
count | sum | round
694
774
--------+---------+---------------
@@ -707,6 +787,12 @@ select * from partitions;
707
787
(6 rows)
708
788
709
789
call merge_chunks(ARRAY['_timescaledb_internal._hyper_1_3_chunk', '_timescaledb_internal._hyper_1_1_chunk','_timescaledb_internal._hyper_1_2_chunk']);
790
+ select * from compression_size_fraction;
791
+ chunk_id | compressed_chunk_id | uncompressed_heap_size_fraction | uncompressed_toast_size_fraction | uncompressed_index_size_fraction | compressed_heap_size_fraction | compressed_toast_size_fraction | compressed_index_size_fraction | numrows_pre_compression_fraction | numrows_post_compression_fraction | numrows_frozen_immediately_fraction
792
+ ----------+---------------------+---------------------------------+----------------------------------+----------------------------------+-------------------------------+--------------------------------+--------------------------------+----------------------------------+-----------------------------------+-------------------------------------
793
+ 1 | 17 | 1.0 | 0 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0
794
+ (1 row)
795
+
710
796
select count(*), sum(device), round(sum(temp)::numeric, 4) from mergeme;
711
797
count | sum | round
712
798
--------+---------+---------------
0 commit comments