diff --git a/scripts/test_updates_pg13.sh b/scripts/test_updates_pg13.sh index 998ad0ba8cc..5e83ca0dfee 100755 --- a/scripts/test_updates_pg13.sh +++ b/scripts/test_updates_pg13.sh @@ -2,6 +2,9 @@ set -e +PG_VERSION=${PG_VERSION:-13.14} +export PG_VERSION + SCRIPT_DIR=$(dirname $0) # shellcheck source=scripts/test_functions.inc diff --git a/scripts/test_updates_pg14.sh b/scripts/test_updates_pg14.sh index 03252e33427..11799a4feda 100755 --- a/scripts/test_updates_pg14.sh +++ b/scripts/test_updates_pg14.sh @@ -2,6 +2,9 @@ set -e +PG_VERSION=${PG_VERSION:-14.11} +export PG_VERSION + SCRIPT_DIR=$(dirname $0) # shellcheck source=scripts/test_functions.inc diff --git a/scripts/test_updates_pg15.sh b/scripts/test_updates_pg15.sh index 8835a7fe01e..04e14b29b1e 100755 --- a/scripts/test_updates_pg15.sh +++ b/scripts/test_updates_pg15.sh @@ -2,6 +2,9 @@ set -e +PG_VERSION=${PG_VERSION:-15.6} +export PG_VERSION + SCRIPT_DIR=$(dirname $0) # shellcheck source=scripts/test_functions.inc diff --git a/scripts/test_updates_pg16.sh b/scripts/test_updates_pg16.sh index 0f22c408f11..b38b928f347 100755 --- a/scripts/test_updates_pg16.sh +++ b/scripts/test_updates_pg16.sh @@ -1,5 +1,9 @@ #!/usr/bin/env bash +PG_VERSION=${PG_VERSION:-16.2} + +export PG_VERSION + set -e SCRIPT_DIR=$(dirname $0) diff --git a/sql/updates/2.13.1--2.14.0.sql b/sql/updates/2.13.1--2.14.0.sql index f77cd202c2d..96864ede747 100644 --- a/sql/updates/2.13.1--2.14.0.sql +++ b/sql/updates/2.13.1--2.14.0.sql @@ -105,6 +105,13 @@ INSERT INTO _timescaledb_catalog.compression_settings(relid, segmentby, orderby, INNER JOIN _timescaledb_catalog.hypertable ht ON ht.id = hc.hypertable_id GROUP BY hypertable_id, ht.schema_name, ht.table_name; +INSERT INTO _timescaledb_catalog.compression_settings +SELECT format('%I.%I',ch.schema_name,ch.table_name)::regclass,s.segmentby,s.orderby,s.orderby_desc,s.orderby_nullsfirst +FROM _timescaledb_catalog.hypertable ht1 +INNER JOIN _timescaledb_catalog.hypertable ht2 ON ht2.id = ht1.compressed_hypertable_id +INNER JOIN _timescaledb_catalog.compression_settings s ON s.relid = format('%I.%I',ht1.schema_name,ht1.table_name)::regclass +INNER JOIN _timescaledb_catalog.chunk ch ON ch.hypertable_id = ht2.id ON CONFLICT DO NOTHING; + GRANT SELECT ON _timescaledb_catalog.compression_settings TO PUBLIC; SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.compression_settings', ''); diff --git a/sql/updates/latest-dev.sql b/sql/updates/latest-dev.sql index bd64dc2ccec..febf507460d 100644 --- a/sql/updates/latest-dev.sql +++ b/sql/updates/latest-dev.sql @@ -65,3 +65,11 @@ CREATE VIEW timescaledb_information.chunk_compression_settings AS FROM unnest(s.orderby, s.orderby_desc, s.orderby_nullsfirst) un(orderby, "desc", nullsfirst) ) un ON true; +INSERT INTO _timescaledb_catalog.compression_settings +SELECT + format('%I.%I',ch.schema_name,ch.table_name)::regclass,s.segmentby,s.orderby,s.orderby_desc,s.orderby_nullsfirst +FROM _timescaledb_catalog.hypertable ht1 +INNER JOIN _timescaledb_catalog.hypertable ht2 ON ht2.id = ht1.compressed_hypertable_id +INNER JOIN _timescaledb_catalog.compression_settings s ON s.relid = format('%I.%I',ht1.schema_name,ht1.table_name)::regclass +INNER JOIN _timescaledb_catalog.chunk ch ON ch.hypertable_id = ht2.id ON CONFLICT DO NOTHING; + diff --git a/tsl/src/nodes/decompress_chunk/decompress_chunk.c b/tsl/src/nodes/decompress_chunk/decompress_chunk.c index aedc982289d..1195b9f9b81 100644 --- a/tsl/src/nodes/decompress_chunk/decompress_chunk.c +++ b/tsl/src/nodes/decompress_chunk/decompress_chunk.c @@ -266,7 +266,7 @@ copy_decompress_chunk_path(DecompressChunkPath *src) } static CompressionInfo * -build_compressioninfo(PlannerInfo *root, Hypertable *ht, RelOptInfo *chunk_rel) +build_compressioninfo(PlannerInfo *root, Hypertable *ht, Chunk *chunk, RelOptInfo *chunk_rel) { AppendRelInfo *appinfo; CompressionInfo *info = palloc0(sizeof(CompressionInfo)); @@ -276,7 +276,8 @@ build_compressioninfo(PlannerInfo *root, Hypertable *ht, RelOptInfo *chunk_rel) info->chunk_rel = chunk_rel; info->chunk_rte = planner_rt_fetch(chunk_rel->relid, root); - info->settings = ts_compression_settings_get(ht->main_table_relid); + Oid relid = ts_chunk_get_relid(chunk->fd.compressed_chunk_id, true); + info->settings = ts_compression_settings_get(relid); if (chunk_rel->reloptkind == RELOPT_OTHER_MEMBER_REL) { @@ -693,7 +694,7 @@ ts_decompress_chunk_generate_paths(PlannerInfo *root, RelOptInfo *chunk_rel, Hyp double new_row_estimate; Index ht_relid = 0; - CompressionInfo *compression_info = build_compressioninfo(root, ht, chunk_rel); + CompressionInfo *compression_info = build_compressioninfo(root, ht, chunk, chunk_rel); /* double check we don't end up here on single chunk queries with ONLY */ Assert(compression_info->chunk_rel->reloptkind == RELOPT_OTHER_MEMBER_REL || diff --git a/tsl/test/expected/compression_settings.out b/tsl/test/expected/compression_settings.out index 4fe1f4a9d5f..0a823f3d499 100644 --- a/tsl/test/expected/compression_settings.out +++ b/tsl/test/expected/compression_settings.out @@ -344,3 +344,25 @@ SELECT * FROM ht_settings; metrics2 | | d1 DESC NULLS LAST,d2 NULLS FIRST,value DESC,"time" NULLS FIRST | (2 rows) +-- test decompression uses the correct settings +ALTER TABLE metrics SET (timescaledb.compress_segmentby=''); +SELECT compress_chunk(show_chunks('metrics'), recompress:=true); + compress_chunk +---------------------------------------- + _timescaledb_internal._hyper_3_6_chunk + _timescaledb_internal._hyper_3_8_chunk +(2 rows) + +ALTER TABLE metrics SET (timescaledb.compress_segmentby='d1,d2'); +SELECT * FROM chunk_settings; + hypertable | chunk | segmentby | orderby +------------+----------------------------------------+-----------+------------- + metrics | _timescaledb_internal._hyper_3_6_chunk | | "time" DESC + metrics | _timescaledb_internal._hyper_3_8_chunk | | "time" DESC +(2 rows) + +SELECT * FROM metrics WHERE d1 = 'foo'; + time | d1 | d2 | value +------+----+----+------- +(0 rows) + diff --git a/tsl/test/sql/compression_settings.sql b/tsl/test/sql/compression_settings.sql index c646ef86422..977bc8cfcc5 100644 --- a/tsl/test/sql/compression_settings.sql +++ b/tsl/test/sql/compression_settings.sql @@ -112,4 +112,11 @@ SELECT * FROM ht_settings; ALTER TABLE metrics2 SET (timescaledb.compress_orderby='d1 DESC NULLS LAST, d2 ASC NULLS FIRST, value DESC, time ASC NULLS FIRST'); SELECT * FROM ht_settings; +-- test decompression uses the correct settings +ALTER TABLE metrics SET (timescaledb.compress_segmentby=''); +SELECT compress_chunk(show_chunks('metrics'), recompress:=true); +ALTER TABLE metrics SET (timescaledb.compress_segmentby='d1,d2'); +SELECT * FROM chunk_settings; + +SELECT * FROM metrics WHERE d1 = 'foo';