diff --git a/.unreleased/pr_10340 b/.unreleased/pr_10340 new file mode 100644 index 00000000000..97f0ad3c0f0 --- /dev/null +++ b/.unreleased/pr_10340 @@ -0,0 +1 @@ +Fixes: #10340 Validate max_batches in compact_chunk diff --git a/tsl/src/compression/recompress.c b/tsl/src/compression/recompress.c index 6ac66d39b01..96bae00f505 100644 --- a/tsl/src/compression/recompress.c +++ b/tsl/src/compression/recompress.c @@ -289,7 +289,12 @@ tsl_compact_chunk(PG_FUNCTION_ARGS) } int max_batches = PG_GETARG_INT32(1); - Assert(max_batches >= 0); + if (max_batches < 0) + { + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("max_batches must be greater than or equal to 0"))); + } uncompressed_relid = compact_chunk_impl(chunk, max_batches); diff --git a/tsl/test/expected/compact_chunk.out b/tsl/test/expected/compact_chunk.out index e1881667316..b7fbd0e6606 100644 --- a/tsl/test/expected/compact_chunk.out +++ b/tsl/test/expected/compact_chunk.out @@ -115,6 +115,11 @@ SELECT DISTINCT _timescaledb_functions.chunk_status_text(chunk) FROM show_chunks ------------------- {COMPRESSED} +-- compact_chunk with negative max_batches must fail +\set ON_ERROR_STOP 0 +SELECT _timescaledb_functions.compact_chunk(chunk, -1) FROM show_chunks('metrics') chunk; +ERROR: max_batches must be greater than or equal to 0 +\set ON_ERROR_STOP 1 -- compact an uncompressed chunk -- Create a new uncompressed chunk for a different time range by -- inserting with direct compress insert disabled. diff --git a/tsl/test/sql/compact_chunk.sql b/tsl/test/sql/compact_chunk.sql index 57e5463d1e2..54f806c44d7 100644 --- a/tsl/test/sql/compact_chunk.sql +++ b/tsl/test/sql/compact_chunk.sql @@ -76,6 +76,11 @@ ORDER BY _ts_meta_min_1; -- Status should not contain UNORDERED flag SELECT DISTINCT _timescaledb_functions.chunk_status_text(chunk) FROM show_chunks('metrics') chunk; +-- compact_chunk with negative max_batches must fail +\set ON_ERROR_STOP 0 +SELECT _timescaledb_functions.compact_chunk(chunk, -1) FROM show_chunks('metrics') chunk; +\set ON_ERROR_STOP 1 + -- compact an uncompressed chunk -- Create a new uncompressed chunk for a different time range by -- inserting with direct compress insert disabled.