-
Notifications
You must be signed in to change notification settings - Fork 848
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add catalog entries for correlated constraint
Create dimension_slice and chunk_constraint entries for chunks which have correlated constraints on them. The dimension slice entry will have -inf/+inf as start/end range initially for a given correlated constraint and the chunk_constraint entry will refer back to this slice entry. This start/end range will be refreshed later. One of the entry points is during compression for now.
- Loading branch information
Showing
32 changed files
with
538 additions
and
79 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,5 +182,90 @@ CREATE OR REPLACE FUNCTION @[email protected]_dimension( | |
) RETURNS TABLE(dimension_id INT, schema_name NAME, table_name NAME, column_name NAME, created BOOL) | ||
AS '@MODULE_PATHNAME@', 'ts_dimension_add' LANGUAGE C VOLATILE; | ||
|
||
ALTER TABLE _timescaledb_catalog.dimension ADD COLUMN correlated BOOLEAN; | ||
UPDATE _timescaledb_catalog.dimension SET correlated = FALSE; | ||
|
||
-- | ||
-- Rebuild the catalog table `_timescaledb_catalog.dimension with correlated column | ||
-- | ||
|
||
CREATE TABLE _timescaledb_internal.dimension_tmp | ||
AS SELECT * from _timescaledb_catalog.dimension; | ||
|
||
CREATE TABLE _timescaledb_internal.tmp_dimension_seq_value AS | ||
SELECT last_value, is_called FROM _timescaledb_catalog.dimension_id_seq; | ||
|
||
--drop foreign keys on dimension table | ||
ALTER TABLE _timescaledb_catalog.dimension_slice DROP CONSTRAINT | ||
dimension_slice_dimension_id_fkey; | ||
|
||
--drop dependent views | ||
DROP VIEW IF EXISTS timescaledb_information.chunks; | ||
DROP VIEW IF EXISTS timescaledb_information.dimensions; | ||
DROP VIEW IF EXISTS timescaledb_information.hypertable_compression_settings; | ||
|
||
ALTER EXTENSION timescaledb DROP TABLE _timescaledb_catalog.dimension; | ||
ALTER EXTENSION timescaledb DROP SEQUENCE _timescaledb_catalog.dimension_id_seq; | ||
DROP TABLE _timescaledb_catalog.dimension; | ||
|
||
CREATE TABLE _timescaledb_catalog.dimension ( | ||
id serial NOT NULL , | ||
hypertable_id integer NOT NULL, | ||
column_name name NOT NULL, | ||
column_type REGTYPE NOT NULL, | ||
aligned boolean NOT NULL, | ||
-- closed dimensions | ||
num_slices smallint NULL, | ||
partitioning_func_schema name NULL, | ||
partitioning_func name NULL, | ||
-- open dimensions (e.g., time) | ||
interval_length bigint NULL, | ||
-- compress interval is used by rollup procedure during compression | ||
-- in order to merge multiple chunks into a single one | ||
compress_interval_length bigint NULL, | ||
integer_now_func_schema name NULL, | ||
integer_now_func name NULL, | ||
correlated boolean NOT NULL, | ||
-- table constraints | ||
CONSTRAINT dimension_pkey PRIMARY KEY (id), | ||
CONSTRAINT dimension_hypertable_id_column_name_key UNIQUE (hypertable_id, column_name), | ||
CONSTRAINT dimension_check CHECK ((partitioning_func_schema IS NULL AND partitioning_func IS NULL) OR (partitioning_func_schema IS NOT NULL AND partitioning_func IS NOT NULL)), | ||
CONSTRAINT dimension_check1 CHECK ((num_slices IS NULL AND interval_length IS NOT NULL) OR (num_slices IS NOT NULL AND interval_length IS NULL)), | ||
CONSTRAINT dimension_check2 CHECK ((integer_now_func_schema IS NULL AND integer_now_func IS NULL) OR (integer_now_func_schema IS NOT NULL AND integer_now_func IS NOT NULL)), | ||
CONSTRAINT dimension_interval_length_check CHECK (interval_length IS NULL OR interval_length > 0 OR correlated IS true), | ||
CONSTRAINT dimension_compress_interval_length_check CHECK (compress_interval_length IS NULL OR compress_interval_length > 0), | ||
CONSTRAINT dimension_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable (id) ON DELETE CASCADE | ||
); | ||
|
||
INSERT INTO _timescaledb_catalog.dimension | ||
( id, hypertable_id, column_name, column_type, | ||
aligned, num_slices, partitioning_func_schema, | ||
partitioning_func, interval_length, | ||
compress_interval_length, | ||
integer_now_func_schema, integer_now_func, | ||
correlated) | ||
SELECT id, hypertable_id, column_name, column_type, | ||
aligned, num_slices, partitioning_func_schema, | ||
partitioning_func, interval_length, | ||
compress_interval_length, | ||
integer_now_func_schema, integer_now_func, | ||
false AS correlated | ||
FROM _timescaledb_internal.dimension_tmp; | ||
|
||
ALTER SEQUENCE _timescaledb_catalog.dimension_id_seq OWNED BY _timescaledb_catalog.dimension.id; | ||
SELECT setval('_timescaledb_catalog.dimension_id_seq', last_value, is_called) FROM _timescaledb_internal.tmp_dimension_seq_value; | ||
|
||
SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.dimension', ''); | ||
SELECT pg_catalog.pg_extension_config_dump(pg_get_serial_sequence('_timescaledb_catalog.dimension', 'id'), ''); | ||
|
||
--add the foreign key constraints | ||
ALTER TABLE _timescaledb_catalog.dimension_slice ADD CONSTRAINT | ||
dimension_slice_dimension_id_fkey FOREIGN KEY (dimension_id) | ||
REFERENCES _timescaledb_catalog.dimension(id) ON DELETE CASCADE; | ||
|
||
--cleanup | ||
DROP TABLE _timescaledb_internal.dimension_tmp; | ||
DROP TABLE _timescaledb_internal.tmp_dimension_seq_value; | ||
|
||
GRANT SELECT ON _timescaledb_catalog.dimension_id_seq TO PUBLIC; | ||
GRANT SELECT ON _timescaledb_catalog.dimension TO PUBLIC; | ||
|
||
-- end recreate _timescaledb_catalog.dimension table -- |
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 |
---|---|---|
|
@@ -90,5 +90,83 @@ CREATE OR REPLACE FUNCTION @[email protected]_dimension( | |
) RETURNS TABLE(dimension_id INT, schema_name NAME, table_name NAME, column_name NAME, created BOOL) | ||
AS '@MODULE_PATHNAME@', 'ts_dimension_add' LANGUAGE C VOLATILE; | ||
|
||
DELETE FROM _timescaledb_catalog.dimension WHERE correlated IS TRUE; | ||
ALTER TABLE _timescaledb_catalog.dimension DROP COLUMN correlated; | ||
-- Recreate _timescaledb_catalog.dimension table without the crrelated column -- | ||
CREATE TABLE _timescaledb_internal.dimension_tmp | ||
AS SELECT * from _timescaledb_catalog.dimension; | ||
|
||
CREATE TABLE _timescaledb_internal.tmp_dimension_seq_value AS | ||
SELECT last_value, is_called FROM _timescaledb_catalog.dimension_id_seq; | ||
|
||
--drop foreign keys on dimension table | ||
ALTER TABLE _timescaledb_catalog.dimension_slice DROP CONSTRAINT | ||
dimension_slice_dimension_id_fkey; | ||
|
||
--drop dependent views | ||
DROP VIEW IF EXISTS timescaledb_information.chunks; | ||
DROP VIEW IF EXISTS timescaledb_information.dimensions; | ||
DROP VIEW IF EXISTS timescaledb_information.hypertable_compression_settings; | ||
|
||
ALTER EXTENSION timescaledb DROP TABLE _timescaledb_catalog.dimension; | ||
ALTER EXTENSION timescaledb DROP SEQUENCE _timescaledb_catalog.dimension_id_seq; | ||
DROP TABLE _timescaledb_catalog.dimension; | ||
|
||
CREATE TABLE _timescaledb_catalog.dimension ( | ||
id serial NOT NULL , | ||
hypertable_id integer NOT NULL, | ||
column_name name NOT NULL, | ||
column_type REGTYPE NOT NULL, | ||
aligned boolean NOT NULL, | ||
-- closed dimensions | ||
num_slices smallint NULL, | ||
partitioning_func_schema name NULL, | ||
partitioning_func name NULL, | ||
-- open dimensions (e.g., time) | ||
interval_length bigint NULL, | ||
-- compress interval is used by rollup procedure during compression | ||
-- in order to merge multiple chunks into a single one | ||
compress_interval_length bigint NULL, | ||
integer_now_func_schema name NULL, | ||
integer_now_func name NULL, | ||
-- table constraints | ||
CONSTRAINT dimension_pkey PRIMARY KEY (id), | ||
CONSTRAINT dimension_hypertable_id_column_name_key UNIQUE (hypertable_id, column_name), | ||
CONSTRAINT dimension_check CHECK ((partitioning_func_schema IS NULL AND partitioning_func IS NULL) OR (partitioning_func_schema IS NOT NULL AND partitioning_func IS NOT NULL)), | ||
CONSTRAINT dimension_check1 CHECK ((num_slices IS NULL AND interval_length IS NOT NULL) OR (num_slices IS NOT NULL AND interval_length IS NULL)), | ||
CONSTRAINT dimension_check2 CHECK ((integer_now_func_schema IS NULL AND integer_now_func IS NULL) OR (integer_now_func_schema IS NOT NULL AND integer_now_func IS NOT NULL)), | ||
CONSTRAINT dimension_interval_length_check CHECK (interval_length IS NULL OR interval_length > 0), | ||
CONSTRAINT dimension_compress_interval_length_check CHECK (compress_interval_length IS NULL OR compress_interval_length > 0), | ||
CONSTRAINT dimension_hypertable_id_fkey FOREIGN KEY (hypertable_id) REFERENCES _timescaledb_catalog.hypertable (id) ON DELETE CASCADE | ||
); | ||
|
||
INSERT INTO _timescaledb_catalog.dimension | ||
( id, hypertable_id, column_name, column_type, | ||
aligned, num_slices, partitioning_func_schema, | ||
partitioning_func, interval_length, | ||
compress_interval_length, | ||
integer_now_func_schema, integer_now_func) | ||
SELECT id, hypertable_id, column_name, column_type, | ||
aligned, num_slices, partitioning_func_schema, | ||
partitioning_func, interval_length, | ||
compress_interval_length, | ||
integer_now_func_schema, integer_now_func | ||
FROM _timescaledb_internal.dimension_tmp; | ||
|
||
ALTER SEQUENCE _timescaledb_catalog.dimension_id_seq OWNED BY _timescaledb_catalog.dimension.id; | ||
SELECT setval('_timescaledb_catalog.dimension_id_seq', last_value, is_called) FROM _timescaledb_internal.tmp_dimension_seq_value; | ||
|
||
SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.dimension', ''); | ||
SELECT pg_catalog.pg_extension_config_dump(pg_get_serial_sequence('_timescaledb_catalog.dimension', 'id'), ''); | ||
|
||
--add the foreign key constraints | ||
ALTER TABLE _timescaledb_catalog.dimension_slice ADD CONSTRAINT | ||
dimension_slice_dimension_id_fkey FOREIGN KEY (dimension_id) | ||
REFERENCES _timescaledb_catalog.dimension(id) ON DELETE CASCADE; | ||
|
||
--cleanup | ||
DROP TABLE _timescaledb_internal.dimension_tmp; | ||
DROP TABLE _timescaledb_internal.tmp_dimension_seq_value; | ||
|
||
GRANT SELECT ON _timescaledb_catalog.dimension_id_seq TO PUBLIC; | ||
GRANT SELECT ON _timescaledb_catalog.dimension TO PUBLIC; | ||
|
||
-- end recreate _timescaledb_catalog.dimension table -- |
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.