From b9df9ea24b7697d9cfabf2a7fadb4c788eac0d5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Nordstr=C3=B6m?= Date: Mon, 6 May 2024 11:26:23 +0200 Subject: [PATCH] Add table mappings to compression settings Refactor the compression settings metadata table to include a mapping from a chunk's relid to its compressed chunk's relid. Adding this mapping makes compression settings the main metadata table for compression-related information, while decoupling it from chunk metadata. This simplifies the code that looks up compression metadata as it no longer requires first looking up the corresponding compressed chunk. The new compression settings is a step towards removing a chunk's compression table from the chunk metadata. In other words, the "compressed chunk" will no longer be a chunk, just a relation associated with the regular chunk via compression settings. --- sql/pre_install/tables.sql | 4 +- sql/updates/latest-dev.sql | 55 ++++++++ sql/updates/reverse-dev.sql | 47 +++++++ sql/views.sql | 3 +- src/chunk.c | 4 +- src/dimension.c | 1 + src/process_utility.c | 6 +- src/ts_catalog/catalog.c | 1 + src/ts_catalog/catalog.h | 12 ++ src/ts_catalog/compression_settings.c | 130 +++++++++++------ src/ts_catalog/compression_settings.h | 15 +- src/ts_catalog/continuous_agg.h | 1 + tsl/src/compression/api.c | 16 +-- tsl/src/compression/compression.c | 132 +++++++++--------- tsl/src/compression/compression.h | 13 +- tsl/src/compression/create.c | 17 ++- tsl/src/compression/create.h | 2 +- tsl/src/continuous_aggs/materialize.c | 1 + tsl/src/continuous_aggs/refresh.c | 1 + .../nodes/decompress_chunk/decompress_chunk.c | 4 +- tsl/test/expected/cagg_ddl-14.out | 4 +- tsl/test/expected/cagg_ddl-15.out | 4 +- tsl/test/expected/cagg_ddl-16.out | 4 +- tsl/test/expected/compression.out | 18 +-- tsl/test/expected/compression_ddl.out | 36 ++--- tsl/test/expected/compression_defaults.out | 42 +++--- tsl/test/expected/compression_errors-14.out | 20 +-- tsl/test/expected/compression_errors-15.out | 20 +-- tsl/test/expected/compression_errors-16.out | 20 +-- tsl/test/expected/compression_settings.out | 112 +++++++-------- tsl/test/t/002_logrepl_decomp_marker.pl | 6 +- 31 files changed, 460 insertions(+), 291 deletions(-) diff --git a/sql/pre_install/tables.sql b/sql/pre_install/tables.sql index 08a315bcd95..40beb7ecd18 100644 --- a/sql/pre_install/tables.sql +++ b/sql/pre_install/tables.sql @@ -431,7 +431,8 @@ CREATE TABLE _timescaledb_catalog.compression_algorithm ( ); CREATE TABLE _timescaledb_catalog.compression_settings ( - relid regclass NOT NULL, + relid regclass NOT NULL, + compress_relid regclass NULL, segmentby text[], orderby text[], orderby_desc bool[], @@ -443,6 +444,7 @@ CREATE TABLE _timescaledb_catalog.compression_settings ( ); SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.compression_settings', ''); +CREATE INDEX compression_settings_compress_relid_idx ON _timescaledb_catalog.compression_settings (compress_relid); CREATE TABLE _timescaledb_catalog.compression_chunk_size ( chunk_id integer NOT NULL, diff --git a/sql/updates/latest-dev.sql b/sql/updates/latest-dev.sql index e69de29bb2d..9a0afe32cfa 100644 --- a/sql/updates/latest-dev.sql +++ b/sql/updates/latest-dev.sql @@ -0,0 +1,55 @@ +-- Update compression settings + +CREATE TABLE _timescaledb_catalog.tempsettings (LIKE _timescaledb_catalog.compression_settings); +INSERT INTO _timescaledb_catalog.tempsettings SELECT * FROM _timescaledb_catalog.compression_settings; +ALTER EXTENSION timescaledb DROP TABLE _timescaledb_catalog.compression_settings; +DROP TABLE _timescaledb_catalog.compression_settings CASCADE; + +CREATE TABLE _timescaledb_catalog.compression_settings ( + relid regclass NOT NULL, + compress_relid regclass NULL, + segmentby text[], + orderby text[], + orderby_desc bool[], + orderby_nullsfirst bool[], + CONSTRAINT compression_settings_pkey PRIMARY KEY (relid), + CONSTRAINT compression_settings_check_segmentby CHECK (array_ndims(segmentby) = 1), + CONSTRAINT compression_settings_check_orderby_null CHECK ((orderby IS NULL AND orderby_desc IS NULL AND orderby_nullsfirst IS NULL) OR (orderby IS NOT NULL AND orderby_desc IS NOT NULL AND orderby_nullsfirst IS NOT NULL)), + CONSTRAINT compression_settings_check_orderby_cardinality CHECK (array_ndims(orderby) = 1 AND array_ndims(orderby_desc) = 1 AND array_ndims(orderby_nullsfirst) = 1 AND cardinality(orderby) = cardinality(orderby_desc) AND cardinality(orderby) = cardinality(orderby_nullsfirst)) +); + +-- Insert hypertable settings +INSERT INTO _timescaledb_catalog.compression_settings +SELECT + cs.relid, + NULL, + cs.segmentby, + cs.orderby, + cs.orderby_desc, + cs.orderby_nullsfirst +FROM + _timescaledb_catalog.tempsettings cs +INNER JOIN + _timescaledb_catalog.hypertable h ON (cs.relid = format('%I.%I', h.schema_name, h.table_name)::regclass); + +-- Insert chunk settings +INSERT INTO _timescaledb_catalog.compression_settings +SELECT + format('%I.%I', ch2.schema_name, ch2.table_name)::regclass AS relid, + cs.relid AS compress_relid, + cs.segmentby, + cs.orderby, + cs.orderby_desc, + cs.orderby_nullsfirst +FROM + _timescaledb_catalog.tempsettings cs +INNER JOIN + _timescaledb_catalog.chunk ch ON (cs.relid = format('%I.%I', ch.schema_name, ch.table_name)::regclass) +INNER JOIN + _timescaledb_catalog.chunk ch2 ON (ch.id = ch2.compressed_chunk_id); + +CREATE INDEX compression_settings_compress_relid_idx ON _timescaledb_catalog.compression_settings (compress_relid); + +DROP TABLE _timescaledb_catalog.tempsettings CASCADE; +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/reverse-dev.sql b/sql/updates/reverse-dev.sql index e69de29bb2d..0c32d651981 100644 --- a/sql/updates/reverse-dev.sql +++ b/sql/updates/reverse-dev.sql @@ -0,0 +1,47 @@ +-- Update compression settings +CREATE TABLE _timescaledb_catalog.tempsettings (LIKE _timescaledb_catalog.compression_settings); +INSERT INTO _timescaledb_catalog.tempsettings SELECT * FROM _timescaledb_catalog.compression_settings; +ALTER EXTENSION timescaledb DROP TABLE _timescaledb_catalog.compression_settings; +DROP TABLE _timescaledb_catalog.compression_settings CASCADE; + +CREATE TABLE _timescaledb_catalog.compression_settings ( + relid regclass NOT NULL, + segmentby text[], + orderby text[], + orderby_desc bool[], + orderby_nullsfirst bool[], + CONSTRAINT compression_settings_pkey PRIMARY KEY (relid), + CONSTRAINT compression_settings_check_segmentby CHECK (array_ndims(segmentby) = 1), + CONSTRAINT compression_settings_check_orderby_null CHECK ((orderby IS NULL AND orderby_desc IS NULL AND orderby_nullsfirst IS NULL) OR (orderby IS NOT NULL AND orderby_desc IS NOT NULL AND orderby_nullsfirst IS NOT NULL)), + CONSTRAINT compression_settings_check_orderby_cardinality CHECK (array_ndims(orderby) = 1 AND array_ndims(orderby_desc) = 1 AND array_ndims(orderby_nullsfirst) = 1 AND cardinality(orderby) = cardinality(orderby_desc) AND cardinality(orderby) = cardinality(orderby_nullsfirst)) +); + +-- Insert hypertable settings +INSERT INTO _timescaledb_catalog.compression_settings +SELECT + cs.compress_relid, + cs.segmentby, + cs.orderby, + cs.orderby_desc, + cs.orderby_nullsfirst +FROM + _timescaledb_catalog.tempsettings cs +WHERE + cs.compress_relid IS NOT NULL; + +-- Insert chunk settings +INSERT INTO _timescaledb_catalog.compression_settings +SELECT + cs.relid, + cs.segmentby, + cs.orderby, + cs.orderby_desc, + cs.orderby_nullsfirst +FROM + _timescaledb_catalog.tempsettings cs +WHERE + cs.compress_relid IS NULL; + +DROP TABLE _timescaledb_catalog.tempsettings CASCADE; +GRANT SELECT ON _timescaledb_catalog.compression_settings TO PUBLIC; +SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.compression_settings', ''); diff --git a/sql/views.sql b/sql/views.sql index d771e624ead..8c124c00ca4 100644 --- a/sql/views.sql +++ b/sql/views.sql @@ -390,8 +390,7 @@ CREATE OR REPLACE VIEW timescaledb_information.chunk_compression_settings AS un.orderby FROM _timescaledb_catalog.hypertable ht INNER JOIN _timescaledb_catalog.chunk ch ON ch.hypertable_id = ht.id - INNER JOIN _timescaledb_catalog.chunk ch2 ON ch2.id = ch.compressed_chunk_id - LEFT JOIN _timescaledb_catalog.compression_settings s ON format('%I.%I',ch2.schema_name,ch2.table_name)::regclass = s.relid + INNER JOIN _timescaledb_catalog.compression_settings s ON (format('%I.%I',ch.schema_name,ch.table_name)::regclass = s.relid AND format('%I.%I',ch.schema_name,ch.table_name)::regclass != s.compress_relid) LEFT JOIN LATERAL ( SELECT string_agg( diff --git a/src/chunk.c b/src/chunk.c index cf2a8a14e41..a1bc32844a0 100644 --- a/src/chunk.c +++ b/src/chunk.c @@ -2865,13 +2865,13 @@ chunk_tuple_delete(TupleInfo *ti, DropBehavior behavior, bool preserve_chunk_cat { Chunk *compressed_chunk = ts_chunk_get_by_id(form.compressed_chunk_id, false); - /* The chunk may have been delete by a CASCADE */ + /* The chunk may have been deleted by a CASCADE */ if (compressed_chunk != NULL) { /* Plain drop without preserving catalog row because this is the compressed * chunk */ - ts_compression_settings_delete(compressed_chunk->table_id); ts_chunk_drop(compressed_chunk, behavior, DEBUG1); + ts_compression_settings_delete_by_compress_relid(compressed_chunk->table_id); } } diff --git a/src/dimension.c b/src/dimension.c index f6684b4c5f4..e9fe54cdc4e 100644 --- a/src/dimension.c +++ b/src/dimension.c @@ -18,6 +18,7 @@ #include #include "compat/compat.h" +#include "chunk.h" #include "cross_module_fn.h" #include "debug_point.h" #include "dimension.h" diff --git a/src/process_utility.c b/src/process_utility.c index 6855daea337..9e68ef41383 100644 --- a/src/process_utility.c +++ b/src/process_utility.c @@ -1916,7 +1916,9 @@ process_rename_column(ProcessUtilityArgs *args, Cache *hcache, Oid relid, Rename * we don't do anything. */ if (ht) { - ts_compression_settings_rename_column_hypertable(ht, stmt->subname, stmt->newname); + ts_compression_settings_rename_column_recurse(ht->main_table_relid, + stmt->subname, + stmt->newname); add_hypertable_to_process_args(args, ht); dim = ts_hyperspace_get_mutable_dimension_by_name(ht->space, DIMENSION_TYPE_ANY, @@ -4276,8 +4278,8 @@ process_drop_table(EventTriggerDropObject *obj) Assert(obj->type == EVENT_TRIGGER_DROP_TABLE || obj->type == EVENT_TRIGGER_DROP_FOREIGN_TABLE); ts_hypertable_delete_by_name(table->schema, table->name); - ts_chunk_delete_by_name(table->schema, table->name, DROP_RESTRICT); ts_compression_settings_delete(table->relid); + ts_chunk_delete_by_name(table->schema, table->name, DROP_RESTRICT); } static void diff --git a/src/ts_catalog/catalog.c b/src/ts_catalog/catalog.c index 312d0f30856..a98a7ea5f6d 100644 --- a/src/ts_catalog/catalog.c +++ b/src/ts_catalog/catalog.c @@ -237,6 +237,7 @@ static const TableIndexDef catalog_table_index_definitions[_MAX_CATALOG_TABLES] .length = _MAX_COMPRESSION_SETTINGS_INDEX, .names = (char *[]) { [COMPRESSION_SETTINGS_PKEY] = "compression_settings_pkey", + [COMPRESSION_SETTINGS_COMPRESS_RELID_IDX] = "compression_settings_compress_relid_idx", }, }, [COMPRESSION_CHUNK_SIZE] = { diff --git a/src/ts_catalog/catalog.h b/src/ts_catalog/catalog.h index 901c01adc50..e4fa8c0b89b 100644 --- a/src/ts_catalog/catalog.h +++ b/src/ts_catalog/catalog.h @@ -1091,6 +1091,7 @@ typedef enum Anum_continuous_aggs_watermark_pkey typedef enum Anum_compression_settings { Anum_compression_settings_relid = 1, + Anum_compression_settings_compress_relid, Anum_compression_settings_segmentby, Anum_compression_settings_orderby, Anum_compression_settings_orderby_desc, @@ -1103,6 +1104,7 @@ typedef enum Anum_compression_settings typedef struct FormData_compression_settings { Oid relid; + Oid compress_relid; ArrayType *segmentby; ArrayType *orderby; ArrayType *orderby_desc; @@ -1114,6 +1116,7 @@ typedef FormData_compression_settings *Form_compression_settings; enum { COMPRESSION_SETTINGS_PKEY = 0, + COMPRESSION_SETTINGS_COMPRESS_RELID_IDX, _MAX_COMPRESSION_SETTINGS_INDEX, }; @@ -1125,6 +1128,15 @@ typedef enum Anum_compression_settings_pkey #define Natts_compression_chunk_size_pkey (_Anum_compression_chunk_size_pkey_max - 1) +typedef enum Anum_compression_settings_compress_relid_idx +{ + Anum_compression_settings_compress_relid_idx_relid = 1, + _Anum_compression_settings_compress_relid_idx_max, +} Anum_compression_settings_compress_relid_idx; + +#define Natts_compression_settings_compress_relid_idx \ + (_Anum_compression_settings_compress_relid_idx_max - 1) + #define COMPRESSION_CHUNK_SIZE_TABLE_NAME "compression_chunk_size" typedef enum Anum_compression_chunk_size { diff --git a/src/ts_catalog/compression_settings.c b/src/ts_catalog/compression_settings.c index 1847e05866e..fe1c7d8477f 100644 --- a/src/ts_catalog/compression_settings.c +++ b/src/ts_catalog/compression_settings.c @@ -4,10 +4,9 @@ * LICENSE-APACHE for a copy of the license. */ #include +#include #include -#include "chunk.h" -#include "hypertable.h" #include "scan_iterator.h" #include "scanner.h" #include "ts_catalog/array_utils.h" @@ -28,11 +27,10 @@ ts_compression_settings_equal(const CompressionSettings *left, const Compression } CompressionSettings * -ts_compression_settings_materialize(Oid ht_relid, Oid dst_relid) +ts_compression_settings_materialize(const CompressionSettings *src, Oid relid, Oid compress_relid) { - CompressionSettings *src = ts_compression_settings_get(ht_relid); - Assert(src); - CompressionSettings *dst = ts_compression_settings_create(dst_relid, + CompressionSettings *dst = ts_compression_settings_create(relid, + compress_relid, src->fd.segmentby, src->fd.orderby, src->fd.orderby_desc, @@ -42,8 +40,9 @@ ts_compression_settings_materialize(Oid ht_relid, Oid dst_relid) } CompressionSettings * -ts_compression_settings_create(Oid relid, ArrayType *segmentby, ArrayType *orderby, - ArrayType *orderby_desc, ArrayType *orderby_nullsfirst) +ts_compression_settings_create(Oid relid, Oid compress_relid, ArrayType *segmentby, + ArrayType *orderby, ArrayType *orderby_desc, + ArrayType *orderby_nullsfirst) { Catalog *catalog = ts_catalog_get(); CatalogSecurityContext sec_ctx; @@ -61,6 +60,7 @@ ts_compression_settings_create(Oid relid, ArrayType *segmentby, ArrayType *order (!orderby && !orderby_desc && !orderby_nullsfirst)); fd.relid = relid; + fd.compress_relid = compress_relid; fd.segmentby = segmentby; fd.orderby = orderby; fd.orderby_desc = orderby_desc; @@ -95,6 +95,12 @@ compression_settings_fill_from_tuple(CompressionSettings *settings, TupleInfo *t fd->relid = DatumGetObjectId(values[AttrNumberGetAttrOffset(Anum_compression_settings_relid)]); + if (nulls[AttrNumberGetAttrOffset(Anum_compression_settings_compress_relid)]) + fd->compress_relid = InvalidOid; + else + fd->compress_relid = DatumGetObjectId( + values[AttrNumberGetAttrOffset(Anum_compression_settings_compress_relid)]); + if (nulls[AttrNumberGetAttrOffset(Anum_compression_settings_segmentby)]) fd->segmentby = NULL; else @@ -125,19 +131,28 @@ compression_settings_fill_from_tuple(CompressionSettings *settings, TupleInfo *t heap_freetuple(tuple); } -TSDLLEXPORT CompressionSettings * -ts_compression_settings_get(Oid relid) +static void +compression_settings_iterator_init(ScanIterator *iterator, Oid relid, bool by_compress_relid) { - CompressionSettings *settings = NULL; - ScanIterator iterator = - ts_scan_iterator_create(COMPRESSION_SETTINGS, AccessShareLock, CurrentMemoryContext); - iterator.ctx.index = - catalog_get_index(ts_catalog_get(), COMPRESSION_SETTINGS, COMPRESSION_SETTINGS_PKEY); - ts_scan_iterator_scan_key_init(&iterator, - Anum_compression_settings_pkey_relid, + int indexid = + by_compress_relid ? COMPRESSION_SETTINGS_COMPRESS_RELID_IDX : COMPRESSION_SETTINGS_PKEY; + iterator->ctx.index = catalog_get_index(ts_catalog_get(), COMPRESSION_SETTINGS, indexid); + ts_scan_iterator_scan_key_init(iterator, + by_compress_relid ? + Anum_compression_settings_compress_relid_idx_relid : + Anum_compression_settings_pkey_relid, BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(relid)); +} + +static CompressionSettings * +compression_settings_get(Oid relid, bool by_compress_relid) +{ + CompressionSettings *settings = NULL; + ScanIterator iterator = + ts_scan_iterator_create(COMPRESSION_SETTINGS, AccessShareLock, CurrentMemoryContext); + compression_settings_iterator_init(&iterator, relid, by_compress_relid); ts_scanner_start_scan(&iterator.ctx); TupleInfo *ti = ts_scanner_next(&iterator.ctx); @@ -151,8 +166,20 @@ ts_compression_settings_get(Oid relid) return settings; } -TSDLLEXPORT bool -ts_compression_settings_delete(Oid relid) +TSDLLEXPORT CompressionSettings * +ts_compression_settings_get(Oid relid) +{ + return compression_settings_get(relid, false); +} + +TSDLLEXPORT CompressionSettings * +ts_compression_settings_get_by_compress_relid(Oid relid) +{ + return compression_settings_get(relid, true); +} + +static bool +compression_settings_delete(Oid relid, bool by_compress_relid) { if (!OidIsValid(relid)) return false; @@ -160,13 +187,7 @@ ts_compression_settings_delete(Oid relid) int count = 0; ScanIterator iterator = ts_scan_iterator_create(COMPRESSION_SETTINGS, RowExclusiveLock, CurrentMemoryContext); - iterator.ctx.index = - catalog_get_index(ts_catalog_get(), COMPRESSION_SETTINGS, COMPRESSION_SETTINGS_PKEY); - ts_scan_iterator_scan_key_init(&iterator, - Anum_compression_settings_pkey_relid, - BTEqualStrategyNumber, - F_OIDEQ, - ObjectIdGetDatum(relid)); + compression_settings_iterator_init(&iterator, relid, by_compress_relid); ts_scanner_foreach(&iterator) { @@ -177,35 +198,46 @@ ts_compression_settings_delete(Oid relid) return count > 0; } -TSDLLEXPORT void -ts_compression_settings_rename_column_hypertable(Hypertable *ht, char *old, char *new) +TSDLLEXPORT bool +ts_compression_settings_delete(Oid relid) { - ts_compression_settings_rename_column(ht->main_table_relid, old, new); - if (ht->fd.compressed_hypertable_id) - { - ListCell *lc; - List *chunks = ts_chunk_get_by_hypertable_id(ht->fd.compressed_hypertable_id); - foreach (lc, chunks) - { - Chunk *chunk = lfirst(lc); - ts_compression_settings_rename_column(chunk->table_id, old, new); - } - } + return compression_settings_delete(relid, false); +} + +TSDLLEXPORT bool +ts_compression_settings_delete_by_compress_relid(Oid relid) +{ + return compression_settings_delete(relid, true); +} + +static void +compression_settings_rename_column(CompressionSettings *settings, const char *old, const char *new) +{ + settings->fd.segmentby = ts_array_replace_text(settings->fd.segmentby, old, new); + settings->fd.orderby = ts_array_replace_text(settings->fd.orderby, old, new); + ts_compression_settings_update(settings); } TSDLLEXPORT void -ts_compression_settings_rename_column(Oid relid, char *old, char *new) +ts_compression_settings_rename_column_recurse(Oid parent_relid, const char *old, const char *new) { - CompressionSettings *settings = ts_compression_settings_get(relid); + CompressionSettings *settings = ts_compression_settings_get(parent_relid); - if (!settings) - return; + if (settings) + compression_settings_rename_column(settings, old, new); - settings->fd.segmentby = ts_array_replace_text(settings->fd.segmentby, old, new); + List *children = find_inheritance_children(parent_relid, NoLock); + ListCell *lc; - settings->fd.orderby = ts_array_replace_text(settings->fd.orderby, old, new); + foreach (lc, children) + { + Oid relid = lfirst_oid(lc); - ts_compression_settings_update(settings); + settings = ts_compression_settings_get(relid); + + if (settings) + compression_settings_rename_column(settings, old, new); + } } TSDLLEXPORT int @@ -269,6 +301,12 @@ compression_settings_formdata_make_tuple(const FormData_compression_settings *fd values[AttrNumberGetAttrOffset(Anum_compression_settings_relid)] = ObjectIdGetDatum(fd->relid); + if (OidIsValid(fd->compress_relid)) + values[AttrNumberGetAttrOffset(Anum_compression_settings_compress_relid)] = + ObjectIdGetDatum(fd->compress_relid); + else + nulls[AttrNumberGetAttrOffset(Anum_compression_settings_compress_relid)] = true; + if (fd->segmentby) values[AttrNumberGetAttrOffset(Anum_compression_settings_segmentby)] = PointerGetDatum(fd->segmentby); diff --git a/src/ts_catalog/compression_settings.h b/src/ts_catalog/compression_settings.h index 26a7dbc4d70..09fe330c2c8 100644 --- a/src/ts_catalog/compression_settings.h +++ b/src/ts_catalog/compression_settings.h @@ -8,7 +8,6 @@ #include #include -#include "hypertable.h" #include "ts_catalog/catalog.h" typedef struct CompressionSettings @@ -16,18 +15,20 @@ typedef struct CompressionSettings FormData_compression_settings fd; } CompressionSettings; -TSDLLEXPORT CompressionSettings *ts_compression_settings_create(Oid relid, ArrayType *segmentby, +TSDLLEXPORT CompressionSettings *ts_compression_settings_create(Oid relid, Oid compress_relid, + ArrayType *segmentby, ArrayType *orderby, ArrayType *orderby_desc, ArrayType *orderby_nullsfirst); TSDLLEXPORT CompressionSettings *ts_compression_settings_get(Oid relid); -TSDLLEXPORT CompressionSettings *ts_compression_settings_materialize(Oid ht_relid, Oid dst_relid); +TSDLLEXPORT CompressionSettings *ts_compression_settings_get_by_compress_relid(Oid relid); +TSDLLEXPORT CompressionSettings *ts_compression_settings_materialize(const CompressionSettings *src, + Oid relid, Oid compress_relid); TSDLLEXPORT bool ts_compression_settings_delete(Oid relid); +TSDLLEXPORT bool ts_compression_settings_delete_by_compress_relid(Oid relid); TSDLLEXPORT bool ts_compression_settings_equal(const CompressionSettings *left, const CompressionSettings *right); TSDLLEXPORT int ts_compression_settings_update(CompressionSettings *settings); - -TSDLLEXPORT void ts_compression_settings_rename_column(Oid relid, char *old, char *new); -TSDLLEXPORT void ts_compression_settings_rename_column_hypertable(Hypertable *ht, char *old, - char *new); +TSDLLEXPORT void ts_compression_settings_rename_column_recurse(Oid parent_relid, const char *old, + const char *new); diff --git a/src/ts_catalog/continuous_agg.h b/src/ts_catalog/continuous_agg.h index 268c42488d3..02f802b687e 100644 --- a/src/ts_catalog/continuous_agg.h +++ b/src/ts_catalog/continuous_agg.h @@ -10,6 +10,7 @@ #include #include "chunk.h" +#include "hypertable.h" #include "ts_catalog/catalog.h" #include "compat/compat.h" diff --git a/tsl/src/compression/api.c b/tsl/src/compression/api.c index a0b62e0e3f0..e55892bd875 100644 --- a/tsl/src/compression/api.c +++ b/tsl/src/compression/api.c @@ -310,8 +310,7 @@ find_chunk_to_merge_into(Hypertable *ht, Chunk *current_chunk) return NULL; /* Get reloid of the previous compressed chunk */ - Oid prev_comp_reloid = ts_chunk_get_relid(previous_chunk->fd.compressed_chunk_id, false); - CompressionSettings *prev_comp_settings = ts_compression_settings_get(prev_comp_reloid); + CompressionSettings *prev_comp_settings = ts_compression_settings_get(previous_chunk->table_id); CompressionSettings *ht_comp_settings = ts_compression_settings_get(ht->main_table_relid); if (!ts_compression_settings_equal(ht_comp_settings, prev_comp_settings)) return NULL; @@ -594,7 +593,7 @@ decompress_chunk_impl(Chunk *uncompressed_chunk, bool if_compressed) /* Delete the compressed chunk */ ts_compression_chunk_size_delete(uncompressed_chunk->fd.id); ts_chunk_clear_compressed_chunk(uncompressed_chunk); - ts_compression_settings_delete(compressed_chunk->table_id); + ts_compression_settings_delete(uncompressed_chunk->table_id); /* * Lock the compressed chunk that is going to be deleted. At this point, @@ -715,9 +714,7 @@ tsl_compress_chunk_wrapper(Chunk *chunk, bool if_not_compressed, bool recompress if (recompress) { CompressionSettings *ht_settings = ts_compression_settings_get(chunk->hypertable_relid); - Oid compressed_chunk_relid = ts_chunk_get_relid(chunk->fd.compressed_chunk_id, true); - CompressionSettings *chunk_settings = - ts_compression_settings_get(compressed_chunk_relid); + CompressionSettings *chunk_settings = ts_compression_settings_get(chunk->table_id); if (!ts_compression_settings_equal(ht_settings, chunk_settings)) { @@ -890,11 +887,10 @@ static Oid get_compressed_chunk_index_for_recompression(Chunk *uncompressed_chunk) { Chunk *compressed_chunk = ts_chunk_get_by_id(uncompressed_chunk->fd.compressed_chunk_id, true); - Relation uncompressed_chunk_rel = table_open(uncompressed_chunk->table_id, ShareLock); Relation compressed_chunk_rel = table_open(compressed_chunk->table_id, ShareLock); - CompressionSettings *settings = ts_compression_settings_get(compressed_chunk->table_id); + CompressionSettings *settings = ts_compression_settings_get(uncompressed_chunk->table_id); ResultRelInfo *indstate = ts_catalog_open_indexes(compressed_chunk_rel); Oid index_oid = get_compressed_chunk_index(indstate, settings); @@ -1078,8 +1074,7 @@ recompress_chunk_segmentwise_impl(Chunk *uncompressed_chunk) NameStr(uncompressed_chunk->fd.table_name)); /* need it to find the segby cols from the catalog */ - Chunk *compressed_chunk = ts_chunk_get_by_id(uncompressed_chunk->fd.compressed_chunk_id, true); - CompressionSettings *settings = ts_compression_settings_get(compressed_chunk->table_id); + const CompressionSettings *settings = ts_compression_settings_get(uncompressed_chunk->table_id); int nsegmentby_cols = ts_array_length(settings->fd.segmentby); @@ -1093,6 +1088,7 @@ recompress_chunk_segmentwise_impl(Chunk *uncompressed_chunk) /* lock both chunks, compressed and uncompressed */ /* TODO: Take RowExclusive locks instead of AccessExclusive */ + Chunk *compressed_chunk = ts_chunk_get_by_id(uncompressed_chunk->fd.compressed_chunk_id, true); Relation uncompressed_chunk_rel = table_open(uncompressed_chunk->table_id, ExclusiveLock); Relation compressed_chunk_rel = table_open(compressed_chunk->table_id, ExclusiveLock); diff --git a/tsl/src/compression/compression.c b/tsl/src/compression/compression.c index ac55a1f6a36..56e4887fb42 100644 --- a/tsl/src/compression/compression.c +++ b/tsl/src/compression/compression.c @@ -236,7 +236,7 @@ compress_chunk(Oid in_table, Oid out_table, int insert_options) HeapTuple in_table_tp = NULL, index_tp = NULL; Form_pg_attribute in_table_attr_tp, index_attr_tp; CompressionStats cstat; - CompressionSettings *settings = ts_compression_settings_get(out_table); + CompressionSettings *settings = ts_compression_settings_get_by_compress_relid(out_table); int64 report_reltuples; /* We want to prevent other compressors from compressing this table, @@ -585,7 +585,7 @@ compress_chunk_sort_relation(CompressionSettings *settings, Relation in_rel) } void -compress_chunk_populate_sort_info_for_column(CompressionSettings *settings, Oid table, +compress_chunk_populate_sort_info_for_column(const CompressionSettings *settings, Oid table, const char *attname, AttrNumber *att_nums, Oid *sort_operator, Oid *collation, bool *nulls_first) { @@ -637,7 +637,7 @@ compress_chunk_populate_sort_info_for_column(CompressionSettings *settings, Oid * we are trying to roll up chunks while compressing */ Oid -get_compressed_chunk_index(ResultRelInfo *resultRelInfo, CompressionSettings *settings) +get_compressed_chunk_index(ResultRelInfo *resultRelInfo, const CompressionSettings *settings) { int num_segmentby_columns = ts_array_length(settings->fd.segmentby); @@ -830,7 +830,7 @@ get_sequence_number_for_current_group(Relation table_rel, Oid index_oid, } static void -build_column_map(CompressionSettings *settings, Relation uncompressed_table, +build_column_map(const CompressionSettings *settings, Relation uncompressed_table, Relation compressed_table, PerColumn **pcolumns, int16 **pmap) { Oid compressed_data_type_oid = ts_custom_type_cache_get(CUSTOM_TYPE_COMPRESSED_DATA)->type_oid; @@ -924,7 +924,7 @@ build_column_map(CompressionSettings *settings, Relation uncompressed_table, ** row_compressor ** ********************/ void -row_compressor_init(CompressionSettings *settings, RowCompressor *row_compressor, +row_compressor_init(const CompressionSettings *settings, RowCompressor *row_compressor, Relation uncompressed_table, Relation compressed_table, int16 num_columns_in_compressed_table, bool need_bistate, bool reset_sequence, int insert_options) @@ -2004,14 +2004,12 @@ compression_get_default_algorithm(Oid typeoid) * columns of the uncompressed chunk. */ static ScanKeyData * -build_scankeys(Oid hypertable_relid, Oid out_rel, RowDecompressor *decompressor, - Bitmapset *key_columns, Bitmapset **null_columns, TupleTableSlot *slot, - int *num_scankeys) +build_scankeys(Oid hypertable_relid, const CompressionSettings *settings, + RowDecompressor *decompressor, Bitmapset *key_columns, Bitmapset **null_columns, + TupleTableSlot *slot, int *num_scankeys) { int key_index = 0; ScanKeyData *scankeys = NULL; - - CompressionSettings *settings = ts_compression_settings_get(out_rel); Assert(settings); if (!bms_is_empty(key_columns)) @@ -2272,8 +2270,9 @@ decompress_batches_for_insert(const ChunkInsertState *cis, TupleTableSlot *slot) Bitmapset *null_columns = NULL; int num_scankeys; + const CompressionSettings *settings = ts_compression_settings_get(RelationGetRelid(cis->rel)); ScanKeyData *scankeys = build_scankeys(cis->hypertable_relid, - in_rel->rd_id, + settings, &decompressor, key_columns, &null_columns, @@ -2592,15 +2591,18 @@ process_predicates(Chunk *ch, CompressionSettings *settings, List *predicates, L continue; } + Assert(OidIsValid(settings->fd.compress_relid)); + Assert(ch->table_id == settings->fd.relid); + int min_attno = compressed_column_metadata_attno(settings, ch->table_id, var->varattno, - settings->fd.relid, + settings->fd.compress_relid, "min"); int max_attno = compressed_column_metadata_attno(settings, ch->table_id, var->varattno, - settings->fd.relid, + settings->fd.compress_relid, "max"); if (min_attno != InvalidAttrNumber && max_attno != InvalidAttrNumber) @@ -2610,66 +2612,70 @@ process_predicates(Chunk *ch, CompressionSettings *settings, List *predicates, L case BTEqualStrategyNumber: { /* orderby col = value implies min <= value and max >= value */ - *heap_filters = lappend(*heap_filters, - make_batchfilter(get_attname(settings->fd.relid, - min_attno, - false), - BTLessEqualStrategyNumber, - collation, - opcode, - arg_value, - false, /* is_null_check */ - false, /* is_null */ - false /* is_array_op */ - )); - *heap_filters = lappend(*heap_filters, - make_batchfilter(get_attname(settings->fd.relid, - max_attno, - false), - BTGreaterEqualStrategyNumber, - collation, - opcode, - arg_value, - false, /* is_null_check */ - false, /* is_null */ - false /* is_array_op */ - )); + *heap_filters = + lappend(*heap_filters, + make_batchfilter(get_attname(settings->fd.compress_relid, + min_attno, + false), + BTLessEqualStrategyNumber, + collation, + opcode, + arg_value, + false, /* is_null_check */ + false, /* is_null */ + false /* is_array_op */ + )); + *heap_filters = + lappend(*heap_filters, + make_batchfilter(get_attname(settings->fd.compress_relid, + max_attno, + false), + BTGreaterEqualStrategyNumber, + collation, + opcode, + arg_value, + false, /* is_null_check */ + false, /* is_null */ + false /* is_array_op */ + )); } break; case BTLessStrategyNumber: case BTLessEqualStrategyNumber: { /* orderby col <[=] value implies min <[=] value */ - *heap_filters = lappend(*heap_filters, - make_batchfilter(get_attname(settings->fd.relid, - min_attno, - false), - op_strategy, - collation, - opcode, - arg_value, - false, /* is_null_check */ - false, /* is_null */ - false /* is_array_op */ - )); + *heap_filters = + lappend(*heap_filters, + make_batchfilter(get_attname(settings->fd.compress_relid, + min_attno, + false), + op_strategy, + collation, + opcode, + arg_value, + false, /* is_null_check */ + false, /* is_null */ + false /* is_array_op */ + )); } break; case BTGreaterStrategyNumber: case BTGreaterEqualStrategyNumber: { /* orderby col >[=] value implies max >[=] value */ - *heap_filters = lappend(*heap_filters, - make_batchfilter(get_attname(settings->fd.relid, - max_attno, - false), - op_strategy, - collation, - opcode, - arg_value, - false, /* is_null_check */ - false, /* is_null */ - false /* is_array_op */ - )); + *heap_filters = + lappend(*heap_filters, + make_batchfilter(get_attname(settings->fd.compress_relid, + max_attno, + false), + op_strategy, + collation, + opcode, + arg_value, + false, /* is_null_check */ + false, /* is_null */ + false /* is_array_op */ + )); } } } @@ -3185,12 +3191,12 @@ decompress_batches_for_update_delete(HypertableModifyState *ht_state, Chunk *chu ScanKeyData *index_scankeys = NULL; int num_index_scankeys = 0; - comp_chunk = ts_chunk_get_by_id(chunk->fd.compressed_chunk_id, true); - CompressionSettings *settings = ts_compression_settings_get(comp_chunk->table_id); + CompressionSettings *settings = ts_compression_settings_get(chunk->table_id); process_predicates(chunk, settings, predicates, &heap_filters, &index_filters, &is_null); chunk_rel = table_open(chunk->table_id, RowExclusiveLock); + comp_chunk = ts_chunk_get_by_id(chunk->fd.compressed_chunk_id, true); comp_chunk_rel = table_open(comp_chunk->table_id, RowExclusiveLock); decompressor = build_decompressor(comp_chunk_rel, chunk_rel); diff --git a/tsl/src/compression/compression.h b/tsl/src/compression/compression.h index 69427f49d82..3972febaac3 100644 --- a/tsl/src/compression/compression.h +++ b/tsl/src/compression/compression.h @@ -349,11 +349,11 @@ extern void compress_row_destroy(CompressSingleRowState *cr); extern void row_decompressor_decompress_row_to_table(RowDecompressor *row_decompressor); extern void row_decompressor_decompress_row_to_tuplesort(RowDecompressor *row_decompressor, Tuplesortstate *tuplesortstate); -extern void compress_chunk_populate_sort_info_for_column(CompressionSettings *settings, Oid table, - const char *attname, AttrNumber *att_nums, - Oid *sort_operator, Oid *collation, - bool *nulls_first); -extern void row_compressor_init(CompressionSettings *settings, RowCompressor *row_compressor, +extern void compress_chunk_populate_sort_info_for_column(const CompressionSettings *settings, + Oid table, const char *attname, + AttrNumber *att_nums, Oid *sort_operator, + Oid *collation, bool *nulls_first); +extern void row_compressor_init(const CompressionSettings *settings, RowCompressor *row_compressor, Relation uncompressed_table, Relation compressed_table, int16 num_columns_in_compressed_table, bool need_bistate, bool reset_sequence, int insert_options); @@ -362,7 +362,8 @@ extern void row_compressor_close(RowCompressor *row_compressor); extern void row_compressor_append_sorted_rows(RowCompressor *row_compressor, Tuplesortstate *sorted_rel, TupleDesc sorted_desc, Relation in_rel); -extern Oid get_compressed_chunk_index(ResultRelInfo *resultRelInfo, CompressionSettings *settings); +extern Oid get_compressed_chunk_index(ResultRelInfo *resultRelInfo, + const CompressionSettings *settings); extern void segment_info_update(SegmentInfo *segment_info, Datum val, bool is_null); diff --git a/tsl/src/compression/create.c b/tsl/src/compression/create.c index c7b892c8492..933a29c7a74 100644 --- a/tsl/src/compression/create.c +++ b/tsl/src/compression/create.c @@ -144,7 +144,7 @@ compressed_column_metadata_name_v2(const char *metadata_type, const char *column } int -compressed_column_metadata_attno(CompressionSettings *settings, Oid chunk_reloid, +compressed_column_metadata_attno(const CompressionSettings *settings, Oid chunk_reloid, AttrNumber chunk_attno, Oid compressed_reloid, char *metadata_type) { Assert(is_sparse_index_type(metadata_type)); @@ -445,12 +445,12 @@ create_compress_chunk(Hypertable *compress_ht, Chunk *src_chunk, Oid table_id) * for now. */ tablespace_oid = get_rel_tablespace(src_chunk->table_id); + CompressionSettings *settings = ts_compression_settings_get(src_chunk->hypertable_relid); if (OidIsValid(table_id)) compress_chunk->table_id = table_id; else { - CompressionSettings *settings = ts_compression_settings_get(src_chunk->hypertable_relid); List *column_defs = build_columndefs(settings, src_chunk->table_id); compress_chunk->table_id = compression_chunk_create(src_chunk, compress_chunk, column_defs, tablespace_oid); @@ -460,7 +460,7 @@ create_compress_chunk(Hypertable *compress_ht, Chunk *src_chunk, Oid table_id) elog(ERROR, "could not create compressed chunk table"); /* Materialize current compression settings for this chunk */ - ts_compression_settings_materialize(src_chunk->hypertable_relid, compress_chunk->table_id); + ts_compression_settings_materialize(settings, src_chunk->table_id, compress_chunk->table_id); /* if the src chunk is not in the default tablespace, the compressed indexes * should also be in a non-default tablespace. IN the usual case, this is inferred @@ -519,6 +519,7 @@ validate_existing_constraints(Hypertable *ht, CompressionSettings *settings) ArrayType *arr; + Assert(ht->main_table_relid == settings->fd.relid); pg_constr = table_open(ConstraintRelationId, AccessShareLock); ScanKeyInit(&scankey, @@ -805,7 +806,12 @@ tsl_process_compress_table(AlterTableCmd *cmd, Hypertable *ht, settings = ts_compression_settings_get(ht->main_table_relid); if (!settings) { - settings = ts_compression_settings_create(ht->main_table_relid, NULL, NULL, NULL, NULL); + settings = ts_compression_settings_create(ht->main_table_relid, + InvalidOid, + NULL, + NULL, + NULL, + NULL); } compression_settings_update(ht, settings, with_clause_options); @@ -1190,7 +1196,8 @@ tsl_process_compress_table_add_column(Hypertable *ht, ColumnDef *orig_def) return; } ColumnDef *coldef = build_columndef_singlecolumn(orig_def->colname, coloid); - CompressionSettings *settings = ts_compression_settings_get(chunk->table_id); + CompressionSettings *settings = + ts_compression_settings_get_by_compress_relid(chunk->table_id); add_column_to_compression_table(chunk->table_id, settings, coldef); } } diff --git a/tsl/src/compression/create.h b/tsl/src/compression/create.h index 8b3ea7845d8..f20ad8628c0 100644 --- a/tsl/src/compression/create.h +++ b/tsl/src/compression/create.h @@ -30,6 +30,6 @@ char *column_segment_max_name(int16 column_index); char *compressed_column_metadata_name_v2(const char *metadata_type, const char *column_name); typedef struct CompressionSettings CompressionSettings; -int compressed_column_metadata_attno(CompressionSettings *settings, Oid chunk_reloid, +int compressed_column_metadata_attno(const CompressionSettings *settings, Oid chunk_reloid, AttrNumber chunk_attno, Oid compressed_reloid, char *metadata_type); diff --git a/tsl/src/continuous_aggs/materialize.c b/tsl/src/continuous_aggs/materialize.c index 017ee583c33..56476a6586f 100644 --- a/tsl/src/continuous_aggs/materialize.c +++ b/tsl/src/continuous_aggs/materialize.c @@ -19,6 +19,7 @@ #include #include +#include "chunk.h" #include "debug_assert.h" #include "materialize.h" #include "ts_catalog/continuous_agg.h" diff --git a/tsl/src/continuous_aggs/refresh.c b/tsl/src/continuous_aggs/refresh.c index cb432ad6b69..a38552950e2 100644 --- a/tsl/src/continuous_aggs/refresh.c +++ b/tsl/src/continuous_aggs/refresh.c @@ -20,6 +20,7 @@ #include "ts_catalog/catalog.h" #include "ts_catalog/continuous_agg.h" +#include #include #include #include diff --git a/tsl/src/nodes/decompress_chunk/decompress_chunk.c b/tsl/src/nodes/decompress_chunk/decompress_chunk.c index 94e5f79b92d..35ed5b9c413 100644 --- a/tsl/src/nodes/decompress_chunk/decompress_chunk.c +++ b/tsl/src/nodes/decompress_chunk/decompress_chunk.c @@ -274,9 +274,7 @@ build_compressioninfo(PlannerInfo *root, Hypertable *ht, Chunk *chunk, RelOptInf info->chunk_rel = chunk_rel; info->chunk_rte = planner_rt_fetch(chunk_rel->relid, root); - - Oid relid = ts_chunk_get_relid(chunk->fd.compressed_chunk_id, true); - info->settings = ts_compression_settings_get(relid); + info->settings = ts_compression_settings_get(chunk->table_id); if (chunk_rel->reloptkind == RELOPT_OTHER_MEMBER_REL) { diff --git a/tsl/test/expected/cagg_ddl-14.out b/tsl/test/expected/cagg_ddl-14.out index 68077a8f324..9ff20deb0d0 100644 --- a/tsl/test/expected/cagg_ddl-14.out +++ b/tsl/test/expected/cagg_ddl-14.out @@ -2112,7 +2112,7 @@ SELECT count(compress_chunk(ch)) FROM show_chunks('cagg1') ch; DROP MATERIALIZED VIEW cagg1; NOTICE: drop cascades to table _timescaledb_internal._hyper_52_70_chunk SELECT * FROM _timescaledb_catalog.compression_settings; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst --------+-----------+---------+--------------+-------------------- + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +-------+----------------+-----------+---------+--------------+-------------------- (0 rows) diff --git a/tsl/test/expected/cagg_ddl-15.out b/tsl/test/expected/cagg_ddl-15.out index 68077a8f324..9ff20deb0d0 100644 --- a/tsl/test/expected/cagg_ddl-15.out +++ b/tsl/test/expected/cagg_ddl-15.out @@ -2112,7 +2112,7 @@ SELECT count(compress_chunk(ch)) FROM show_chunks('cagg1') ch; DROP MATERIALIZED VIEW cagg1; NOTICE: drop cascades to table _timescaledb_internal._hyper_52_70_chunk SELECT * FROM _timescaledb_catalog.compression_settings; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst --------+-----------+---------+--------------+-------------------- + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +-------+----------------+-----------+---------+--------------+-------------------- (0 rows) diff --git a/tsl/test/expected/cagg_ddl-16.out b/tsl/test/expected/cagg_ddl-16.out index 38de3c97af2..7233851c065 100644 --- a/tsl/test/expected/cagg_ddl-16.out +++ b/tsl/test/expected/cagg_ddl-16.out @@ -2112,7 +2112,7 @@ SELECT count(compress_chunk(ch)) FROM show_chunks('cagg1') ch; DROP MATERIALIZED VIEW cagg1; NOTICE: drop cascades to table _timescaledb_internal._hyper_52_70_chunk SELECT * FROM _timescaledb_catalog.compression_settings; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst --------+-----------+---------+--------------+-------------------- + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +-------+----------------+-----------+---------+--------------+-------------------- (0 rows) diff --git a/tsl/test/expected/compression.out b/tsl/test/expected/compression.out index 2f5ab848313..d598f5c1ca7 100644 --- a/tsl/test/expected/compression.out +++ b/tsl/test/expected/compression.out @@ -67,9 +67,9 @@ SELECT id, schema_name, table_name, compression_state as compressed, compressed_ (2 rows) SELECT * FROM _timescaledb_catalog.compression_settings ORDER BY relid::regclass; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst --------+-----------+---------+--------------+-------------------- - foo | {a,b} | {c,d} | {t,f} | {t,f} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +-------+----------------+-----------+---------+--------------+-------------------- + foo | | {a,b} | {c,d} | {t,f} | {t,f} (1 row) SELECT * FROM timescaledb_information.compression_settings ORDER BY hypertable_name; @@ -289,9 +289,9 @@ SELECT id, schema_name, table_name, compression_state as compressed, compressed_ (1 row) SELECT * FROM _timescaledb_catalog.compression_settings WHERE relid = 'conditions'::regclass; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst -------------+------------+---------+--------------+-------------------- - conditions | {location} | {time} | {f} | {f} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +------------+----------------+------------+---------+--------------+-------------------- + conditions | | {location} | {time} | {f} | {f} (1 row) select attname, attstorage, typname from pg_attribute at, pg_class cl , pg_type ty @@ -917,9 +917,9 @@ select id, schema_name, table_name, compression_state as compressed, compressed_ (1 row) SELECT * FROM _timescaledb_catalog.compression_settings WHERE relid='datatype_test'::regclass; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst ----------------+-----------+---------+--------------+-------------------- - datatype_test | | {time} | {t} | {t} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +---------------+----------------+-----------+---------+--------------+-------------------- + datatype_test | | | {time} | {t} | {t} (1 row) --TEST try to compress a hypertable that has a continuous aggregate diff --git a/tsl/test/expected/compression_ddl.out b/tsl/test/expected/compression_ddl.out index 84fd25d985c..f51303976ca 100644 --- a/tsl/test/expected/compression_ddl.out +++ b/tsl/test/expected/compression_ddl.out @@ -718,9 +718,9 @@ WARNING: there was some uncertainty picking the default segment by for the hype NOTICE: default segment by for hypertable "i2844" is set to "" NOTICE: default order by for hypertable "i2844" is set to "created_at DESC" SELECT * FROM _timescaledb_catalog.compression_settings WHERE relid='i2844'::regclass; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst --------+-----------+--------------+--------------+-------------------- - i2844 | | {created_at} | {t} | {t} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +-------+----------------+-----------+--------------+--------------+-------------------- + i2844 | | | {created_at} | {t} | {t} (1 row) SELECT compress_chunk(show_chunks) AS compressed_chunk FROM show_chunks('i2844'); @@ -883,9 +883,9 @@ SELECT * from _timescaledb_catalog.hypertable WHERE table_name = 'test1'; (1 row) SELECT * FROM _timescaledb_catalog.compression_settings WHERE relid='test1'::regclass; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst --------+-----------+---------+--------------+-------------------- - test1 | {bntcol} | {Time} | {t} | {t} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +-------+----------------+-----------+---------+--------------+-------------------- + test1 | | {bntcol} | {Time} | {t} | {t} (1 row) ALTER TABLE test1 RENAME new_coli TO coli; @@ -896,9 +896,9 @@ SELECT * from _timescaledb_catalog.hypertable WHERE table_name = 'test1'; (1 row) SELECT * FROM _timescaledb_catalog.compression_settings WHERE relid='test1'::regclass; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst --------+-----------+---------+--------------+-------------------- - test1 | {bntcol} | {Time} | {t} | {t} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +-------+----------------+-----------+---------+--------------+-------------------- + test1 | | {bntcol} | {Time} | {t} | {t} (1 row) SELECT count(*) from test1 where coli = 100; @@ -910,9 +910,9 @@ SELECT count(*) from test1 where coli = 100; --rename segment by column name ALTER TABLE test1 RENAME bntcol TO bigintcol ; SELECT * FROM _timescaledb_catalog.compression_settings WHERE relid='test1'::regclass; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst --------+-------------+---------+--------------+-------------------- - test1 | {bigintcol} | {Time} | {t} | {t} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +-------+----------------+-------------+---------+--------------+-------------------- + test1 | | {bigintcol} | {Time} | {t} | {t} (1 row) --query by segment by column name @@ -982,9 +982,9 @@ ALTER TABLE test1 RENAME bigintcol TO ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccabdeeeeeeccccccccccccc; psql:include/compression_alter.sql:97: NOTICE: identifier "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccabdeeeeeeccccccccccccc" will be truncated to "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccca" SELECT * from _timescaledb_catalog.compression_settings WHERE relid = 'test1'::regclass; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst --------+-------------------------------------------------------------------+---------+--------------+-------------------- - test1 | {cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccca} | {Time} | {t} | {t} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +-------+----------------+-------------------------------------------------------------------+---------+--------------+-------------------- + test1 | | {cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccca} | {Time} | {t} | {t} (1 row) SELECT * from timescaledb_information.compression_settings @@ -1208,9 +1208,9 @@ SELECT * FROM _timescaledb_catalog.hypertable WHERE table_name = 'test_drop'; (1 row) SELECT * FROM _timescaledb_catalog.compression_settings WHERE relid = 'test_drop'::regclass; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst ------------+-----------+--------------+--------------+-------------------- - test_drop | {device} | {o1,o2,time} | {f,f,t} | {f,f,t} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +-----------+----------------+-----------+--------------+--------------+-------------------- + test_drop | | {device} | {o1,o2,time} | {f,f,t} | {f,f,t} (1 row) --TEST tablespaces for compressed chunks with attach_tablespace interface -- diff --git a/tsl/test/expected/compression_defaults.out b/tsl/test/expected/compression_defaults.out index 503f785f246..b01e84daff9 100644 --- a/tsl/test/expected/compression_defaults.out +++ b/tsl/test/expected/compression_defaults.out @@ -41,18 +41,18 @@ ALTER TABLE metrics SET (timescaledb.compress = true); NOTICE: default segment by for hypertable "metrics" is set to "device_id" NOTICE: default order by for hypertable "metrics" is set to ""time" DESC" SELECT * FROM _timescaledb_catalog.compression_settings; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst ----------+-------------+---------+--------------+-------------------- - metrics | {device_id} | {time} | {t} | {t} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +---------+----------------+-------------+---------+--------------+-------------------- + metrics | | {device_id} | {time} | {t} | {t} (1 row) ALTER TABLE metrics SET (timescaledb.compress = false); ALTER TABLE metrics SET (timescaledb.compress = true, timescaledb.compress_segmentby = 'device_id'); NOTICE: default order by for hypertable "metrics" is set to ""time" DESC" SELECT * FROM _timescaledb_catalog.compression_settings; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst ----------+-------------+---------+--------------+-------------------- - metrics | {device_id} | {time} | {t} | {t} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +---------+----------------+-------------+---------+--------------+-------------------- + metrics | | {device_id} | {time} | {t} | {t} (1 row) ALTER TABLE metrics SET (timescaledb.compress = false); @@ -62,9 +62,9 @@ SET timescaledb.compression_orderby_default_function = ''; ALTER TABLE metrics SET (timescaledb.compress = true); WARNING: column "device_id" should be used for segmenting or ordering SELECT * FROM _timescaledb_catalog.compression_settings; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst ----------+-----------+---------+--------------+-------------------- - metrics | | {time} | {t} | {t} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +---------+----------------+-----------+---------+--------------+-------------------- + metrics | | | {time} | {t} | {t} (1 row) ALTER TABLE metrics SET (timescaledb.compress = false); @@ -73,9 +73,9 @@ RESET timescaledb.compression_orderby_default_function; ALTER TABLE metrics SET (timescaledb.compress = true); NOTICE: default order by for hypertable "metrics" is set to "device_id, "time" DESC" SELECT * FROM _timescaledb_catalog.compression_settings; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst ----------+-----------+------------------+--------------+-------------------- - metrics | | {device_id,time} | {f,t} | {f,t} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +---------+----------------+-----------+------------------+--------------+-------------------- + metrics | | | {device_id,time} | {f,t} | {f,t} (1 row) ALTER TABLE metrics SET (timescaledb.compress = false); @@ -84,9 +84,9 @@ SET timescaledb.compression_orderby_default_function = ''; ALTER TABLE metrics SET (timescaledb.compress = true); NOTICE: default segment by for hypertable "metrics" is set to "device_id" SELECT * FROM _timescaledb_catalog.compression_settings; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst ----------+-------------+---------+--------------+-------------------- - metrics | {device_id} | {time} | {t} | {t} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +---------+----------------+-------------+---------+--------------+-------------------- + metrics | | {device_id} | {time} | {t} | {t} (1 row) ALTER TABLE metrics SET (timescaledb.compress = false); @@ -203,9 +203,9 @@ WARNING: there was some uncertainty picking the default segment by for the hype NOTICE: default segment by for hypertable "metrics" is set to "" NOTICE: default order by for hypertable "metrics" is set to ""time" DESC" SELECT * FROM _timescaledb_catalog.compression_settings; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst ----------+-----------+---------+--------------+-------------------- - metrics | | {time} | {t} | {t} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +---------+----------------+-----------+---------+--------------+-------------------- + metrics | | | {time} | {t} | {t} (1 row) ALTER TABLE metrics SET (timescaledb.compress = false); @@ -376,9 +376,9 @@ SELECT _timescaledb_functions.get_orderby_defaults('table1', ARRAY['col1']::text ALTER TABLE table1 SET (timescaledb.compress, timescaledb.compress_segmentby = 'col1'); NOTICE: default order by for hypertable "table1" is set to "" SELECT * FROM _timescaledb_catalog.compression_settings; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst ---------+-----------+---------+--------------+-------------------- - table1 | {col1} | | | + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +--------+----------------+-----------+---------+--------------+-------------------- + table1 | | {col1} | | | (1 row) ALTER TABLE table1 SET (timescaledb.compress = false); diff --git a/tsl/test/expected/compression_errors-14.out b/tsl/test/expected/compression_errors-14.out index 847891257c4..563cbdf234d 100644 --- a/tsl/test/expected/compression_errors-14.out +++ b/tsl/test/expected/compression_errors-14.out @@ -67,10 +67,10 @@ ALTER TABLE with_rls set (timescaledb.compress, timescaledb.compress_orderby='a' ERROR: compression cannot be used on table with row security --note that the time column "a" should be added to the end of the orderby list SELECT * FROM _timescaledb_catalog.compression_settings ORDER BY relid::text; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst ------------------+----------------+---------+--------------+-------------------- - default_skipped | {c} | {a} | {t} | {t} - foo2 | {"bacB toD",c} | {d,a} | {f,t} | {f,t} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +-----------------+----------------+----------------+---------+--------------+-------------------- + default_skipped | | {c} | {a} | {t} | {t} + foo2 | | {"bacB toD",c} | {d,a} | {f,t} | {f,t} (2 rows) ALTER TABLE foo3 set (timescaledb.compress, timescaledb.compress_orderby='d DeSc NullS lAsT'); @@ -255,9 +255,9 @@ ALTER TABLE foo DROP CONSTRAINT chk_existing; ROLLBACK; --note that the time column "a" should not be added to the end of the order by list again (should appear first) SELECT * FROM _timescaledb_catalog.compression_settings WHERE relid = 'foo'::regclass; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst --------+-----------+---------+--------------+-------------------- - foo | | {a,b} | {f,f} | {f,f} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +-------+----------------+-----------+---------+--------------+-------------------- + foo | | | {a,b} | {f,f} | {f,f} (1 row) SELECT decompress_chunk(ch, false) FROM show_chunks('foo') ch limit 1; @@ -320,9 +320,9 @@ NOTICE: chunk "_hyper_10_5_chunk" is not compressed --should succeed ALTER TABLE foo set (timescaledb.compress, timescaledb.compress_orderby = 'a', timescaledb.compress_segmentby = 'b'); SELECT * FROM _timescaledb_catalog.compression_settings WHERE relid = 'foo'::regclass; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst --------+-----------+---------+--------------+-------------------- - foo | {b} | {a} | {f} | {f} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +-------+----------------+-----------+---------+--------------+-------------------- + foo | | {b} | {a} | {f} | {f} (1 row) SELECT comp_hyper.schema_name|| '.' || comp_hyper.table_name as "COMPRESSED_HYPER_NAME" diff --git a/tsl/test/expected/compression_errors-15.out b/tsl/test/expected/compression_errors-15.out index 847891257c4..563cbdf234d 100644 --- a/tsl/test/expected/compression_errors-15.out +++ b/tsl/test/expected/compression_errors-15.out @@ -67,10 +67,10 @@ ALTER TABLE with_rls set (timescaledb.compress, timescaledb.compress_orderby='a' ERROR: compression cannot be used on table with row security --note that the time column "a" should be added to the end of the orderby list SELECT * FROM _timescaledb_catalog.compression_settings ORDER BY relid::text; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst ------------------+----------------+---------+--------------+-------------------- - default_skipped | {c} | {a} | {t} | {t} - foo2 | {"bacB toD",c} | {d,a} | {f,t} | {f,t} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +-----------------+----------------+----------------+---------+--------------+-------------------- + default_skipped | | {c} | {a} | {t} | {t} + foo2 | | {"bacB toD",c} | {d,a} | {f,t} | {f,t} (2 rows) ALTER TABLE foo3 set (timescaledb.compress, timescaledb.compress_orderby='d DeSc NullS lAsT'); @@ -255,9 +255,9 @@ ALTER TABLE foo DROP CONSTRAINT chk_existing; ROLLBACK; --note that the time column "a" should not be added to the end of the order by list again (should appear first) SELECT * FROM _timescaledb_catalog.compression_settings WHERE relid = 'foo'::regclass; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst --------+-----------+---------+--------------+-------------------- - foo | | {a,b} | {f,f} | {f,f} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +-------+----------------+-----------+---------+--------------+-------------------- + foo | | | {a,b} | {f,f} | {f,f} (1 row) SELECT decompress_chunk(ch, false) FROM show_chunks('foo') ch limit 1; @@ -320,9 +320,9 @@ NOTICE: chunk "_hyper_10_5_chunk" is not compressed --should succeed ALTER TABLE foo set (timescaledb.compress, timescaledb.compress_orderby = 'a', timescaledb.compress_segmentby = 'b'); SELECT * FROM _timescaledb_catalog.compression_settings WHERE relid = 'foo'::regclass; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst --------+-----------+---------+--------------+-------------------- - foo | {b} | {a} | {f} | {f} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +-------+----------------+-----------+---------+--------------+-------------------- + foo | | {b} | {a} | {f} | {f} (1 row) SELECT comp_hyper.schema_name|| '.' || comp_hyper.table_name as "COMPRESSED_HYPER_NAME" diff --git a/tsl/test/expected/compression_errors-16.out b/tsl/test/expected/compression_errors-16.out index 9ad6955df69..06720884857 100644 --- a/tsl/test/expected/compression_errors-16.out +++ b/tsl/test/expected/compression_errors-16.out @@ -67,10 +67,10 @@ ALTER TABLE with_rls set (timescaledb.compress, timescaledb.compress_orderby='a' ERROR: compression cannot be used on table with row security --note that the time column "a" should be added to the end of the orderby list SELECT * FROM _timescaledb_catalog.compression_settings ORDER BY relid::text; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst ------------------+----------------+---------+--------------+-------------------- - default_skipped | {c} | {a} | {t} | {t} - foo2 | {"bacB toD",c} | {d,a} | {f,t} | {f,t} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +-----------------+----------------+----------------+---------+--------------+-------------------- + default_skipped | | {c} | {a} | {t} | {t} + foo2 | | {"bacB toD",c} | {d,a} | {f,t} | {f,t} (2 rows) ALTER TABLE foo3 set (timescaledb.compress, timescaledb.compress_orderby='d DeSc NullS lAsT'); @@ -255,9 +255,9 @@ ALTER TABLE foo DROP CONSTRAINT chk_existing; ROLLBACK; --note that the time column "a" should not be added to the end of the order by list again (should appear first) SELECT * FROM _timescaledb_catalog.compression_settings WHERE relid = 'foo'::regclass; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst --------+-----------+---------+--------------+-------------------- - foo | | {a,b} | {f,f} | {f,f} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +-------+----------------+-----------+---------+--------------+-------------------- + foo | | | {a,b} | {f,f} | {f,f} (1 row) SELECT decompress_chunk(ch, false) FROM show_chunks('foo') ch limit 1; @@ -320,9 +320,9 @@ NOTICE: chunk "_hyper_10_5_chunk" is not compressed --should succeed ALTER TABLE foo set (timescaledb.compress, timescaledb.compress_orderby = 'a', timescaledb.compress_segmentby = 'b'); SELECT * FROM _timescaledb_catalog.compression_settings WHERE relid = 'foo'::regclass; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst --------+-----------+---------+--------------+-------------------- - foo | {b} | {a} | {f} | {f} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +-------+----------------+-----------+---------+--------------+-------------------- + foo | | {b} | {a} | {f} | {f} (1 row) SELECT comp_hyper.schema_name|| '.' || comp_hyper.table_name as "COMPRESSED_HYPER_NAME" diff --git a/tsl/test/expected/compression_settings.out b/tsl/test/expected/compression_settings.out index aa18b9746c2..09a28867ee2 100644 --- a/tsl/test/expected/compression_settings.out +++ b/tsl/test/expected/compression_settings.out @@ -15,9 +15,9 @@ SELECT table_name FROM create_hypertable('metrics','time'); ALTER TABLE metrics SET (timescaledb.compress, timescaledb.compress_segmentby='device'); NOTICE: default order by for hypertable "metrics" is set to ""time" DESC" SELECT * FROM settings; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst ----------+-----------+---------+--------------+-------------------- - metrics | {device} | {time} | {t} | {t} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +---------+----------------+-----------+---------+--------------+-------------------- + metrics | | {device} | {time} | {t} | {t} (1 row) SELECT * FROM ht_settings; @@ -35,9 +35,9 @@ SELECT * FROM chunk_settings; INSERT INTO metrics VALUES ('2000-01-01'), ('2001-01-01'); -- no change to settings SELECT * FROM settings; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst ----------+-----------+---------+--------------+-------------------- - metrics | {device} | {time} | {t} | {t} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +---------+----------------+-----------+---------+--------------+-------------------- + metrics | | {device} | {time} | {t} | {t} (1 row) --Enable compression path info @@ -51,10 +51,10 @@ INFO: compress_chunk_tuplesort_start RESET timescaledb.debug_compression_path_info; SELECT * FROM settings; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst -------------------------------------------------+-----------+---------+--------------+-------------------- - metrics | {device} | {time} | {t} | {t} - _timescaledb_internal.compress_hyper_2_3_chunk | {device} | {time} | {t} | {t} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +----------------------------------------+------------------------------------------------+-----------+---------+--------------+-------------------- + metrics | | {device} | {time} | {t} | {t} + _timescaledb_internal._hyper_1_1_chunk | _timescaledb_internal.compress_hyper_2_3_chunk | {device} | {time} | {t} | {t} (2 rows) SELECT * FROM chunk_settings; @@ -70,11 +70,11 @@ SELECT compress_chunk('_timescaledb_internal._hyper_1_2_chunk'); (1 row) SELECT * FROM settings; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst -------------------------------------------------+-----------+---------+--------------+-------------------- - metrics | {device} | {time} | {t} | {t} - _timescaledb_internal.compress_hyper_2_3_chunk | {device} | {time} | {t} | {t} - _timescaledb_internal.compress_hyper_2_4_chunk | {device} | {time} | {t} | {t} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +----------------------------------------+------------------------------------------------+-----------+---------+--------------+-------------------- + metrics | | {device} | {time} | {t} | {t} + _timescaledb_internal._hyper_1_1_chunk | _timescaledb_internal.compress_hyper_2_3_chunk | {device} | {time} | {t} | {t} + _timescaledb_internal._hyper_1_2_chunk | _timescaledb_internal.compress_hyper_2_4_chunk | {device} | {time} | {t} | {t} (3 rows) SELECT * FROM chunk_settings; @@ -87,10 +87,10 @@ SELECT * FROM chunk_settings; -- dropping chunk should remove that chunks compression settings DROP TABLE _timescaledb_internal._hyper_1_1_chunk; SELECT * FROM settings; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst -------------------------------------------------+-----------+---------+--------------+-------------------- - metrics | {device} | {time} | {t} | {t} - _timescaledb_internal.compress_hyper_2_4_chunk | {device} | {time} | {t} | {t} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +----------------------------------------+------------------------------------------------+-----------+---------+--------------+-------------------- + metrics | | {device} | {time} | {t} | {t} + _timescaledb_internal._hyper_1_2_chunk | _timescaledb_internal.compress_hyper_2_4_chunk | {device} | {time} | {t} | {t} (2 rows) SELECT * FROM chunk_settings; @@ -107,9 +107,9 @@ SELECT decompress_chunk('_timescaledb_internal._hyper_1_2_chunk'); (1 row) SELECT * FROM settings; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst ----------+-----------+---------+--------------+-------------------- - metrics | {device} | {time} | {t} | {t} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +---------+----------------+-----------+---------+--------------+-------------------- + metrics | | {device} | {time} | {t} | {t} (1 row) SELECT * FROM chunk_settings; @@ -125,10 +125,10 @@ SELECT compress_chunk('_timescaledb_internal._hyper_1_2_chunk'); (1 row) SELECT * FROM settings; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst -------------------------------------------------+-----------+---------+--------------+-------------------- - metrics | {device} | {time} | {t} | {t} - _timescaledb_internal.compress_hyper_2_5_chunk | {device} | {time} | {t} | {t} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +----------------------------------------+------------------------------------------------+-----------+---------+--------------+-------------------- + metrics | | {device} | {time} | {t} | {t} + _timescaledb_internal._hyper_1_2_chunk | _timescaledb_internal.compress_hyper_2_5_chunk | {device} | {time} | {t} | {t} (2 rows) SELECT * FROM chunk_settings; @@ -140,8 +140,8 @@ SELECT * FROM chunk_settings; -- dropping hypertable should remove all settings DROP TABLE metrics; SELECT * FROM settings; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst --------+-----------+---------+--------------+-------------------- + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +-------+----------------+-----------+---------+--------------+-------------------- (0 rows) SELECT * FROM ht_settings; @@ -167,9 +167,9 @@ NOTICE: default segment by for hypertable "metrics" is set to "" NOTICE: default order by for hypertable "metrics" is set to ""time" DESC" -- hypertable should have default settings now SELECT * FROM settings; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst ----------+-----------+---------+--------------+-------------------- - metrics | | {time} | {t} | {t} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +---------+----------------+-----------+---------+--------------+-------------------- + metrics | | | {time} | {t} | {t} (1 row) SELECT * FROM ht_settings; @@ -183,9 +183,9 @@ INSERT INTO metrics VALUES ('2000-01-01'); ALTER TABLE metrics SET (timescaledb.compress_segmentby='d1'); -- settings should be updated SELECT * FROM settings; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst ----------+-----------+---------+--------------+-------------------- - metrics | {d1} | {time} | {t} | {t} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +---------+----------------+-----------+---------+--------------+-------------------- + metrics | | {d1} | {time} | {t} | {t} (1 row) SELECT * FROM ht_settings; @@ -202,10 +202,10 @@ SELECT compress_chunk(show_chunks('metrics')); -- settings for compressed chunk should be present SELECT * FROM settings; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst -------------------------------------------------+-----------+---------+--------------+-------------------- - metrics | {d1} | {time} | {t} | {t} - _timescaledb_internal.compress_hyper_4_7_chunk | {d1} | {time} | {t} | {t} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +----------------------------------------+------------------------------------------------+-----------+---------+--------------+-------------------- + metrics | | {d1} | {time} | {t} | {t} + _timescaledb_internal._hyper_3_6_chunk | _timescaledb_internal.compress_hyper_4_7_chunk | {d1} | {time} | {t} | {t} (2 rows) SELECT * FROM chunk_settings; @@ -217,10 +217,10 @@ SELECT * FROM chunk_settings; -- changing settings should update settings for hypertable but not existing compressed chunks ALTER TABLE metrics SET (timescaledb.compress_segmentby='d2'); SELECT * FROM settings; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst -------------------------------------------------+-----------+---------+--------------+-------------------- - metrics | {d2} | {time} | {t} | {t} - _timescaledb_internal.compress_hyper_4_7_chunk | {d1} | {time} | {t} | {t} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +----------------------------------------+------------------------------------------------+-----------+---------+--------------+-------------------- + metrics | | {d2} | {time} | {t} | {t} + _timescaledb_internal._hyper_3_6_chunk | _timescaledb_internal.compress_hyper_4_7_chunk | {d1} | {time} | {t} | {t} (2 rows) SELECT * FROM ht_settings; @@ -238,10 +238,10 @@ SELECT * FROM chunk_settings; -- changing settings should update settings for hypertable but not existing compressed chunks ALTER TABLE metrics SET (timescaledb.compress_segmentby=''); SELECT * FROM settings; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst -------------------------------------------------+-----------+---------+--------------+-------------------- - metrics | | {time} | {t} | {t} - _timescaledb_internal.compress_hyper_4_7_chunk | {d1} | {time} | {t} | {t} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +----------------------------------------+------------------------------------------------+-----------+---------+--------------+-------------------- + metrics | | | {time} | {t} | {t} + _timescaledb_internal._hyper_3_6_chunk | _timescaledb_internal.compress_hyper_4_7_chunk | {d1} | {time} | {t} | {t} (2 rows) SELECT * FROM ht_settings; @@ -267,11 +267,11 @@ NOTICE: chunk "_hyper_3_6_chunk" is already compressed (2 rows) SELECT * FROM settings; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst -------------------------------------------------+-----------+---------+--------------+-------------------- - metrics | | {time} | {t} | {t} - _timescaledb_internal.compress_hyper_4_7_chunk | {d1} | {time} | {t} | {t} - _timescaledb_internal.compress_hyper_4_9_chunk | | {time} | {t} | {t} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +----------------------------------------+------------------------------------------------+-----------+---------+--------------+-------------------- + metrics | | | {time} | {t} | {t} + _timescaledb_internal._hyper_3_6_chunk | _timescaledb_internal.compress_hyper_4_7_chunk | {d1} | {time} | {t} | {t} + _timescaledb_internal._hyper_3_8_chunk | _timescaledb_internal.compress_hyper_4_9_chunk | | {time} | {t} | {t} (3 rows) SELECT * FROM ht_settings; @@ -297,11 +297,11 @@ SELECT compress_chunk(:'CHUNK', recompress:=true); (1 row) SELECT * FROM settings; - relid | segmentby | orderby | orderby_desc | orderby_nullsfirst --------------------------------------------------+-----------+---------+--------------+-------------------- - metrics | {d2} | {time} | {t} | {t} - _timescaledb_internal.compress_hyper_4_10_chunk | {d2} | {time} | {t} | {t} - _timescaledb_internal.compress_hyper_4_7_chunk | {d1} | {time} | {t} | {t} + relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst +----------------------------------------+-------------------------------------------------+-----------+---------+--------------+-------------------- + metrics | | {d2} | {time} | {t} | {t} + _timescaledb_internal._hyper_3_6_chunk | _timescaledb_internal.compress_hyper_4_7_chunk | {d1} | {time} | {t} | {t} + _timescaledb_internal._hyper_3_8_chunk | _timescaledb_internal.compress_hyper_4_10_chunk | {d2} | {time} | {t} | {t} (3 rows) SELECT * FROM ht_settings; diff --git a/tsl/test/t/002_logrepl_decomp_marker.pl b/tsl/test/t/002_logrepl_decomp_marker.pl index 1ac46fb1ea5..a9401b8fd06 100644 --- a/tsl/test/t/002_logrepl_decomp_marker.pl +++ b/tsl/test/t/002_logrepl_decomp_marker.pl @@ -84,7 +84,7 @@ sub discard_wal qq(BEGIN message: transactional: 1 prefix: ::timescaledb-compression-start, sz: 0 content: table _timescaledb_catalog.chunk: INSERT: id[integer]:2 hypertable_id[integer]:2 schema_name[name]:'_timescaledb_internal' table_name[name]:'compress_hyper_2_2_chunk' compressed_chunk_id[integer]:null dropped[boolean]:false status[integer]:0 osm_chunk[boolean]:false -table _timescaledb_catalog.compression_settings: INSERT: relid[regclass]:'_timescaledb_internal.compress_hyper_2_2_chunk' segmentby[text[]]:'{device_id}' orderby[text[]]:'{time}' orderby_desc[boolean[]]:'{f}' orderby_nullsfirst[boolean[]]:'{f}' +table _timescaledb_catalog.compression_settings: INSERT: relid[regclass]:'_timescaledb_internal._hyper_1_1_chunk' compress_relid[regclass]:'_timescaledb_internal.compress_hyper_2_2_chunk' segmentby[text[]]:'{device_id}' orderby[text[]]:'{time}' orderby_desc[boolean[]]:'{f}' orderby_nullsfirst[boolean[]]:'{f}' table _timescaledb_internal.compress_hyper_2_2_chunk: INSERT: _ts_meta_count[integer]:1 _ts_meta_sequence_num[integer]:10 device_id[bigint]:1 _ts_meta_min_1[timestamp with time zone]:'2023-06-30 17:00:00-07' _ts_meta_max_1[timestamp with time zone]:'2023-06-30 17:00:00-07' "time"[_timescaledb_internal.compressed_data]:'BAAAAqJgYhxAAAAComBiHEAAAAAAAQAAAAEAAAAAAAAADgAFRMDEOIAA' value[_timescaledb_internal.compressed_data]:'AwA/8AAAAAAAAAAAAAEAAAABAAAAAAAAAAEAAAAAAAAAAQAAAAEAAAABAAAAAAAAAAEAAAAAAAAAAQAAAAEGAAAAAAAAAAIAAAABAAAAAQAAAAAAAAAEAAAAAAAAAAoAAAABCgAAAAAAAAP/' table _timescaledb_catalog.compression_chunk_size: INSERT: chunk_id[integer]:1 compressed_chunk_id[integer]:2 uncompressed_heap_size[bigint]:8192 uncompressed_toast_size[bigint]:0 uncompressed_index_size[bigint]:16384 compressed_heap_size[bigint]:16384 compressed_toast_size[bigint]:8192 compressed_index_size[bigint]:16384 numrows_pre_compression[bigint]:1 numrows_post_compression[bigint]:1 numrows_frozen_immediately[bigint]:1 table _timescaledb_catalog.chunk: UPDATE: id[integer]:1 hypertable_id[integer]:1 schema_name[name]:'_timescaledb_internal' table_name[name]:'_hyper_1_1_chunk' compressed_chunk_id[integer]:2 dropped[boolean]:false status[integer]:1 osm_chunk[boolean]:false @@ -100,7 +100,7 @@ sub discard_wal table _timescaledb_internal._hyper_1_1_chunk: INSERT: "time"[timestamp with time zone]:'2023-06-30 17:00:00-07' device_id[bigint]:1 value[double precision]:1 table _timescaledb_catalog.compression_chunk_size: DELETE: chunk_id[integer]:1 table _timescaledb_catalog.chunk: UPDATE: id[integer]:1 hypertable_id[integer]:1 schema_name[name]:'_timescaledb_internal' table_name[name]:'_hyper_1_1_chunk' compressed_chunk_id[integer]:null dropped[boolean]:false status[integer]:0 osm_chunk[boolean]:false -table _timescaledb_catalog.compression_settings: DELETE: relid[regclass]:'_timescaledb_internal.compress_hyper_2_2_chunk' +table _timescaledb_catalog.compression_settings: DELETE: relid[regclass]:'_timescaledb_internal._hyper_1_1_chunk' table _timescaledb_catalog.chunk: DELETE: id[integer]:2 message: transactional: 1 prefix: ::timescaledb-decompression-end, sz: 0 content: COMMIT) @@ -254,7 +254,7 @@ sub discard_wal table _timescaledb_internal._hyper_1_1_chunk: INSERT: "time"[timestamp with time zone]:'2023-07-01 05:00:00-07' device_id[bigint]:1 value[double precision]:2 table _timescaledb_catalog.compression_chunk_size: DELETE: chunk_id[integer]:1 table _timescaledb_catalog.chunk: UPDATE: id[integer]:1 hypertable_id[integer]:1 schema_name[name]:'_timescaledb_internal' table_name[name]:'_hyper_1_1_chunk' compressed_chunk_id[integer]:null dropped[boolean]:false status[integer]:0 osm_chunk[boolean]:false -table _timescaledb_catalog.compression_settings: DELETE: relid[regclass]:'_timescaledb_internal.compress_hyper_3_4_chunk' +table _timescaledb_catalog.compression_settings: DELETE: relid[regclass]:'_timescaledb_internal._hyper_1_1_chunk' table _timescaledb_catalog.chunk: DELETE: id[integer]:4 COMMIT) );