Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DecompressChunk path generation with per chunk settings #6651

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions scripts/test_updates_pg13.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions scripts/test_updates_pg14.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions scripts/test_updates_pg15.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions scripts/test_updates_pg16.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bash

PG_VERSION=${PG_VERSION:-16.2}

export PG_VERSION

set -e

SCRIPT_DIR=$(dirname $0)
Expand Down
7 changes: 7 additions & 0 deletions sql/updates/2.13.1--2.14.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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', '');

Expand Down
8 changes: 8 additions & 0 deletions sql/updates/latest-dev.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;

7 changes: 4 additions & 3 deletions tsl/src/nodes/decompress_chunk/decompress_chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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)
{
Expand Down Expand Up @@ -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 ||
Expand Down
22 changes: 22 additions & 0 deletions tsl/test/expected/compression_settings.out
Original file line number Diff line number Diff line change
Expand Up @@ -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)

7 changes: 7 additions & 0 deletions tsl/test/sql/compression_settings.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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';