-
Notifications
You must be signed in to change notification settings - Fork 889
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor compression setting storage
This patch drops the catalog table _timescaledb_catalog.hypertable_compression and stores those settings in _timescaledb_catalog.compression_settings instead. The storage format is changed and the new table will have 1 entry per relation instead of 1 entry per column and has no dependancy on hypertables. All other aspects of compression will remain the same. This is refactoring is to enable per chunk compression settings in a follow-up patch.
- Loading branch information
Showing
47 changed files
with
1,752 additions
and
1,876 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,3 +43,34 @@ DROP FUNCTION IF EXISTS @[email protected]_data_node; | |
DROP PROCEDURE IF EXISTS @[email protected]_exec; | ||
DROP FUNCTION IF EXISTS @[email protected]_distributed_restore_point; | ||
DROP FUNCTION IF EXISTS @[email protected]_replication_factor; | ||
|
||
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 INTO _timescaledb_catalog.compression_settings(relid, segmentby, orderby, orderby_desc, orderby_nullsfirst) | ||
SELECT | ||
format('%I.%I', ht.schema_name, ht.table_name)::regclass, | ||
array_agg(attname ORDER BY segmentby_column_index) FILTER(WHERE segmentby_column_index >= 1) AS compress_segmentby, | ||
array_agg(attname ORDER BY orderby_column_index) FILTER(WHERE orderby_column_index >= 1) AS compress_orderby, | ||
array_agg(NOT orderby_asc ORDER BY orderby_column_index) FILTER(WHERE orderby_column_index >= 1) AS compress_orderby_desc, | ||
array_agg(orderby_nullsfirst ORDER BY orderby_column_index) FILTER(WHERE orderby_column_index >= 1) AS compress_orderby_nullsfirst | ||
FROM _timescaledb_catalog.hypertable_compression hc | ||
INNER JOIN _timescaledb_catalog.hypertable ht ON ht.id = hc.hypertable_id | ||
GROUP BY hypertable_id, ht.schema_name, ht.table_name; | ||
|
||
GRANT SELECT ON _timescaledb_catalog.compression_settings TO PUBLIC; | ||
SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.compression_settings', ''); | ||
|
||
ALTER EXTENSION timescaledb DROP TABLE _timescaledb_catalog.hypertable_compression; | ||
DROP VIEW IF EXISTS timescaledb_information.compression_settings; | ||
DROP TABLE _timescaledb_catalog.hypertable_compression; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,3 +141,53 @@ CREATE FUNCTION @[email protected]_replication_factor( | |
) RETURNS VOID | ||
AS '@MODULE_PATHNAME@', 'ts_hypertable_distributed_set_replication_factor' LANGUAGE C VOLATILE; | ||
|
||
CREATE TABLE _timescaledb_catalog.hypertable_compression ( | ||
hypertable_id integer NOT NULL, | ||
attname name NOT NULL, | ||
compression_algorithm_id smallint, | ||
segmentby_column_index smallint, | ||
orderby_column_index smallint, | ||
orderby_asc boolean, | ||
orderby_nullsfirst boolean, | ||
-- table constraints | ||
CONSTRAINT hypertable_compression_pkey PRIMARY KEY (hypertable_id, attname), | ||
CONSTRAINT hypertable_compression_hypertable_id_orderby_column_index_key UNIQUE (hypertable_id, orderby_column_index), | ||
CONSTRAINT hypertable_compression_hypertable_id_segmentby_column_index_key UNIQUE (hypertable_id, segmentby_column_index), | ||
CONSTRAINT hypertable_compression_compression_algorithm_id_fkey FOREIGN KEY (compression_algorithm_id) REFERENCES _timescaledb_catalog.compression_algorithm (id), | ||
CONSTRAINT hypertable_compression_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable (id) ON DELETE CASCADE | ||
); | ||
|
||
INSERT INTO _timescaledb_catalog.hypertable_compression( | ||
hypertable_id, | ||
attname, | ||
compression_algorithm_id, | ||
segmentby_column_index, | ||
orderby_column_index, | ||
orderby_asc, | ||
orderby_nullsfirst | ||
) SELECT | ||
ht.id, | ||
att.attname, | ||
CASE | ||
WHEN att.attname = ANY(cs.segmentby) THEN 0 | ||
WHEN att.atttypid IN ('numeric'::regtype) THEN 1 | ||
WHEN att.atttypid IN ('float4'::regtype,'float8'::regtype) THEN 3 | ||
WHEN att.atttypid IN ('int2'::regtype,'int4'::regtype,'int8'::regtype,'date'::regtype,'timestamp'::regtype,'timestamptz'::regtype) THEN 4 | ||
WHEN EXISTS(SELECT FROM pg_operator op WHERE op.oprname = '=' AND op.oprkind = 'b' AND op.oprcanhash = true AND op.oprleft = att.atttypid AND op.oprright = att.atttypid) THEN 2 | ||
ELSE 1 | ||
END AS compression_algorithm_id, | ||
CASE WHEN att.attname = ANY(cs.segmentby) THEN array_position(cs.segmentby, att.attname::text) ELSE NULL END AS segmentby_column_index, | ||
CASE WHEN att.attname = ANY(cs.orderby) THEN array_position(cs.orderby, att.attname::text) ELSE NULL END AS orderby_column_index, | ||
CASE WHEN att.attname = ANY(cs.orderby) THEN NOT cs.orderby_desc[array_position(cs.orderby, att.attname::text)] ELSE false END AS orderby_asc, | ||
CASE WHEN att.attname = ANY(cs.orderby) THEN cs.orderby_nullsfirst[array_position(cs.orderby, att.attname::text)] ELSE false END AS orderby_nullsfirst | ||
FROM _timescaledb_catalog.hypertable ht | ||
INNER JOIN _timescaledb_catalog.compression_settings cs ON cs.relid = format('%I.%I',ht.schema_name,ht.table_name)::regclass | ||
LEFT JOIN pg_attribute att ON att.attrelid = format('%I.%I',ht.schema_name,ht.table_name)::regclass AND attnum > 0 | ||
WHERE compressed_hypertable_id IS NOT NULL; | ||
|
||
SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.hypertable_compression', ''); | ||
GRANT SELECT ON _timescaledb_catalog.hypertable_compression TO PUBLIC; | ||
|
||
DROP VIEW timescaledb_information.compression_settings; | ||
ALTER EXTENSION timescaledb DROP TABLE _timescaledb_catalog.compression_settings; | ||
DROP TABLE _timescaledb_catalog.compression_settings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.