From 926a1c9850b949915f908fd6ded6eaf564343e38 Mon Sep 17 00:00:00 2001 From: gayyappan Date: Wed, 15 Jul 2020 13:06:05 -0400 Subject: [PATCH] Add compression settings view Add informational view that lists the settings used while enabling compression on a hypertable. --- sql/views.sql | 23 ++++++++++++++++++++ test/expected/pg_dump.out | 3 ++- tsl/test/expected/compression.out | 35 +++++++++++++++++++++++++++++++ tsl/test/sql/compression.sql | 2 ++ 4 files changed, 62 insertions(+), 1 deletion(-) diff --git a/sql/views.sql b/sql/views.sql index 51605310b..af3bd144d 100644 --- a/sql/views.sql +++ b/sql/views.sql @@ -259,5 +259,28 @@ CREATE OR REPLACE VIEW timescaledb_information.data_node AS LEFT OUTER JOIN LATERAL @extschema@.data_node_hypertable_info(CASE WHEN s.node_up THEN s.node_name ELSE NULL END) size ON TRUE GROUP BY s.node_name, s.node_up, s.owner, s.options; +---compression parameters information --- +CREATE VIEW timescaledb_information.compression_settings +AS +SELECT + ht.schema_name, + ht.table_name, + segq.attname, + segq.segmentby_column_index, + segq.orderby_column_index, + segq.orderby_asc, + segq.orderby_nullsfirst +FROM + _timescaledb_catalog.hypertable_compression segq, + _timescaledb_catalog.hypertable ht +WHERE + segq.hypertable_id = ht.id + AND ( segq.segmentby_column_index IS NOT NULL + OR segq.orderby_column_index IS NOT NULL) +ORDER BY + table_name, + segmentby_column_index, + orderby_column_index; + GRANT USAGE ON SCHEMA timescaledb_information TO PUBLIC; GRANT SELECT ON ALL TABLES IN SCHEMA timescaledb_information TO PUBLIC; diff --git a/test/expected/pg_dump.out b/test/expected/pg_dump.out index a368b320e..c5255cd3e 100644 --- a/test/expected/pg_dump.out +++ b/test/expected/pg_dump.out @@ -535,6 +535,7 @@ WHERE refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass AND ORDER BY objid::text DESC; objid ----------------------------------------------------- + timescaledb_information.compression_settings timescaledb_information.data_node timescaledb_information.compressed_hypertable_stats timescaledb_information.compressed_chunk_stats @@ -550,7 +551,7 @@ WHERE refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass AND _timescaledb_internal.bgw_policy_chunk_stats _timescaledb_internal.bgw_job_stat _timescaledb_catalog.tablespace_id_seq -(15 rows) +(16 rows) -- Make sure we can't run our restoring functions as a normal perm user as that would disable functionality for the whole db \c :TEST_DBNAME :ROLE_DEFAULT_PERM_USER diff --git a/tsl/test/expected/compression.out b/tsl/test/expected/compression.out index 28c553857..82810f5c5 100644 --- a/tsl/test/expected/compression.out +++ b/tsl/test/expected/compression.out @@ -63,6 +63,15 @@ select * from _timescaledb_catalog.hypertable_compression order by hypertable_id 1 | d | 4 | | 2 | t | f (4 rows) +select * from timescaledb_information.compression_settings ; + schema_name | table_name | attname | segmentby_column_index | orderby_column_index | orderby_asc | orderby_nullsfirst +-------------+------------+---------+------------------------+----------------------+-------------+-------------------- + public | foo | a | 1 | | | + public | foo | b | 2 | | | + public | foo | c | | 1 | f | t + public | foo | d | | 2 | t | f +(4 rows) + -- TEST2 compress-chunk for the chunks created earlier -- select compress_chunk( '_timescaledb_internal._hyper_1_2_chunk'); compress_chunk @@ -1124,6 +1133,32 @@ ERROR: constraint "fk_table1" requires column "col2" to be a timescaledb.compre ALTER TABLE table1 SET (timescaledb.compress, timescaledb.compress_segmentby = 'col1,col2'); NOTICE: adding index _compressed_hypertable_23_col1__ts_meta_sequence_num_idx ON _timescaledb_internal._compressed_hypertable_23 USING BTREE(col1, _ts_meta_sequence_num) NOTICE: adding index _compressed_hypertable_23_col2__ts_meta_sequence_num_idx ON _timescaledb_internal._compressed_hypertable_23 USING BTREE(col2, _ts_meta_sequence_num) +SELECT * FROM timescaledb_information.compression_settings ORDER BY table_name; + schema_name | table_name | attname | segmentby_column_index | orderby_column_index | orderby_asc | orderby_nullsfirst +-------------+----------------+-------------+------------------------+----------------------+-------------+-------------------- + public | conditions | location | 1 | | | + public | conditions | time | | 1 | t | f + public | datatype_test | time | | 1 | f | t + public | foo | a | 1 | | | + public | foo | b | 2 | | | + public | foo | c | | 1 | f | t + public | foo | d | | 2 | t | f + public | ht5 | time | | 1 | f | t + public | hyper | device_id | 1 | | | + public | hyper | time | | 1 | t | f + public | metrics | time | | 1 | f | t + public | plan_inval | time | | 1 | f | t + public | rescan_test | id | 1 | | | + public | rescan_test | t | | 1 | f | t + public | table1 | col1 | 1 | | | + public | table1 | col2 | 2 | | | + public | test_collation | device_id | 1 | | | + public | test_collation | device_id_2 | 2 | | | + public | test_collation | val_1 | | 1 | t | f + public | test_collation | val_2 | | 2 | t | f + public | test_collation | time | | 3 | t | f +(21 rows) + -- test delete/update on non-compressed tables involving hypertables with compression CREATE TABLE uncompressed_ht ( time timestamptz NOT NULL, diff --git a/tsl/test/sql/compression.sql b/tsl/test/sql/compression.sql index 49f44fbb4..921ee3e06 100644 --- a/tsl/test/sql/compression.sql +++ b/tsl/test/sql/compression.sql @@ -29,6 +29,7 @@ SET timescaledb.enable_transparent_decompression to OFF; select id, schema_name, table_name, compressed, compressed_hypertable_id from _timescaledb_catalog.hypertable order by id; select * from _timescaledb_catalog.hypertable_compression order by hypertable_id, attname; +select * from timescaledb_information.compression_settings ; -- TEST2 compress-chunk for the chunks created earlier -- select compress_chunk( '_timescaledb_internal._hyper_1_2_chunk'); @@ -451,6 +452,7 @@ SELECT create_hypertable('table1','col1', chunk_time_interval => 10); ALTER TABLE table1 SET (timescaledb.compress, timescaledb.compress_segmentby = 'col1'); -- Listing all fields of the compound key should succeed: ALTER TABLE table1 SET (timescaledb.compress, timescaledb.compress_segmentby = 'col1,col2'); +SELECT * FROM timescaledb_information.compression_settings ORDER BY table_name; -- test delete/update on non-compressed tables involving hypertables with compression CREATE TABLE uncompressed_ht (