Skip to content

Commit 224376b

Browse files
Fix recompress segmentwise when order by is empty, avoid test recaps
1 parent 05a6625 commit 224376b

10 files changed

+21
-13
lines changed

.unreleased/pr_7789

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Implements: #7789 Do not recompress segmentwise when default order by is empty
2+
Fixes: #7748 Crash in the segmentwise recompression

tsl/src/compression/create.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,10 +1143,10 @@ compression_setting_orderby_get_default(Hypertable *ht, ArrayType *segmentby)
11431143
orderby = "";
11441144

11451145
if (*orderby == '\0')
1146-
elog(NOTICE,
1147-
"default order by for hypertable \"%s\" is empty, segmentwise recompression will be "
1148-
"disabled",
1149-
get_rel_name(ht->main_table_relid));
1146+
ereport(NOTICE,
1147+
(errmsg("default order by for hypertable \"%s\" is set to \"\"",
1148+
get_rel_name(ht->main_table_relid))),
1149+
errdetail("Segmentwise recompression will be disabled"));
11501150
else
11511151
elog(NOTICE,
11521152
"default order by for hypertable \"%s\" is set to \"%s\"",

tsl/src/compression/recompress.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "compression.h"
1919
#include "compression_dml.h"
2020
#include "create.h"
21+
#include "debug_assert.h"
2122
#include "guc.h"
2223
#include "hypercore/hypercore_handler.h"
2324
#include "hypercore/utils.h"
@@ -123,7 +124,7 @@ recompress_chunk_segmentwise_impl(Chunk *uncompressed_chunk)
123124

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

128129
/* new status after recompress should simply be compressed (1)
129130
* It is ok to update this early on in the transaction as it keeps a lock

tsl/test/expected/compression.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,10 +1147,10 @@ SELECT create_hypertable('table1','col1', chunk_time_interval => 10);
11471147

11481148
-- Trying to list an incomplete set of fields of the compound key
11491149
ALTER TABLE table1 SET (timescaledb.compress, timescaledb.compress_segmentby = 'col1');
1150-
NOTICE: default order by for hypertable "table1" is empty, segmentwise recompression will be disabled
1150+
NOTICE: default order by for hypertable "table1" is set to ""
11511151
-- Listing all fields of the compound key should succeed:
11521152
ALTER TABLE table1 SET (timescaledb.compress, timescaledb.compress_segmentby = 'col1,col2');
1153-
NOTICE: default order by for hypertable "table1" is empty, segmentwise recompression will be disabled
1153+
NOTICE: default order by for hypertable "table1" is set to ""
11541154
SELECT * FROM timescaledb_information.compression_settings ORDER BY hypertable_name;
11551155
hypertable_schema | hypertable_name | attname | segmentby_column_index | orderby_column_index | orderby_asc | orderby_nullsfirst
11561156
-------------------+-----------------+-------------+------------------------+----------------------+-------------+--------------------

tsl/test/expected/compression_defaults.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ SELECT _timescaledb_functions.get_orderby_defaults('table1', ARRAY['col1']::text
374374
(1 row)
375375

376376
ALTER TABLE table1 SET (timescaledb.compress, timescaledb.compress_segmentby = 'col1');
377-
NOTICE: default order by for hypertable "table1" is empty, segmentwise recompression will be disabled
377+
NOTICE: default order by for hypertable "table1" is set to ""
378378
SELECT * FROM _timescaledb_catalog.compression_settings;
379379
relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst
380380
--------+----------------+-----------+---------+--------------+--------------------

tsl/test/expected/compression_errors-17.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ ALTER TABLE table_unique_index SET (timescaledb.compress = off);
876876
ALTER TABLE table_unique_index SET (timescaledb.compress, timescaledb.compress_segmentby = 'time,location', timescaledb.compress_orderby = 'device_id');
877877
ALTER TABLE table_unique_index SET (timescaledb.compress = off);
878878
ALTER TABLE table_unique_index SET (timescaledb.compress, timescaledb.compress_segmentby = 'time,location,device_id');
879-
NOTICE: default order by for hypertable "table_unique_index" is empty, segmentwise recompression will be disabled
879+
NOTICE: default order by for hypertable "table_unique_index" is set to ""
880880
ALTER TABLE table_unique_index SET (timescaledb.compress = off);
881881
-- try compressing osm chunk
882882
CREATE TABLE osm_table (time timestamptz NOT NULL, device_id text, value float);

tsl/test/expected/compression_fks.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ NOTICE: adding not-null constraint to column "time"
1313

1414
ALTER TABLE ht_with_fk ADD CONSTRAINT keys FOREIGN KEY (time) REFERENCES keys(time) ON DELETE CASCADE;
1515
ALTER TABLE ht_with_fk SET (timescaledb.compress,timescaledb.compress_segmentby='time');
16-
NOTICE: default order by for hypertable "ht_with_fk" is empty, segmentwise recompression will be disabled
16+
NOTICE: default order by for hypertable "ht_with_fk" is set to ""
1717
-- no keys added yet so any insert into ht_with_fk should fail
1818
\set ON_ERROR_STOP 0
1919
INSERT INTO ht_with_fk SELECT '2000-01-01';

tsl/test/expected/compression_update_delete-17.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ SELECT * FROM create_hypertable('sample_table', 'time', chunk_time_interval => 1
464464
ALTER TABLE sample_table SET (
465465
timescaledb.compress,
466466
timescaledb.compress_segmentby = 'time, val');
467-
NOTICE: default order by for hypertable "sample_table" is empty, segmentwise recompression will be disabled
467+
NOTICE: default order by for hypertable "sample_table" is set to ""
468468
INSERT INTO sample_table VALUES (1, 1, 1), (2, 2, 1), (3, 3, 1), (1, 3, 2), (11, 4, 2), (1, 1, 2);
469469
-- compress all chunks
470470
SELECT compress_chunk(show_chunks('sample_table'));
@@ -588,7 +588,7 @@ INSERT INTO sample_table VALUES ('2017-03-22T09:18:22', 23.5, 1, '{"a": 1, "b":
588588
('2017-08-22T09:18:22', 34.1, 3, '{"c": 4}');
589589
ALTER TABLE sample_table SET (timescaledb.compress,
590590
timescaledb.compress_segmentby = 'time');
591-
NOTICE: default order by for hypertable "sample_table" is empty, segmentwise recompression will be disabled
591+
NOTICE: default order by for hypertable "sample_table" is set to ""
592592
SELECT compress_chunk(show_chunks('sample_table'));
593593
compress_chunk
594594
-----------------------------------------

tsl/test/expected/recompress_chunk_segmentwise.out

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,8 +656,11 @@ NOTICE: adding not-null constraint to column "ts"
656656
(20,public,no_oby,t)
657657
(1 row)
658658

659+
\set VERBOSITY default
659660
ALTER TABLE no_oby SET (timescaledb.compress, timescaledb.compress_segmentby = 'ts');
660-
NOTICE: default order by for hypertable "no_oby" is empty, segmentwise recompression will be disabled
661+
NOTICE: default order by for hypertable "no_oby" is set to ""
662+
DETAIL: Segmentwise recompression will be disabled
663+
\set VERBOSITY terse
661664
INSERT INTO no_oby (ts,c1) VALUES (6,6);
662665
SELECT show_chunks as chunk_to_compress FROM show_chunks('no_oby') LIMIT 1 \gset
663666
SELECT compress_chunk(:'chunk_to_compress');

tsl/test/sql/recompress_chunk_segmentwise.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,9 @@ SELECT compress_chunk(:'chunk_to_compress');
310310
-- Test behaviour when default order by is empty: should not segmentwise-recompress in this case
311311
CREATE TABLE no_oby(ts int, c1 int);
312312
SELECT create_hypertable('no_oby','ts');
313+
\set VERBOSITY default
313314
ALTER TABLE no_oby SET (timescaledb.compress, timescaledb.compress_segmentby = 'ts');
315+
\set VERBOSITY terse
314316

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

0 commit comments

Comments
 (0)