-
Notifications
You must be signed in to change notification settings - Fork 882
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
27 changed files
with
436 additions
and
267 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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
-- Update compression settings | ||
|
||
CREATE TEMP TABLE tempsettings (LIKE _timescaledb_catalog.compression_settings); | ||
INSERT INTO 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 | ||
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 | ||
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 tempsettings CASCADE; -- not strictly necessary | ||
GRANT SELECT ON _timescaledb_catalog.compression_settings TO PUBLIC; | ||
SELECT pg_catalog.pg_extension_config_dump('_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
-- Update compression settings | ||
CREATE TEMP TABLE tempsettings (LIKE _timescaledb_catalog.compression_settings); | ||
INSERT INTO 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 | ||
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 | ||
tempsettings cs | ||
WHERE | ||
cs.compress_relid IS NULL; | ||
|
||
DROP TABLE tempsettings CASCADE; | ||
GRANT SELECT ON _timescaledb_catalog.compression_settings TO PUBLIC; | ||
SELECT pg_catalog.pg_extension_config_dump('_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
Oops, something went wrong.