From 3b2ff9b9b602957b8fd7eebf81285743e191a7a1 Mon Sep 17 00:00:00 2001 From: Ante Kresic Date: Tue, 16 Jan 2024 12:38:10 +0100 Subject: [PATCH] Remove reindex_relation from recompression We used to reindex relation when compressing chunks. Recently we moved to inserting into indexes on compressed chunks in order to reduce locks necessary for the operation. Since recompression uses RowCompressor, it also started inserting tuples into indexes but we never removed the relation reindexing. This change removes the unnecessary reindex call. --- tsl/src/compression/api.c | 8 -------- tsl/test/sql/recompress_chunk_segmentwise.sql | 19 +++++++++++++++++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/tsl/src/compression/api.c b/tsl/src/compression/api.c index 1f84cc211c5..160a22f71d7 100644 --- a/tsl/src/compression/api.c +++ b/tsl/src/compression/api.c @@ -1388,14 +1388,6 @@ tsl_recompress_chunk_segmentwise(PG_FUNCTION_ARGS) index_close(index_rel, AccessExclusiveLock); row_decompressor_close(&decompressor); -#if PG14_LT - int options = 0; -#else - ReindexParams params = { 0 }; - ReindexParams *options = ¶ms; -#endif - reindex_relation(compressed_chunk->table_id, 0, options); - /* changed chunk status, so invalidate any plans involving this chunk */ CacheInvalidateRelcacheByRelid(uncompressed_chunk_id); table_close(uncompressed_chunk_rel, ExclusiveLock); diff --git a/tsl/test/sql/recompress_chunk_segmentwise.sql b/tsl/test/sql/recompress_chunk_segmentwise.sql index 2d47d096000..6cab414df48 100644 --- a/tsl/test/sql/recompress_chunk_segmentwise.sql +++ b/tsl/test/sql/recompress_chunk_segmentwise.sql @@ -211,6 +211,21 @@ call recompress_chunk(:'chunk_to_compress_mytab'); select compressed_chunk_name as compressed_chunk_name_after_recompression from compressed_chunk_info_view where hypertable_name = 'mytab' \gset select :'compressed_chunk_name_before_recompression' as before_segmentwise_recompression, :'compressed_chunk_name_after_recompression' as after_segmentwise_recompression; +-- delete will empty out the compressed chunk but keep its compressed status +DELETE FROM mytab; + +INSERT INTO mytab +SELECT t, a, 3, 2 +FROM generate_series('2023-01-01'::timestamptz, '2023-01-02'::timestamptz, '1 hour'::interval) t +CROSS JOIN generate_series(1, 10, 1) a; +-- recompress will insert newly inserted tuples into compressed chunk along with inserting into the compressed chunk index +CALL recompress_chunk(:'chunk_to_compress_mytab'); +-- make sure we are hitting the index and that the index contains the tuples +SET enable_seqscan TO off; +EXPLAIN (COSTS OFF) SELECT count(*) FROM mytab where a = 2; +SELECT count(*) FROM mytab where a = 2; +SET enable_seqscan TO default; + SELECT decompress_chunk(show_chunks('mytab')); alter table mytab set (timescaledb.compress = false); alter table mytab set (timescaledb.compress); @@ -241,7 +256,7 @@ select compressed_chunk_schema || '.' || compressed_chunk_name as compressed_chu call recompress_chunk(:'chunk_to_compress'); select * from :compressed_chunk_name; --- insert again, check both reindex works and NULL values properly handled +-- insert again, check both index insertion works and NULL values properly handled insert into nullseg_one values (:'start_time', NULL, 4); call recompress_chunk(:'chunk_to_compress'); select * from :compressed_chunk_name; @@ -264,7 +279,7 @@ select compressed_chunk_schema || '.' || compressed_chunk_name as compressed_chu call recompress_chunk(:'chunk_to_compress'); select * from :compressed_chunk_name; --- insert again, check both reindex works and NULL values properly handled +-- insert again, check both index insertion works and NULL values properly handled -- should match existing segment (1, NULL) insert into nullseg_many values (:'start_time', 1, NULL, NULL); call recompress_chunk(:'chunk_to_compress');