Skip to content

Commit

Permalink
Use bulk heap insert API for decompression
Browse files Browse the repository at this point in the history
This should improve the throughput somewhat.

This commit does several things:

* Simplify loop condition in decompressing the compressed batch by using
  the count metadata column.
* Split out a separate function that decompresses the entire compressed
  batch and saves the decompressed tuples slot into RowDecompressor.
* Use bulk table insert function for inserting the decompressed rows,
  this reduces WAL activity.  If we have indexes on uncompressed chunk,
update them one index for entire batch at a time, to reduce load on
shared buffers cache. Before that we used to update all indexes for one
row, then for another, etc.
* Add a test for memory leaks during (de)compression.
* Update the compression_update_delete test to use INFO messages + a
  debug GUC instead of DEBUG messages which are flaky.

This gives 10%-30% speedup on tsbench for decompress_chunk and various
compressed DML queries. This is very far from the performance we had in
2.10, but still a nice improvement.
  • Loading branch information
akuzm committed Nov 16, 2023
1 parent 5f8c9e2 commit e5840e3
Show file tree
Hide file tree
Showing 16 changed files with 669 additions and 347 deletions.
12 changes: 12 additions & 0 deletions src/guc.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ static const struct config_enum_entry require_vector_qual_options[] = {
#endif

DebugRequireVectorQual ts_guc_debug_require_vector_qual = RVQ_Allow;
bool ts_guc_debug_compression_path_info = false;

static bool ts_guc_enable_hypertable_create = true;
static bool ts_guc_enable_hypertable_compression = true;
Expand Down Expand Up @@ -827,6 +828,17 @@ _guc_init(void)
/* assign_hook= */ NULL,
/* show_hook= */ NULL);

DefineCustomBoolVariable(/* name= */ "timescaledb.debug_compression_path_info",
/* short_desc= */ "show various compression-related debug info",
/* long_desc= */ "this is for debugging purposes",
/* valueAddr= */ &ts_guc_debug_compression_path_info,
/* bootValue= */ false,
/* context= */ PGC_USERSET,
/* flags= */ 0,
/* check_hook= */ NULL,
/* assign_hook= */ NULL,
/* show_hook= */ NULL);

DefineCustomBoolVariable(/* name= */ "timescaledb.debug_require_batch_sorted_merge",
/* short_desc= */ "require batch sorted merge in DecompressChunk node",
/* long_desc= */ "this is for debugging purposes",
Expand Down
2 changes: 2 additions & 0 deletions src/guc.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ typedef enum DebugRequireVectorQual

extern TSDLLEXPORT DebugRequireVectorQual ts_guc_debug_require_vector_qual;

extern TSDLLEXPORT bool ts_guc_debug_compression_path_info;

extern TSDLLEXPORT bool ts_guc_debug_require_batch_sorted_merge;

void _guc_init(void);
Expand Down
4 changes: 2 additions & 2 deletions tsl/src/compression/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,7 @@ tsl_recompress_chunk_segmentwise(PG_FUNCTION_ARGS)
decompressor.compressed_datums,
decompressor.compressed_is_nulls);

row_decompressor_decompress_row(&decompressor, segment_tuplesortstate);
row_decompressor_decompress_row_to_tuplesort(&decompressor, segment_tuplesortstate);

simple_table_tuple_delete(compressed_chunk_rel, &(slot->tts_tid), snapshot);

Expand Down Expand Up @@ -1529,7 +1529,7 @@ tsl_recompress_chunk_segmentwise(PG_FUNCTION_ARGS)
decompressor.compressed_datums,
decompressor.compressed_is_nulls);

row_decompressor_decompress_row(&decompressor, segment_tuplesortstate);
row_decompressor_decompress_row_to_tuplesort(&decompressor, segment_tuplesortstate);

simple_table_tuple_delete(compressed_chunk_rel, &(slot->tts_tid), snapshot);
/* because this is the first tuple of the new segment */
Expand Down
Loading

0 comments on commit e5840e3

Please sign in to comment.