Skip to content

Commit 440af4f

Browse files
Remove time bucket function metadata table
Co-authored-by: Fabrízio de Royes Mello <[email protected]>
1 parent 709131f commit 440af4f

39 files changed

+1644
-1953
lines changed

sql/pre_install/tables.sql

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -387,29 +387,6 @@ CREATE INDEX continuous_agg_raw_hypertable_id_idx ON _timescaledb_catalog.contin
387387

388388
SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.continuous_agg', '');
389389

390-
-- See the comments for ContinuousAggsBucketFunction structure.
391-
CREATE TABLE _timescaledb_catalog.continuous_aggs_bucket_function (
392-
mat_hypertable_id integer NOT NULL,
393-
-- The bucket function
394-
bucket_func text NOT NULL,
395-
-- `bucket_width` argument of the function, e.g. "1 month"
396-
bucket_width text NOT NULL,
397-
-- optional `origin` argument of the function provided by the user
398-
bucket_origin text,
399-
-- optional `offset` argument of the function provided by the user
400-
bucket_offset text,
401-
-- optional `timezone` argument of the function provided by the user
402-
bucket_timezone text,
403-
-- fixed or variable sized bucket
404-
bucket_fixed_width bool NOT NULL,
405-
-- table constraints
406-
CONSTRAINT continuous_aggs_bucket_function_pkey PRIMARY KEY (mat_hypertable_id),
407-
CONSTRAINT continuous_aggs_bucket_function_mat_hypertable_id_fkey FOREIGN KEY (mat_hypertable_id) REFERENCES _timescaledb_catalog.hypertable (id) ON DELETE CASCADE,
408-
CONSTRAINT continuous_aggs_bucket_function_func_check CHECK (pg_catalog.to_regprocedure(bucket_func) IS DISTINCT FROM 0)
409-
);
410-
411-
SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.continuous_aggs_bucket_function', '');
412-
413390
CREATE TABLE _timescaledb_catalog.continuous_aggs_invalidation_threshold (
414391
hypertable_id integer NOT NULL,
415392
watermark bigint NOT NULL,

sql/updates/latest-dev.sql

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
-- remove obsolete job
2+
DELETE FROM _timescaledb_config.bgw_job WHERE id = 2;
3+
4+
-- Hypercore updates
5+
CREATE FUNCTION _timescaledb_debug.is_compressed_tid(tid) RETURNS BOOL
6+
AS '@MODULE_PATHNAME@', 'ts_update_placeholder' LANGUAGE C STRICT;
7+
8+
DROP FUNCTION IF EXISTS @[email protected]_chunk(uncompressed_chunk REGCLASS, if_not_compressed BOOLEAN, recompress BOOLEAN);
9+
10+
CREATE FUNCTION @[email protected]_chunk(
11+
uncompressed_chunk REGCLASS,
12+
if_not_compressed BOOLEAN = true,
13+
recompress BOOLEAN = false,
14+
hypercore_use_access_method BOOL = NULL
15+
) RETURNS REGCLASS AS '@MODULE_PATHNAME@', 'ts_update_placeholder' LANGUAGE C VOLATILE;
16+
17+
DROP FUNCTION IF EXISTS @[email protected]_compression_policy(hypertable REGCLASS, compress_after "any", if_not_exists BOOL, schedule_interval INTERVAL, initial_start TIMESTAMPTZ, timezone TEXT, compress_created_before INTERVAL);
18+
19+
CREATE FUNCTION @[email protected]_compression_policy(
20+
hypertable REGCLASS,
21+
compress_after "any" = NULL,
22+
if_not_exists BOOL = false,
23+
schedule_interval INTERVAL = NULL,
24+
initial_start TIMESTAMPTZ = NULL,
25+
timezone TEXT = NULL,
26+
compress_created_before INTERVAL = NULL,
27+
hypercore_use_access_method BOOL = NULL
28+
)
29+
RETURNS INTEGER
30+
AS '@MODULE_PATHNAME@', 'ts_update_placeholder'
31+
LANGUAGE C VOLATILE;
32+
33+
DROP FUNCTION IF EXISTS timescaledb_experimental.add_policies(relation REGCLASS, if_not_exists BOOL, refresh_start_offset "any", refresh_end_offset "any", compress_after "any", drop_after "any");
34+
35+
CREATE FUNCTION timescaledb_experimental.add_policies(
36+
relation REGCLASS,
37+
if_not_exists BOOL = false,
38+
refresh_start_offset "any" = NULL,
39+
refresh_end_offset "any" = NULL,
40+
compress_after "any" = NULL,
41+
drop_after "any" = NULL,
42+
hypercore_use_access_method BOOL = NULL)
43+
RETURNS BOOL
44+
AS '@MODULE_PATHNAME@', 'ts_update_placeholder'
45+
LANGUAGE C VOLATILE;
46+
47+
DROP PROCEDURE IF EXISTS _timescaledb_functions.policy_compression_execute(job_id INTEGER, htid INTEGER, lag ANYELEMENT, maxchunks INTEGER, verbose_log BOOLEAN, recompress_enabled BOOLEAN, use_creation_time BOOLEAN);
48+
49+
DROP PROCEDURE IF EXISTS _timescaledb_functions.policy_compression(job_id INTEGER, config JSONB);
50+
51+
CREATE PROCEDURE @[email protected]_to_columnstore(
52+
chunk REGCLASS,
53+
if_not_columnstore BOOLEAN = true,
54+
recompress BOOLEAN = false,
55+
hypercore_use_access_method BOOL = NULL)
56+
AS '@MODULE_PATHNAME@', 'ts_update_placeholder'
57+
LANGUAGE C;
58+
59+
CREATE PROCEDURE @[email protected]_to_rowstore(
60+
chunk REGCLASS,
61+
if_columnstore BOOLEAN = true)
62+
AS '@MODULE_PATHNAME@', 'ts_update_placeholder'
63+
LANGUAGE C;
64+
65+
CREATE PROCEDURE @[email protected]_columnstore_policy(
66+
hypertable REGCLASS,
67+
after "any" = NULL,
68+
if_not_exists BOOL = false,
69+
schedule_interval INTERVAL = NULL,
70+
initial_start TIMESTAMPTZ = NULL,
71+
timezone TEXT = NULL,
72+
created_before INTERVAL = NULL,
73+
hypercore_use_access_method BOOL = NULL
74+
) LANGUAGE C AS '@MODULE_PATHNAME@', 'ts_update_placeholder';
75+
76+
CREATE PROCEDURE @[email protected]_columnstore_policy(
77+
hypertable REGCLASS,
78+
if_exists BOOL = false
79+
) LANGUAGE C AS '@MODULE_PATHNAME@', 'ts_update_placeholder';
80+
81+
CREATE FUNCTION @[email protected]_columnstore_stats (hypertable REGCLASS)
82+
RETURNS TABLE (
83+
chunk_schema name,
84+
chunk_name name,
85+
compression_status text,
86+
before_compression_table_bytes bigint,
87+
before_compression_index_bytes bigint,
88+
before_compression_toast_bytes bigint,
89+
before_compression_total_bytes bigint,
90+
after_compression_table_bytes bigint,
91+
after_compression_index_bytes bigint,
92+
after_compression_toast_bytes bigint,
93+
after_compression_total_bytes bigint,
94+
node_name name)
95+
LANGUAGE SQL
96+
STABLE STRICT
97+
AS 'SELECT * FROM @[email protected]_compression_stats($1)'
98+
SET search_path TO pg_catalog, pg_temp;
99+
100+
CREATE FUNCTION @[email protected]_columnstore_stats (hypertable REGCLASS)
101+
RETURNS TABLE (
102+
total_chunks bigint,
103+
number_compressed_chunks bigint,
104+
before_compression_table_bytes bigint,
105+
before_compression_index_bytes bigint,
106+
before_compression_toast_bytes bigint,
107+
before_compression_total_bytes bigint,
108+
after_compression_table_bytes bigint,
109+
after_compression_index_bytes bigint,
110+
after_compression_toast_bytes bigint,
111+
after_compression_total_bytes bigint,
112+
node_name name)
113+
LANGUAGE SQL
114+
STABLE STRICT
115+
AS 'SELECT * FROM @[email protected]_compression_stats($1)'
116+
SET search_path TO pg_catalog, pg_temp;
117+
118+
-- Remove useless catalog metadata
119+
ALTER EXTENSION timescaledb
120+
DROP TABLE _timescaledb_catalog.continuous_aggs_bucket_function;
121+
122+
DROP TABLE _timescaledb_catalog.continuous_aggs_bucket_function;

sql/updates/reverse-dev.sql

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
-- Hypercore AM
2+
DROP ACCESS METHOD IF EXISTS hypercore_proxy;
3+
DROP FUNCTION IF EXISTS ts_hypercore_proxy_handler;
4+
DROP ACCESS METHOD IF EXISTS hypercore;
5+
DROP FUNCTION IF EXISTS ts_hypercore_handler;
6+
DROP FUNCTION IF EXISTS _timescaledb_debug.is_compressed_tid;
7+
8+
DROP FUNCTION IF EXISTS @[email protected]_chunk(uncompressed_chunk REGCLASS, if_not_compressed BOOLEAN, recompress BOOLEAN, hypercore_use_access_method BOOL);
9+
10+
CREATE FUNCTION @[email protected]_chunk(
11+
uncompressed_chunk REGCLASS,
12+
if_not_compressed BOOLEAN = true,
13+
recompress BOOLEAN = false
14+
) RETURNS REGCLASS AS '@MODULE_PATHNAME@', 'ts_compress_chunk' LANGUAGE C STRICT VOLATILE;
15+
16+
DROP FUNCTION IF EXISTS @[email protected]_compression_policy(hypertable REGCLASS, compress_after "any", if_not_exists BOOL, schedule_interval INTERVAL, initial_start TIMESTAMPTZ, timezone TEXT, compress_created_before INTERVAL, hypercore_use_access_method BOOL);
17+
18+
CREATE FUNCTION @[email protected]_compression_policy(
19+
hypertable REGCLASS,
20+
compress_after "any" = NULL,
21+
if_not_exists BOOL = false,
22+
schedule_interval INTERVAL = NULL,
23+
initial_start TIMESTAMPTZ = NULL,
24+
timezone TEXT = NULL,
25+
compress_created_before INTERVAL = NULL
26+
)
27+
RETURNS INTEGER
28+
AS '@MODULE_PATHNAME@', 'ts_policy_compression_add'
29+
LANGUAGE C VOLATILE;
30+
31+
DROP FUNCTION IF EXISTS timescaledb_experimental.add_policies(relation REGCLASS, if_not_exists BOOL, refresh_start_offset "any", refresh_end_offset "any", compress_after "any", drop_after "any", hypercore_use_access_method BOOL);
32+
33+
CREATE FUNCTION timescaledb_experimental.add_policies(
34+
relation REGCLASS,
35+
if_not_exists BOOL = false,
36+
refresh_start_offset "any" = NULL,
37+
refresh_end_offset "any" = NULL,
38+
compress_after "any" = NULL,
39+
drop_after "any" = NULL)
40+
RETURNS BOOL
41+
AS '@MODULE_PATHNAME@', 'ts_policies_add'
42+
LANGUAGE C VOLATILE;
43+
44+
DROP PROCEDURE IF EXISTS _timescaledb_functions.policy_compression_execute(job_id INTEGER, htid INTEGER, lag ANYELEMENT, maxchunks INTEGER, verbose_log BOOLEAN, recompress_enabled BOOLEAN, use_creation_time BOOLEAN, useam BOOLEAN);
45+
46+
DROP PROCEDURE IF EXISTS _timescaledb_functions.policy_compression(job_id INTEGER, config JSONB);
47+
DROP PROCEDURE IF EXISTS @[email protected]_to_columnstore(REGCLASS, BOOLEAN, BOOLEAN, BOOLEAN);
48+
DROP PROCEDURE IF EXISTS @[email protected]_to_rowstore(REGCLASS, BOOLEAN);
49+
DROP PROCEDURE IF EXISTS @[email protected]_columnstore_policy(REGCLASS, "any", BOOL, INTERVAL, TIMESTAMPTZ, TEXT, INTERVAL, BOOL);
50+
DROP PROCEDURE IF EXISTS @[email protected]_columnstore_policy(REGCLASS, BOOL);
51+
DROP FUNCTION IF EXISTS @[email protected]_columnstore_stats(REGCLASS);
52+
DROP FUNCTION IF EXISTS @[email protected]_columnstore_stats(REGCLASS);
53+
54+
ALTER EXTENSION timescaledb DROP VIEW timescaledb_information.hypertable_columnstore_settings;
55+
ALTER EXTENSION timescaledb DROP VIEW timescaledb_information.chunk_columnstore_settings;
56+
57+
DROP VIEW timescaledb_information.hypertable_columnstore_settings;
58+
DROP VIEW timescaledb_information.chunk_columnstore_settings;
59+
60+
-- Restore the removed metadata table
61+
CREATE TABLE _timescaledb_catalog.continuous_aggs_bucket_function (
62+
mat_hypertable_id integer NOT NULL,
63+
-- The bucket function
64+
bucket_func text NOT NULL,
65+
-- `bucket_width` argument of the function, e.g. "1 month"
66+
bucket_width text NOT NULL,
67+
-- optional `origin` argument of the function provided by the user
68+
bucket_origin text,
69+
-- optional `offset` argument of the function provided by the user
70+
bucket_offset text,
71+
-- optional `timezone` argument of the function provided by the user
72+
bucket_timezone text,
73+
-- fixed or variable sized bucket
74+
bucket_fixed_width bool NOT NULL,
75+
-- table constraints
76+
CONSTRAINT continuous_aggs_bucket_function_pkey PRIMARY KEY (mat_hypertable_id),
77+
CONSTRAINT continuous_aggs_bucket_function_mat_hypertable_id_fkey FOREIGN KEY (mat_hypertable_id) REFERENCES _timescaledb_catalog.hypertable (id) ON DELETE CASCADE,
78+
CONSTRAINT continuous_aggs_bucket_function_func_check CHECK (pg_catalog.to_regprocedure(bucket_func) IS DISTINCT FROM 0)
79+
);
80+
81+
INSERT INTO _timescaledb_catalog.continuous_aggs_bucket_function
82+
(mat_hypertable_id, bucket_func, bucket_width, bucket_origin, bucket_offset, bucket_timezone, bucket_fixed_width)
83+
SELECT mat_hypertable_id, bf.bucket_func::text, bf.bucket_width, bf.bucket_origin, bf.bucket_offset, bf.bucket_timezone, bf.bucket_fixed_width
84+
FROM _timescaledb_catalog.continuous_agg, LATERAL _timescaledb_functions.cagg_get_bucket_function_info(mat_hypertable_id) AS bf;
85+
86+
SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.continuous_aggs_bucket_function', '');
87+
88+
GRANT SELECT ON _timescaledb_catalog.continuous_aggs_bucket_function TO PUBLIC;
89+
90+
DROP FUNCTION IF EXISTS _timescaledb_functions.cagg_get_bucket_function_info(INTEGER);

src/cross_module_fn.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,13 @@ continuous_agg_call_invalidation_trigger_default(int32 hypertable_id, Relation c
310310
pg_unreachable();
311311
}
312312

313+
static ContinuousAggsBucketFunction *
314+
continuous_agg_get_bucket_function_info_internal_default(Oid view_oid)
315+
{
316+
error_no_default_fn_community();
317+
pg_unreachable();
318+
}
319+
313320
TS_FUNCTION_INFO_V1(ts_tsl_loaded);
314321

315322
PGDLLEXPORT Datum
@@ -398,6 +405,8 @@ TSDLLEXPORT CrossModuleFunctions ts_cm_functions_default = {
398405
.continuous_agg_validate_query = error_no_default_fn_pg_community,
399406
.continuous_agg_get_bucket_function = error_no_default_fn_pg_community,
400407
.continuous_agg_get_bucket_function_info = error_no_default_fn_pg_community,
408+
.continuous_agg_get_bucket_function_info_internal =
409+
continuous_agg_get_bucket_function_info_internal_default,
401410
.continuous_agg_migrate_to_time_bucket = error_no_default_fn_pg_community,
402411
.cagg_try_repair = process_cagg_try_repair,
403412

src/cross_module_fn.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ typedef struct CrossModuleFunctions
116116
PGFunction continuous_agg_get_bucket_function_info;
117117
PGFunction continuous_agg_migrate_to_time_bucket;
118118
PGFunction cagg_try_repair;
119+
ContinuousAggsBucketFunction *(*continuous_agg_get_bucket_function_info_internal)(Oid view_oid);
119120

120121
PGFunction compressed_data_send;
121122
PGFunction compressed_data_recv;

src/ts_catalog/catalog.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,6 @@ static const TableInfoDef catalog_table_names[_MAX_CATALOG_TABLES + 1] = {
9797
.schema_name = CATALOG_SCHEMA_NAME,
9898
.table_name = COMPRESSION_CHUNK_SIZE_TABLE_NAME,
9999
},
100-
[CONTINUOUS_AGGS_BUCKET_FUNCTION] = {
101-
.schema_name = CATALOG_SCHEMA_NAME,
102-
.table_name = CONTINUOUS_AGGS_BUCKET_FUNCTION_TABLE_NAME,
103-
},
104100
[CONTINUOUS_AGGS_WATERMARK] = {
105101
.schema_name = CATALOG_SCHEMA_NAME,
106102
.table_name = CONTINUOUS_AGGS_WATERMARK_TABLE_NAME,
@@ -256,12 +252,6 @@ static const TableIndexDef catalog_table_index_definitions[_MAX_CATALOG_TABLES]
256252
.names = (char *[]) {
257253
[COMPRESSION_CHUNK_SIZE_PKEY] = "compression_chunk_size_pkey",
258254
},
259-
},
260-
[CONTINUOUS_AGGS_BUCKET_FUNCTION] = {
261-
.length = _MAX_CONTINUOUS_AGGS_BUCKET_FUNCTION_INDEX,
262-
.names = (char *[]) {
263-
[CONTINUOUS_AGGS_BUCKET_FUNCTION_PKEY_IDX] = "continuous_aggs_bucket_function_pkey",
264-
},
265255
}
266256
};
267257

src/ts_catalog/catalog.h

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ typedef enum CatalogTable
5050
CONTINUOUS_AGGS_MATERIALIZATION_INVALIDATION_LOG,
5151
COMPRESSION_SETTINGS,
5252
COMPRESSION_CHUNK_SIZE,
53-
CONTINUOUS_AGGS_BUCKET_FUNCTION,
5453
CONTINUOUS_AGGS_WATERMARK,
5554
TELEMETRY_EVENT,
5655
CHUNK_COLUMN_STATS,
@@ -972,38 +971,6 @@ typedef enum Anum_continuous_agg_raw_hypertable_id_idx
972971
#define Natts_continuous_agg_raw_hypertable_id_idx \
973972
(_Anum_continuous_agg_raw_hypertable_id_idx_max - 1)
974973

975-
/*** continuous_aggs_bucket_function table definitions ***/
976-
977-
#define CONTINUOUS_AGGS_BUCKET_FUNCTION_TABLE_NAME "continuous_aggs_bucket_function"
978-
typedef enum Anum_continuous_aggs_bucket_function
979-
{
980-
Anum_continuous_aggs_bucket_function_mat_hypertable_id = 1,
981-
Anum_continuous_aggs_bucket_function_function,
982-
Anum_continuous_aggs_bucket_function_bucket_width,
983-
Anum_continuous_aggs_bucket_function_bucket_origin,
984-
Anum_continuous_aggs_bucket_function_bucket_offset,
985-
Anum_continuous_aggs_bucket_function_bucket_timezone,
986-
Anum_continuous_aggs_bucket_function_bucket_fixed_width,
987-
_Anum_continuous_aggs_bucket_function_max,
988-
} Anum_continuous_aggs_bucket_function;
989-
990-
#define Natts_continuous_aggs_bucket_function (_Anum_continuous_aggs_bucket_function_max - 1)
991-
992-
enum
993-
{
994-
CONTINUOUS_AGGS_BUCKET_FUNCTION_PKEY_IDX = 0,
995-
_MAX_CONTINUOUS_AGGS_BUCKET_FUNCTION_INDEX,
996-
};
997-
998-
typedef enum Anum_continuous_aggs_bucket_function_pkey
999-
{
1000-
Anum_continuous_aggs_bucket_function_pkey_mat_hypertable_id = 1,
1001-
_Anum_continuous_aggs_bucket_function_pkey_max,
1002-
} Anum_continuous_aggs_bucket_function_pkey;
1003-
1004-
#define Natts_continuous_aggs_bucket_function_pkey \
1005-
(_Anum_continuous_aggs_bucket_function_pkey_max - 1)
1006-
1007974
/****** CONTINUOUS_AGGS_HYPERTABLE_INVALIDATION_LOG_TABLE definitions*/
1008975
#define CONTINUOUS_AGGS_HYPERTABLE_INVALIDATION_LOG_TABLE_NAME \
1009976
"continuous_aggs_hypertable_invalidation_log"

0 commit comments

Comments
 (0)