Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cagg drop bucket function metadata table #7532

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions sql/pre_install/tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -387,29 +387,6 @@ CREATE INDEX continuous_agg_raw_hypertable_id_idx ON _timescaledb_catalog.contin

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

-- See the comments for ContinuousAggsBucketFunction structure.
CREATE TABLE _timescaledb_catalog.continuous_aggs_bucket_function (
mat_hypertable_id integer NOT NULL,
-- The bucket function
bucket_func text NOT NULL,
-- `bucket_width` argument of the function, e.g. "1 month"
bucket_width text NOT NULL,
-- optional `origin` argument of the function provided by the user
bucket_origin text,
-- optional `offset` argument of the function provided by the user
bucket_offset text,
-- optional `timezone` argument of the function provided by the user
bucket_timezone text,
-- fixed or variable sized bucket
bucket_fixed_width bool NOT NULL,
-- table constraints
CONSTRAINT continuous_aggs_bucket_function_pkey PRIMARY KEY (mat_hypertable_id),
CONSTRAINT continuous_aggs_bucket_function_mat_hypertable_id_fkey FOREIGN KEY (mat_hypertable_id) REFERENCES _timescaledb_catalog.hypertable (id) ON DELETE CASCADE,
CONSTRAINT continuous_aggs_bucket_function_func_check CHECK (pg_catalog.to_regprocedure(bucket_func) IS DISTINCT FROM 0)
);

SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.continuous_aggs_bucket_function', '');

CREATE TABLE _timescaledb_catalog.continuous_aggs_invalidation_threshold (
hypertable_id integer NOT NULL,
watermark bigint NOT NULL,
Expand Down
6 changes: 6 additions & 0 deletions sql/updates/latest-dev.sql
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,9 @@ CREATE FUNCTION @extschema@.hypertable_columnstore_stats (hypertable REGCLASS)
STABLE STRICT
AS 'SELECT * FROM @extschema@.hypertable_compression_stats($1)'
SET search_path TO pg_catalog, pg_temp;

-- Remove useless catalog metadata
ALTER EXTENSION timescaledb
DROP TABLE _timescaledb_catalog.continuous_aggs_bucket_function;

DROP TABLE _timescaledb_catalog.continuous_aggs_bucket_function;
29 changes: 29 additions & 0 deletions sql/updates/reverse-dev.sql
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,32 @@ ALTER EXTENSION timescaledb DROP VIEW timescaledb_information.chunk_columnstore_
DROP VIEW timescaledb_information.hypertable_columnstore_settings;
DROP VIEW timescaledb_information.chunk_columnstore_settings;

-- Restore the removed metadata table
CREATE TABLE _timescaledb_catalog.continuous_aggs_bucket_function (
mat_hypertable_id integer NOT NULL,
-- The bucket function
bucket_func text NOT NULL,
-- `bucket_width` argument of the function, e.g. "1 month"
bucket_width text NOT NULL,
-- optional `origin` argument of the function provided by the user
bucket_origin text,
-- optional `offset` argument of the function provided by the user
bucket_offset text,
-- optional `timezone` argument of the function provided by the user
bucket_timezone text,
-- fixed or variable sized bucket
bucket_fixed_width bool NOT NULL,
-- table constraints
CONSTRAINT continuous_aggs_bucket_function_pkey PRIMARY KEY (mat_hypertable_id),
CONSTRAINT continuous_aggs_bucket_function_mat_hypertable_id_fkey FOREIGN KEY (mat_hypertable_id) REFERENCES _timescaledb_catalog.hypertable (id) ON DELETE CASCADE,
CONSTRAINT continuous_aggs_bucket_function_func_check CHECK (pg_catalog.to_regprocedure(bucket_func) IS DISTINCT FROM 0)
);

INSERT INTO _timescaledb_catalog.continuous_aggs_bucket_function
(mat_hypertable_id, bucket_func, bucket_width, bucket_origin, bucket_offset, bucket_timezone, bucket_fixed_width)
SELECT mat_hypertable_id, bf.bucket_func::text, bf.bucket_width, bf.bucket_origin, bf.bucket_offset, bf.bucket_timezone, bf.bucket_fixed_width
FROM _timescaledb_catalog.continuous_agg, LATERAL _timescaledb_functions.cagg_get_bucket_function_info(mat_hypertable_id) AS bf;

SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.continuous_aggs_bucket_function', '');

GRANT SELECT ON _timescaledb_catalog.continuous_aggs_bucket_function TO PUBLIC;
9 changes: 9 additions & 0 deletions src/cross_module_fn.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,13 @@ continuous_agg_call_invalidation_trigger_default(int32 hypertable_id, Relation c
pg_unreachable();
}

static ContinuousAggsBucketFunction *
continuous_agg_get_bucket_function_info_internal_default(Oid view_oid)
{
error_no_default_fn_community();
pg_unreachable();
}

TS_FUNCTION_INFO_V1(ts_tsl_loaded);

PGDLLEXPORT Datum
Expand Down Expand Up @@ -373,6 +380,8 @@ TSDLLEXPORT CrossModuleFunctions ts_cm_functions_default = {
.continuous_agg_validate_query = error_no_default_fn_pg_community,
.continuous_agg_get_bucket_function = error_no_default_fn_pg_community,
.continuous_agg_get_bucket_function_info = error_no_default_fn_pg_community,
.continuous_agg_get_bucket_function_info_internal =
continuous_agg_get_bucket_function_info_internal_default,
.continuous_agg_migrate_to_time_bucket = error_no_default_fn_pg_community,
.cagg_try_repair = process_cagg_try_repair,

Expand Down
1 change: 1 addition & 0 deletions src/cross_module_fn.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ typedef struct CrossModuleFunctions
PGFunction continuous_agg_get_bucket_function_info;
PGFunction continuous_agg_migrate_to_time_bucket;
PGFunction cagg_try_repair;
ContinuousAggsBucketFunction *(*continuous_agg_get_bucket_function_info_internal)(Oid view_oid);

PGFunction compressed_data_send;
PGFunction compressed_data_recv;
Expand Down
10 changes: 0 additions & 10 deletions src/ts_catalog/catalog.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ static const TableInfoDef catalog_table_names[_MAX_CATALOG_TABLES + 1] = {
.schema_name = CATALOG_SCHEMA_NAME,
.table_name = COMPRESSION_CHUNK_SIZE_TABLE_NAME,
},
[CONTINUOUS_AGGS_BUCKET_FUNCTION] = {
.schema_name = CATALOG_SCHEMA_NAME,
.table_name = CONTINUOUS_AGGS_BUCKET_FUNCTION_TABLE_NAME,
},
[CONTINUOUS_AGGS_WATERMARK] = {
.schema_name = CATALOG_SCHEMA_NAME,
.table_name = CONTINUOUS_AGGS_WATERMARK_TABLE_NAME,
Expand Down Expand Up @@ -255,12 +251,6 @@ static const TableIndexDef catalog_table_index_definitions[_MAX_CATALOG_TABLES]
.names = (char *[]) {
[COMPRESSION_CHUNK_SIZE_PKEY] = "compression_chunk_size_pkey",
},
},
[CONTINUOUS_AGGS_BUCKET_FUNCTION] = {
.length = _MAX_CONTINUOUS_AGGS_BUCKET_FUNCTION_INDEX,
.names = (char *[]) {
[CONTINUOUS_AGGS_BUCKET_FUNCTION_PKEY_IDX] = "continuous_aggs_bucket_function_pkey",
},
}
};

Expand Down
33 changes: 0 additions & 33 deletions src/ts_catalog/catalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ typedef enum CatalogTable
CONTINUOUS_AGGS_MATERIALIZATION_INVALIDATION_LOG,
COMPRESSION_SETTINGS,
COMPRESSION_CHUNK_SIZE,
CONTINUOUS_AGGS_BUCKET_FUNCTION,
CONTINUOUS_AGGS_WATERMARK,
TELEMETRY_EVENT,
CHUNK_COLUMN_STATS,
Expand Down Expand Up @@ -972,38 +971,6 @@ typedef enum Anum_continuous_agg_raw_hypertable_id_idx
#define Natts_continuous_agg_raw_hypertable_id_idx \
(_Anum_continuous_agg_raw_hypertable_id_idx_max - 1)

/*** continuous_aggs_bucket_function table definitions ***/

#define CONTINUOUS_AGGS_BUCKET_FUNCTION_TABLE_NAME "continuous_aggs_bucket_function"
typedef enum Anum_continuous_aggs_bucket_function
{
Anum_continuous_aggs_bucket_function_mat_hypertable_id = 1,
Anum_continuous_aggs_bucket_function_function,
Anum_continuous_aggs_bucket_function_bucket_width,
Anum_continuous_aggs_bucket_function_bucket_origin,
Anum_continuous_aggs_bucket_function_bucket_offset,
Anum_continuous_aggs_bucket_function_bucket_timezone,
Anum_continuous_aggs_bucket_function_bucket_fixed_width,
_Anum_continuous_aggs_bucket_function_max,
} Anum_continuous_aggs_bucket_function;

#define Natts_continuous_aggs_bucket_function (_Anum_continuous_aggs_bucket_function_max - 1)

enum
{
CONTINUOUS_AGGS_BUCKET_FUNCTION_PKEY_IDX = 0,
_MAX_CONTINUOUS_AGGS_BUCKET_FUNCTION_INDEX,
};

typedef enum Anum_continuous_aggs_bucket_function_pkey
{
Anum_continuous_aggs_bucket_function_pkey_mat_hypertable_id = 1,
_Anum_continuous_aggs_bucket_function_pkey_max,
} Anum_continuous_aggs_bucket_function_pkey;

#define Natts_continuous_aggs_bucket_function_pkey \
(_Anum_continuous_aggs_bucket_function_pkey_max - 1)

/****** CONTINUOUS_AGGS_HYPERTABLE_INVALIDATION_LOG_TABLE definitions*/
#define CONTINUOUS_AGGS_HYPERTABLE_INVALIDATION_LOG_TABLE_NAME \
"continuous_aggs_hypertable_invalidation_log"
Expand Down
Loading
Loading