Skip to content

Commit

Permalink
Add warning for poor compression ratio
Browse files Browse the repository at this point in the history
Adds functionality to emit a warning to the user when the compression
ratio is "bad".

Currently, "bad" is defined to be when size after compression is higher
than after compression.
  • Loading branch information
kpan2034 committed Mar 4, 2025
1 parent 4ebfedf commit 1889c9b
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions .unreleased/pr_7756
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implements: #7756 Add warning for poor compression ratio
11 changes: 11 additions & 0 deletions src/guc.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ TSDLLEXPORT bool ts_guc_default_hypercore_use_access_method = false;
bool ts_guc_enable_chunk_skipping = false;
TSDLLEXPORT bool ts_guc_enable_segmentwise_recompression = true;
TSDLLEXPORT bool ts_guc_enable_bool_compression = false;
TSDLLEXPORT bool ts_guc_enable_compression_ratio_warnings = true;

/* Enable of disable columnar scans for columnar-oriented storage engines. If
* disabled, regular sequence scans will be used instead. */
Expand Down Expand Up @@ -761,6 +762,16 @@ _guc_init(void)
NULL,
NULL);

DefineCustomBoolVariable(MAKE_EXTOPTION("enable_compression_ratio_warnings"),
"Enable warnings for poor compression ratio",
"Enable warnings for poor compression ratio",
&ts_guc_enable_compression_ratio_warnings,
true,
PGC_USERSET,
0,
NULL,
NULL,
NULL);
/*
* Define the limit on number of invalidation-based refreshes we allow per
* refresh call. If this limit is exceeded, fall back to a single refresh that
Expand Down
1 change: 1 addition & 0 deletions src/guc.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ extern TSDLLEXPORT bool ts_guc_enable_merge_on_cagg_refresh;
extern bool ts_guc_enable_chunk_skipping;
extern TSDLLEXPORT bool ts_guc_enable_segmentwise_recompression;
extern TSDLLEXPORT bool ts_guc_enable_bool_compression;
extern TSDLLEXPORT bool ts_guc_enable_compression_ratio_warnings;

#ifdef USE_TELEMETRY
typedef enum TelemetryLevel
Expand Down
1 change: 1 addition & 0 deletions test/postgresql.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ extra_float_digits=0
@TELEMETRY_DEFAULT_SETTING@

timescaledb.license='apache'
timescaledb.enable_compression_ratio_warnings=false
11 changes: 11 additions & 0 deletions tsl/src/compression/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,17 @@ compress_chunk_impl(Oid hypertable_relid, Oid chunk_relid)
*/
ts_chunk_constraints_create(cxt.compress_ht, compress_ht_chunk);
ts_trigger_create_all_on_chunk(compress_ht_chunk);

/* Detect and emit warning if poor compression ratio is found */
float compression_ratio = ((float) before_size.total_size / after_size.total_size);
float POOR_COMPRESSION_THRESHOLD = 1.0;
elog(ts_guc_enable_compression_ratio_warnings &&
compression_ratio < POOR_COMPRESSION_THRESHOLD ?
WARNING :
DEBUG1,
"size before compression: %ld bytes, size after compression: %ld bytes",
before_size.total_size,
after_size.total_size);
}
else
{
Expand Down
1 change: 1 addition & 0 deletions tsl/test/postgresql.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ log_statement='all'
# It is necessary to have at least 2 more workers than `max_worker_processes`
# in order to test failures starting bgworkers.
timescaledb.max_background_workers=26
timescaledb.enable_compression_ratio_warnings=false

0 comments on commit 1889c9b

Please sign in to comment.