Skip to content

Commit

Permalink
Fix recompress segmentwise when order by is empty, avoid test recaps
Browse files Browse the repository at this point in the history
  • Loading branch information
natalya-aksman committed Mar 4, 2025
1 parent 05a6625 commit 224376b
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .unreleased/pr_7789
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Implements: #7789 Do not recompress segmentwise when default order by is empty
Fixes: #7748 Crash in the segmentwise recompression
8 changes: 4 additions & 4 deletions tsl/src/compression/create.c
Original file line number Diff line number Diff line change
Expand Up @@ -1143,10 +1143,10 @@ compression_setting_orderby_get_default(Hypertable *ht, ArrayType *segmentby)
orderby = "";

if (*orderby == '\0')
elog(NOTICE,
"default order by for hypertable \"%s\" is empty, segmentwise recompression will be "
"disabled",
get_rel_name(ht->main_table_relid));
ereport(NOTICE,
(errmsg("default order by for hypertable \"%s\" is set to \"\"",
get_rel_name(ht->main_table_relid))),
errdetail("Segmentwise recompression will be disabled"));
else
elog(NOTICE,
"default order by for hypertable \"%s\" is set to \"%s\"",
Expand Down
3 changes: 2 additions & 1 deletion tsl/src/compression/recompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "compression.h"
#include "compression_dml.h"
#include "create.h"
#include "debug_assert.h"
#include "guc.h"
#include "hypercore/hypercore_handler.h"
#include "hypercore/utils.h"
Expand Down Expand Up @@ -123,7 +124,7 @@ recompress_chunk_segmentwise_impl(Chunk *uncompressed_chunk)

/* We should not do segment-wise recompression with empty orderby, see #7748
*/
Assert(settings->fd.orderby);
Ensure(settings->fd.orderby, "empty order by, cannot recompress segmentwise");

/* new status after recompress should simply be compressed (1)
* It is ok to update this early on in the transaction as it keeps a lock
Expand Down
4 changes: 2 additions & 2 deletions tsl/test/expected/compression.out
Original file line number Diff line number Diff line change
Expand Up @@ -1147,10 +1147,10 @@ SELECT create_hypertable('table1','col1', chunk_time_interval => 10);

-- Trying to list an incomplete set of fields of the compound key
ALTER TABLE table1 SET (timescaledb.compress, timescaledb.compress_segmentby = 'col1');
NOTICE: default order by for hypertable "table1" is empty, segmentwise recompression will be disabled
NOTICE: default order by for hypertable "table1" is set to ""
-- Listing all fields of the compound key should succeed:
ALTER TABLE table1 SET (timescaledb.compress, timescaledb.compress_segmentby = 'col1,col2');
NOTICE: default order by for hypertable "table1" is empty, segmentwise recompression will be disabled
NOTICE: default order by for hypertable "table1" is set to ""
SELECT * FROM timescaledb_information.compression_settings ORDER BY hypertable_name;
hypertable_schema | hypertable_name | attname | segmentby_column_index | orderby_column_index | orderby_asc | orderby_nullsfirst
-------------------+-----------------+-------------+------------------------+----------------------+-------------+--------------------
Expand Down
2 changes: 1 addition & 1 deletion tsl/test/expected/compression_defaults.out
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ SELECT _timescaledb_functions.get_orderby_defaults('table1', ARRAY['col1']::text
(1 row)

ALTER TABLE table1 SET (timescaledb.compress, timescaledb.compress_segmentby = 'col1');
NOTICE: default order by for hypertable "table1" is empty, segmentwise recompression will be disabled
NOTICE: default order by for hypertable "table1" is set to ""
SELECT * FROM _timescaledb_catalog.compression_settings;
relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst
--------+----------------+-----------+---------+--------------+--------------------
Expand Down
2 changes: 1 addition & 1 deletion tsl/test/expected/compression_errors-17.out
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ ALTER TABLE table_unique_index SET (timescaledb.compress = off);
ALTER TABLE table_unique_index SET (timescaledb.compress, timescaledb.compress_segmentby = 'time,location', timescaledb.compress_orderby = 'device_id');
ALTER TABLE table_unique_index SET (timescaledb.compress = off);
ALTER TABLE table_unique_index SET (timescaledb.compress, timescaledb.compress_segmentby = 'time,location,device_id');
NOTICE: default order by for hypertable "table_unique_index" is empty, segmentwise recompression will be disabled
NOTICE: default order by for hypertable "table_unique_index" is set to ""
ALTER TABLE table_unique_index SET (timescaledb.compress = off);
-- try compressing osm chunk
CREATE TABLE osm_table (time timestamptz NOT NULL, device_id text, value float);
Expand Down
2 changes: 1 addition & 1 deletion tsl/test/expected/compression_fks.out
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ NOTICE: adding not-null constraint to column "time"

ALTER TABLE ht_with_fk ADD CONSTRAINT keys FOREIGN KEY (time) REFERENCES keys(time) ON DELETE CASCADE;
ALTER TABLE ht_with_fk SET (timescaledb.compress,timescaledb.compress_segmentby='time');
NOTICE: default order by for hypertable "ht_with_fk" is empty, segmentwise recompression will be disabled
NOTICE: default order by for hypertable "ht_with_fk" is set to ""
-- no keys added yet so any insert into ht_with_fk should fail
\set ON_ERROR_STOP 0
INSERT INTO ht_with_fk SELECT '2000-01-01';
Expand Down
4 changes: 2 additions & 2 deletions tsl/test/expected/compression_update_delete-17.out
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ SELECT * FROM create_hypertable('sample_table', 'time', chunk_time_interval => 1
ALTER TABLE sample_table SET (
timescaledb.compress,
timescaledb.compress_segmentby = 'time, val');
NOTICE: default order by for hypertable "sample_table" is empty, segmentwise recompression will be disabled
NOTICE: default order by for hypertable "sample_table" is set to ""
INSERT INTO sample_table VALUES (1, 1, 1), (2, 2, 1), (3, 3, 1), (1, 3, 2), (11, 4, 2), (1, 1, 2);
-- compress all chunks
SELECT compress_chunk(show_chunks('sample_table'));
Expand Down Expand Up @@ -588,7 +588,7 @@ INSERT INTO sample_table VALUES ('2017-03-22T09:18:22', 23.5, 1, '{"a": 1, "b":
('2017-08-22T09:18:22', 34.1, 3, '{"c": 4}');
ALTER TABLE sample_table SET (timescaledb.compress,
timescaledb.compress_segmentby = 'time');
NOTICE: default order by for hypertable "sample_table" is empty, segmentwise recompression will be disabled
NOTICE: default order by for hypertable "sample_table" is set to ""
SELECT compress_chunk(show_chunks('sample_table'));
compress_chunk
-----------------------------------------
Expand Down
5 changes: 4 additions & 1 deletion tsl/test/expected/recompress_chunk_segmentwise.out
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,11 @@ NOTICE: adding not-null constraint to column "ts"
(20,public,no_oby,t)
(1 row)

\set VERBOSITY default
ALTER TABLE no_oby SET (timescaledb.compress, timescaledb.compress_segmentby = 'ts');
NOTICE: default order by for hypertable "no_oby" is empty, segmentwise recompression will be disabled
NOTICE: default order by for hypertable "no_oby" is set to ""
DETAIL: Segmentwise recompression will be disabled
\set VERBOSITY terse
INSERT INTO no_oby (ts,c1) VALUES (6,6);
SELECT show_chunks as chunk_to_compress FROM show_chunks('no_oby') LIMIT 1 \gset
SELECT compress_chunk(:'chunk_to_compress');
Expand Down
2 changes: 2 additions & 0 deletions tsl/test/sql/recompress_chunk_segmentwise.sql
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,9 @@ SELECT compress_chunk(:'chunk_to_compress');
-- Test behaviour when default order by is empty: should not segmentwise-recompress in this case
CREATE TABLE no_oby(ts int, c1 int);
SELECT create_hypertable('no_oby','ts');
\set VERBOSITY default
ALTER TABLE no_oby SET (timescaledb.compress, timescaledb.compress_segmentby = 'ts');
\set VERBOSITY terse

INSERT INTO no_oby (ts,c1) VALUES (6,6);
SELECT show_chunks as chunk_to_compress FROM show_chunks('no_oby') LIMIT 1 \gset
Expand Down

0 comments on commit 224376b

Please sign in to comment.