mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-19 20:24:46 +08:00
Fix DecompressChunk path generation with per chunk settings
Adjust DecompressChunk path generation to use the per chunk settings and not the hypertable settings when building compression info. This patch also fixes the missing chunk configuration generation in the update script which was masked by this bug.
This commit is contained in:
parent
a4bd6f171b
commit
fc0e41cc13
scripts
sql/updates
tsl
src/nodes/decompress_chunk
test
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -1,5 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
PG_VERSION=${PG_VERSION:-16.2}
|
||||
|
||||
export PG_VERSION
|
||||
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR=$(dirname $0)
|
||||
|
@ -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', '');
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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 ||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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';
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user