Skip to content

Commit

Permalink
Add aliases for compression functions and views
Browse files Browse the repository at this point in the history
This adds a set of aliases for existing compression functions and view
to better reflect the column store capabilities of compressed
hypertables.

The procedures `convert_to_rowstore` and `convert_to_columnstore` are
added as aliases to `decompress_chunk` and `compress_chunk`
respectively. We change these from functions to procedures to be able
to split the conversion into multiple transactions and avoid heavy
locking for longer periods.

The procedures `add_columnstore_policy` and `remove_columnstore_policy`
are added as alias for `add_compression_policy` and
`remove_compression_policy` respectively.

The functions `hypertable_columnstore_stats` and
`chunk_columnstore_stats` are added as aliases for
`hypertable_compression_stats` and `chunk_compression_stats`
respectively.

The views `hypertable_columnstore_settings`,
`chunk_columnstore_settings`, and `columnstore_settings` are added as
aliases for the corresponding views.

We also add aliases for parameters to functions and procedures that
take these.

- The parameter `timescaledb.enable_columnstore` is an alias for
  `timescaledb.compress`

- The parameter `timescaledb.segmentby` is an alias for
  `timescaledb.compress_segmentby`.

- The parameter `timescaledb.orderby` is an alias for
  `timescaledb.compress_orderby`.
  • Loading branch information
mkindahl committed Dec 2, 2024
1 parent 155ca6f commit e80d766
Show file tree
Hide file tree
Showing 19 changed files with 370 additions and 46 deletions.
1 change: 1 addition & 0 deletions .unreleased/pr_7443
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implements: #7443 Add Hypercore function and view aliases
13 changes: 13 additions & 0 deletions sql/maintenance_utils.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,24 @@ CREATE OR REPLACE FUNCTION @[email protected]_chunk(
hypercore_use_access_method BOOL = NULL
) RETURNS REGCLASS AS '@MODULE_PATHNAME@', 'ts_compress_chunk' LANGUAGE C VOLATILE;

-- Alias for compress_chunk above.
CREATE OR REPLACE PROCEDURE @[email protected]_to_columnstore(
chunk REGCLASS,
if_not_columnstore BOOLEAN = true,
recompress BOOLEAN = false,
hypercore_use_access_method BOOL = NULL
) AS '@MODULE_PATHNAME@', 'ts_compress_chunk' LANGUAGE C;

CREATE OR REPLACE FUNCTION @[email protected]_chunk(
uncompressed_chunk REGCLASS,
if_compressed BOOLEAN = true
) RETURNS REGCLASS AS '@MODULE_PATHNAME@', 'ts_decompress_chunk' LANGUAGE C STRICT VOLATILE;

CREATE OR REPLACE PROCEDURE @[email protected]_to_rowstore(
chunk REGCLASS,
if_columnstore BOOLEAN = true
) AS '@MODULE_PATHNAME@', 'ts_decompress_chunk' LANGUAGE C;

CREATE OR REPLACE FUNCTION _timescaledb_functions.recompress_chunk_segmentwise(
uncompressed_chunk REGCLASS,
if_compressed BOOLEAN = true
Expand Down
16 changes: 16 additions & 0 deletions sql/policy_api.sql
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,26 @@ RETURNS INTEGER
AS '@MODULE_PATHNAME@', 'ts_policy_compression_add'
LANGUAGE C VOLATILE; -- not strict because we need to set different default values for schedule_interval

CREATE OR REPLACE PROCEDURE @[email protected]_columnstore_policy(
hypertable REGCLASS,
after "any" = NULL,
if_not_exists BOOL = false,
schedule_interval INTERVAL = NULL,
initial_start TIMESTAMPTZ = NULL,
timezone TEXT = NULL,
created_before INTERVAL = NULL,
hypercore_use_access_method BOOL = NULL
) LANGUAGE C AS '@MODULE_PATHNAME@', 'ts_policy_compression_add';

CREATE OR REPLACE FUNCTION @[email protected]_compression_policy(hypertable REGCLASS, if_exists BOOL = false) RETURNS BOOL
AS '@MODULE_PATHNAME@', 'ts_policy_compression_remove'
LANGUAGE C VOLATILE STRICT;

CREATE OR REPLACE PROCEDURE @[email protected]_columnstore_policy(
hypertable REGCLASS,
if_exists BOOL = false
) LANGUAGE C AS '@MODULE_PATHNAME@', 'ts_policy_compression_remove';

/* continuous aggregates policy */
CREATE OR REPLACE FUNCTION @[email protected]_continuous_aggregate_policy(
continuous_aggregate REGCLASS, start_offset "any",
Expand Down
37 changes: 37 additions & 0 deletions sql/size_utils.sql
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,25 @@ BEGIN
END;
$BODY$ SET search_path TO pg_catalog, pg_temp;

CREATE OR REPLACE FUNCTION @[email protected]_columnstore_stats (hypertable REGCLASS)
RETURNS TABLE (
chunk_schema name,
chunk_name name,
compression_status text,
before_compression_table_bytes bigint,
before_compression_index_bytes bigint,
before_compression_toast_bytes bigint,
before_compression_total_bytes bigint,
after_compression_table_bytes bigint,
after_compression_index_bytes bigint,
after_compression_toast_bytes bigint,
after_compression_total_bytes bigint,
node_name name)
LANGUAGE SQL
STABLE STRICT
AS 'SELECT * FROM @[email protected]_compression_stats($1)'
SET search_path TO pg_catalog, pg_temp;

-- Get compression statistics for a hypertable that has
-- compression enabled
CREATE OR REPLACE FUNCTION @[email protected]_compression_stats (hypertable REGCLASS)
Expand Down Expand Up @@ -581,6 +600,24 @@ $BODY$
ch.node_name;
$BODY$ SET search_path TO pg_catalog, pg_temp;

CREATE OR REPLACE FUNCTION @[email protected]_columnstore_stats (hypertable REGCLASS)
RETURNS TABLE (
total_chunks bigint,
number_compressed_chunks bigint,
before_compression_table_bytes bigint,
before_compression_index_bytes bigint,
before_compression_toast_bytes bigint,
before_compression_total_bytes bigint,
after_compression_table_bytes bigint,
after_compression_index_bytes bigint,
after_compression_toast_bytes bigint,
after_compression_total_bytes bigint,
node_name name)
LANGUAGE SQL
STABLE STRICT
AS 'SELECT * FROM @[email protected]_compression_stats($1)'
SET search_path TO pg_catalog, pg_temp;

-------------Get index size for hypertables -------
--schema_name - schema_name for hypertable index
-- index_name - index on hyper table
Expand Down
67 changes: 67 additions & 0 deletions sql/updates/latest-dev.sql
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,70 @@ LANGUAGE C VOLATILE;
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);

DROP PROCEDURE IF EXISTS _timescaledb_functions.policy_compression(job_id INTEGER, config JSONB);

CREATE PROCEDURE @[email protected]_to_columnstore(
chunk REGCLASS,
if_not_columnstore BOOLEAN = true,
recompress BOOLEAN = false,
hypercore_use_access_method BOOL = NULL)
AS '@MODULE_PATHNAME@', 'ts_update_placeholder'
LANGUAGE C;

CREATE PROCEDURE @[email protected]_to_rowstore(
chunk REGCLASS,
if_columnstore BOOLEAN = true)
AS '@MODULE_PATHNAME@', 'ts_update_placeholder'
LANGUAGE C;

CREATE PROCEDURE @[email protected]_columnstore_policy(
hypertable REGCLASS,
after "any" = NULL,
if_not_exists BOOL = false,
schedule_interval INTERVAL = NULL,
initial_start TIMESTAMPTZ = NULL,
timezone TEXT = NULL,
created_before INTERVAL = NULL,
hypercore_use_access_method BOOL = NULL
) LANGUAGE C AS '@MODULE_PATHNAME@', 'ts_update_placeholder';

CREATE PROCEDURE @[email protected]_columnstore_policy(
hypertable REGCLASS,
if_exists BOOL = false
) LANGUAGE C AS '@MODULE_PATHNAME@', 'ts_update_placeholder';

CREATE FUNCTION @[email protected]_columnstore_stats (hypertable REGCLASS)
RETURNS TABLE (
chunk_schema name,
chunk_name name,
compression_status text,
before_compression_table_bytes bigint,
before_compression_index_bytes bigint,
before_compression_toast_bytes bigint,
before_compression_total_bytes bigint,
after_compression_table_bytes bigint,
after_compression_index_bytes bigint,
after_compression_toast_bytes bigint,
after_compression_total_bytes bigint,
node_name name)
LANGUAGE SQL
STABLE STRICT
AS 'SELECT * FROM @[email protected]_compression_stats($1)'
SET search_path TO pg_catalog, pg_temp;

CREATE FUNCTION @[email protected]_columnstore_stats (hypertable REGCLASS)
RETURNS TABLE (
total_chunks bigint,
number_compressed_chunks bigint,
before_compression_table_bytes bigint,
before_compression_index_bytes bigint,
before_compression_toast_bytes bigint,
before_compression_total_bytes bigint,
after_compression_table_bytes bigint,
after_compression_index_bytes bigint,
after_compression_toast_bytes bigint,
after_compression_total_bytes bigint,
node_name name)
LANGUAGE SQL
STABLE STRICT
AS 'SELECT * FROM @[email protected]_compression_stats($1)'
SET search_path TO pg_catalog, pg_temp;
13 changes: 13 additions & 0 deletions sql/updates/reverse-dev.sql
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,16 @@ LANGUAGE C VOLATILE;
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);

DROP PROCEDURE IF EXISTS _timescaledb_functions.policy_compression(job_id INTEGER, config JSONB);
DROP PROCEDURE IF EXISTS @[email protected]_to_columnstore(REGCLASS, BOOLEAN, BOOLEAN, BOOLEAN);
DROP PROCEDURE IF EXISTS @[email protected]_to_rowstore(REGCLASS, BOOLEAN);
DROP PROCEDURE IF EXISTS @[email protected]_columnstore_policy(REGCLASS, "any", BOOL, INTERVAL, TIMESTAMPTZ, TEXT, INTERVAL, BOOL);
DROP PROCEDURE IF EXISTS @[email protected]_columnstore_policy(REGCLASS, BOOL);
DROP FUNCTION IF EXISTS @[email protected]_columnstore_stats(REGCLASS);
DROP FUNCTION IF EXISTS @[email protected]_columnstore_stats(REGCLASS);

ALTER EXTENSION timescaledb DROP VIEW timescaledb_information.hypertable_columnstore_settings;
ALTER EXTENSION timescaledb DROP VIEW timescaledb_information.chunk_columnstore_settings;

DROP VIEW timescaledb_information.hypertable_columnstore_settings;
DROP VIEW timescaledb_information.chunk_columnstore_settings;

7 changes: 7 additions & 0 deletions sql/views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -403,5 +403,12 @@ CREATE OR REPLACE VIEW timescaledb_information.chunk_compression_settings AS
FROM unnest(s.orderby, s.orderby_desc, s.orderby_nullsfirst) un(orderby, "desc", nullsfirst)
) un ON true;


CREATE OR REPLACE VIEW timescaledb_information.hypertable_columnstore_settings
AS SELECT * FROM timescaledb_information.hypertable_compression_settings;

CREATE OR REPLACE VIEW timescaledb_information.chunk_columnstore_settings AS
SELECT * FROM timescaledb_information.chunk_compression_settings;

GRANT SELECT ON ALL TABLES IN SCHEMA timescaledb_information TO PUBLIC;

8 changes: 4 additions & 4 deletions src/compression_with_clause.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@

static const WithClauseDefinition compress_hypertable_with_clause_def[] = {
[CompressEnabled] = {
.arg_name = "compress",
.arg_names = {"compress", "enable_columnstore", NULL},
.type_id = BOOLOID,
.default_val = (Datum)false,
},
[CompressSegmentBy] = {
.arg_name = "compress_segmentby",
.arg_names = {"compress_segmentby", "segmentby", NULL},
.type_id = TEXTOID,
},
[CompressOrderBy] = {
.arg_name = "compress_orderby",
.arg_names = {"compress_orderby", "orderby", NULL},
.type_id = TEXTOID,
},
[CompressChunkTimeInterval] = {
.arg_name = "compress_chunk_time_interval",
.arg_names = {"compress_chunk_time_interval", NULL},
.type_id = INTERVALOID,
},
};
Expand Down
6 changes: 3 additions & 3 deletions src/process_utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -2960,10 +2960,10 @@ typedef enum HypertableIndexFlags
} HypertableIndexFlags;

static const WithClauseDefinition index_with_clauses[] = {
[HypertableIndexFlagMultiTransaction] = {.arg_name = "transaction_per_chunk", .type_id = BOOLOID,},
[HypertableIndexFlagMultiTransaction] = {.arg_names = {"transaction_per_chunk", NULL}, .type_id = BOOLOID,},
#ifdef DEBUG
[HypertableIndexFlagBarrierTable] = {.arg_name = "barrier_table", .type_id = REGCLASSOID,},
[HypertableIndexFlagMaxChunks] = {.arg_name = "max_chunks", .type_id = INT4OID, .default_val = (Datum)-1},
[HypertableIndexFlagBarrierTable] = {.arg_names = {"barrier_table", NULL}, .type_id = REGCLASSOID,},
[HypertableIndexFlagMaxChunks] = {.arg_names = {"max_chunks", NULL}, .type_id = INT4OID, .default_val = (Datum)-1},
#endif
};

Expand Down
20 changes: 10 additions & 10 deletions src/ts_catalog/continuous_agg.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,39 +48,39 @@

static const WithClauseDefinition continuous_aggregate_with_clause_def[] = {
[ContinuousEnabled] = {
.arg_name = "continuous",
.arg_names = {"continuous", NULL},
.type_id = BOOLOID,
.default_val = (Datum)false,
},
[ContinuousViewOptionCreateGroupIndex] = {
.arg_name = "create_group_indexes",
.arg_names = {"create_group_indexes", NULL},
.type_id = BOOLOID,
.default_val = (Datum)true,
},
[ContinuousViewOptionMaterializedOnly] = {
.arg_name = "materialized_only",
.arg_names = {"materialized_only", NULL},
.type_id = BOOLOID,
.default_val = (Datum)true,
},
[ContinuousViewOptionCompress] = {
.arg_name = "compress",
.arg_names = {"enable_columnstore", "compress", NULL},
.type_id = BOOLOID,
},
[ContinuousViewOptionFinalized] = {
.arg_name = "finalized",
.arg_names = {"finalized", NULL},
.type_id = BOOLOID,
.default_val = (Datum)true,
},
[ContinuousViewOptionCompressSegmentBy] = {
.arg_name = "compress_segmentby",
.type_id = TEXTOID,
.arg_names = {"segmentby", "compress_segmentby", NULL},
.type_id = TEXTOID,
},
[ContinuousViewOptionCompressOrderBy] = {
.arg_name = "compress_orderby",
.arg_names = {"orderby", "compress_orderby", NULL},
.type_id = TEXTOID,
},
[ContinuousViewOptionCompressChunkTimeInterval] = {
.arg_name = "compress_chunk_time_interval",
.arg_names = {"compress_chunk_time_interval", NULL},
.type_id = INTERVALOID,
},
};
Expand Down Expand Up @@ -127,7 +127,7 @@ ts_continuous_agg_get_compression_defelems(const WithClauseResult *with_clauses)
{
Node *value = (Node *) makeString(ts_with_clause_result_deparse_value(input));
DefElem *elem = makeDefElemExtended(EXTENSION_NAMESPACE,
(char *) def.arg_name,
(char *) def.arg_names[0],
value,
DEFELEM_UNSPEC,
-1);
Expand Down
29 changes: 16 additions & 13 deletions src/with_clause_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,23 @@ ts_with_clauses_parse(const List *def_elems, const WithClauseDefinition *args, S

for (i = 0; i < nargs; i++)
{
if (pg_strcasecmp(def->defname, args[i].arg_name) == 0)
for (int j = 0; args[i].arg_names[j] != NULL; ++j)
{
argument_recognized = true;

if (!results[i].is_default)
ereport(ERROR,
(errcode(ERRCODE_AMBIGUOUS_PARAMETER),
errmsg("duplicate parameter \"%s.%s\"",
def->defnamespace,
def->defname)));

results[i].parsed = parse_arg(args[i], def);
results[i].is_default = false;
break;
if (pg_strcasecmp(def->defname, args[i].arg_names[j]) == 0)
{
argument_recognized = true;

if (!results[i].is_default)
ereport(ERROR,
(errcode(ERRCODE_AMBIGUOUS_PARAMETER),
errmsg("duplicate parameter \"%s.%s\"",
def->defnamespace,
def->defname)));

results[i].parsed = parse_arg(args[i], def);
results[i].is_default = false;
break;
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/with_clause_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

typedef struct WithClauseDefinition
{
const char *arg_name;
/* Alternative names for the parameters. The first one is the "main" one
* when it comes to printouts.*/
const char *arg_names[5];
Oid type_id;
Datum default_val;
} WithClauseDefinition;
Expand Down
4 changes: 3 additions & 1 deletion test/expected/pg_dump.out
Original file line number Diff line number Diff line change
Expand Up @@ -571,18 +571,20 @@ WHERE refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass AND
_timescaledb_internal.compressed_chunk_stats
_timescaledb_internal.hypertable_chunk_local_size
timescaledb_experimental.policies
timescaledb_information.chunk_columnstore_settings
timescaledb_information.chunk_compression_settings
timescaledb_information.chunks
timescaledb_information.compression_settings
timescaledb_information.continuous_aggregates
timescaledb_information.dimensions
timescaledb_information.hypertable_columnstore_settings
timescaledb_information.hypertable_compression_settings
timescaledb_information.hypertables
timescaledb_information.job_errors
timescaledb_information.job_history
timescaledb_information.job_stats
timescaledb_information.jobs
(24 rows)
(26 rows)

-- Make sure we can't run our restoring functions as a normal perm user as that would disable functionality for the whole db
\c :TEST_DBNAME :ROLE_DEFAULT_PERM_USER
Expand Down
Loading

0 comments on commit e80d766

Please sign in to comment.