Skip to content

Commit

Permalink
Remove reindex_relation from recompression
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
antekresic committed Jan 16, 2024
1 parent 7ae7cc5 commit 7674b5c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions .unreleased/pr_6529
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implements: #6529 Remove reindex_relation from recompression
8 changes: 0 additions & 8 deletions tsl/src/compression/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = &params;
#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);
Expand Down
19 changes: 17 additions & 2 deletions tsl/test/sql/recompress_chunk_segmentwise.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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');
Expand Down

0 comments on commit 7674b5c

Please sign in to comment.