From 2d7eb18f249e898e63fc90bf02012af9ce2ccded Mon Sep 17 00:00:00 2001 From: Sven Klemm Date: Thu, 6 Apr 2023 14:50:27 +0200 Subject: [PATCH] Drop unused SQL functions This patch drops the following internal SQL functions which were unused: _timescaledb_internal.is_main_table(regclass); _timescaledb_internal.is_main_table(text, text); _timescaledb_internal.hypertable_from_main_table(regclass); _timescaledb_internal.main_table_from_hypertable(integer); _timescaledb_internal.time_literal_sql(bigint, regtype); --- cmake/ScriptFiles.cmake | 1 - sql/schema_info.sql | 58 ------------------- sql/updates/latest-dev.sql | 6 ++ sql/updates/reverse-dev.sql | 79 ++++++++++++++++++++++++++ sql/util_time.sql | 31 ---------- tsl/test/shared/expected/extension.out | 5 -- 6 files changed, 85 insertions(+), 95 deletions(-) delete mode 100644 sql/schema_info.sql diff --git a/cmake/ScriptFiles.cmake b/cmake/ScriptFiles.cmake index 8639787e5..0706c5535 100644 --- a/cmake/ScriptFiles.cmake +++ b/cmake/ScriptFiles.cmake @@ -37,7 +37,6 @@ set(SOURCE_FILES chunk_constraint.sql hypertable_constraint.sql partitioning.sql - schema_info.sql ddl_api.sql ddl_triggers.sql bookend.sql diff --git a/sql/schema_info.sql b/sql/schema_info.sql deleted file mode 100644 index 5300e0d44..000000000 --- a/sql/schema_info.sql +++ /dev/null @@ -1,58 +0,0 @@ --- This file and its contents are licensed under the Apache License 2.0. --- Please see the included NOTICE for copyright information and --- LICENSE-APACHE for a copy of the license. - --- This file contains functions related to getting information about the --- schema of a hypertable, including columns, their types, etc. - - --- Check if a given table OID is a main table (i.e. the table a user --- targets for SQL operations) for a hypertable -CREATE OR REPLACE FUNCTION _timescaledb_internal.is_main_table( - table_oid regclass -) - RETURNS bool LANGUAGE SQL STABLE AS -$BODY$ - SELECT EXISTS(SELECT 1 FROM _timescaledb_catalog.hypertable WHERE table_name = relname AND schema_name = nspname) - FROM pg_class c - INNER JOIN pg_namespace n ON (n.OID = c.relnamespace) - WHERE c.OID = table_oid; -$BODY$ SET search_path TO pg_catalog, pg_temp; - --- Check if given table is a hypertable's main table -CREATE OR REPLACE FUNCTION _timescaledb_internal.is_main_table( - schema_name NAME, - table_name NAME -) - RETURNS BOOLEAN LANGUAGE SQL STABLE AS -$BODY$ - SELECT EXISTS( - SELECT 1 FROM _timescaledb_catalog.hypertable h - WHERE h.schema_name = is_main_table.schema_name AND - h.table_name = is_main_table.table_name - ); -$BODY$ SET search_path TO pg_catalog, pg_temp; - --- Get a hypertable given its main table OID -CREATE OR REPLACE FUNCTION _timescaledb_internal.hypertable_from_main_table( - table_oid regclass -) - RETURNS _timescaledb_catalog.hypertable LANGUAGE SQL STABLE AS -$BODY$ - SELECT h.* - FROM pg_class c - INNER JOIN pg_namespace n ON (n.OID = c.relnamespace) - INNER JOIN _timescaledb_catalog.hypertable h ON (h.table_name = c.relname AND h.schema_name = n.nspname) - WHERE c.OID = table_oid; -$BODY$ SET search_path TO pg_catalog, pg_temp; - -CREATE OR REPLACE FUNCTION _timescaledb_internal.main_table_from_hypertable( - hypertable_id int -) - RETURNS regclass LANGUAGE SQL STABLE AS -$BODY$ - SELECT format('%I.%I',h.schema_name, h.table_name)::regclass - FROM _timescaledb_catalog.hypertable h - WHERE id = hypertable_id; -$BODY$ SET search_path TO pg_catalog, pg_temp; - diff --git a/sql/updates/latest-dev.sql b/sql/updates/latest-dev.sql index 6fd8de8dc..cb3b6ddac 100644 --- a/sql/updates/latest-dev.sql +++ b/sql/updates/latest-dev.sql @@ -44,3 +44,9 @@ ALTER FUNCTION _timescaledb_internal.bookend_finalfunc(internal, anyelement, "an ALTER FUNCTION _timescaledb_internal.bookend_serializefunc(internal) SET SCHEMA _timescaledb_functions; ALTER FUNCTION _timescaledb_internal.bookend_deserializefunc(bytea, internal) SET SCHEMA _timescaledb_functions; +DROP FUNCTION IF EXISTS _timescaledb_internal.is_main_table(regclass); +DROP FUNCTION IF EXISTS _timescaledb_internal.is_main_table(name, name); +DROP FUNCTION IF EXISTS _timescaledb_internal.hypertable_from_main_table(regclass); +DROP FUNCTION IF EXISTS _timescaledb_internal.main_table_from_hypertable(integer); +DROP FUNCTION IF EXISTS _timescaledb_internal.time_literal_sql(bigint, regtype); + diff --git a/sql/updates/reverse-dev.sql b/sql/updates/reverse-dev.sql index 0bfdd06a2..019efad15 100644 --- a/sql/updates/reverse-dev.sql +++ b/sql/updates/reverse-dev.sql @@ -115,3 +115,82 @@ ALTER FUNCTION _timescaledb_functions.bookend_deserializefunc(bytea, internal) S DROP SCHEMA _timescaledb_functions; +CREATE FUNCTION _timescaledb_internal.is_main_table( + table_oid regclass +) + RETURNS bool LANGUAGE SQL STABLE AS +$BODY$ + SELECT EXISTS(SELECT 1 FROM _timescaledb_catalog.hypertable WHERE table_name = relname AND schema_name = nspname) + FROM pg_class c + INNER JOIN pg_namespace n ON (n.OID = c.relnamespace) + WHERE c.OID = table_oid; +$BODY$ SET search_path TO pg_catalog, pg_temp; + +-- Check if given table is a hypertable's main table +CREATE FUNCTION _timescaledb_internal.is_main_table( + schema_name NAME, + table_name NAME +) + RETURNS BOOLEAN LANGUAGE SQL STABLE AS +$BODY$ + SELECT EXISTS( + SELECT 1 FROM _timescaledb_catalog.hypertable h + WHERE h.schema_name = is_main_table.schema_name AND + h.table_name = is_main_table.table_name + ); +$BODY$ SET search_path TO pg_catalog, pg_temp; + +-- Get a hypertable given its main table OID +CREATE FUNCTION _timescaledb_internal.hypertable_from_main_table( + table_oid regclass +) + RETURNS _timescaledb_catalog.hypertable LANGUAGE SQL STABLE AS +$BODY$ + SELECT h.* + FROM pg_class c + INNER JOIN pg_namespace n ON (n.OID = c.relnamespace) + INNER JOIN _timescaledb_catalog.hypertable h ON (h.table_name = c.relname AND h.schema_name = n.nspname) + WHERE c.OID = table_oid; +$BODY$ SET search_path TO pg_catalog, pg_temp; + +CREATE FUNCTION _timescaledb_internal.main_table_from_hypertable( + hypertable_id int +) + RETURNS regclass LANGUAGE SQL STABLE AS +$BODY$ + SELECT format('%I.%I',h.schema_name, h.table_name)::regclass + FROM _timescaledb_catalog.hypertable h + WHERE id = hypertable_id; +$BODY$ SET search_path TO pg_catalog, pg_temp; + +-- Gets the sql code for representing the literal for the given time value (in the internal representation) as the column_type. +CREATE FUNCTION _timescaledb_internal.time_literal_sql( + time_value BIGINT, + column_type REGTYPE +) + RETURNS text LANGUAGE PLPGSQL STABLE AS +$BODY$ +DECLARE + ret text; +BEGIN + IF time_value IS NULL THEN + RETURN format('%L', NULL); + END IF; + CASE column_type + WHEN 'BIGINT'::regtype, 'INTEGER'::regtype, 'SMALLINT'::regtype THEN + RETURN format('%L', time_value); -- scale determined by user. + WHEN 'TIMESTAMP'::regtype THEN + --the time_value for timestamps w/o tz does not depend on local timezones. So perform at UTC. + RETURN format('TIMESTAMP %1$L', timezone('UTC',_timescaledb_internal.to_timestamp(time_value))); -- microseconds + WHEN 'TIMESTAMPTZ'::regtype THEN + -- assume time_value is in microsec + RETURN format('TIMESTAMPTZ %1$L', _timescaledb_internal.to_timestamp(time_value)); -- microseconds + WHEN 'DATE'::regtype THEN + RETURN format('%L', timezone('UTC',_timescaledb_internal.to_timestamp(time_value))::date); + ELSE + EXECUTE 'SELECT format(''%L'', $1::' || column_type::text || ')' into ret using time_value; + RETURN ret; + END CASE; +END +$BODY$ SET search_path TO pg_catalog, pg_temp; + diff --git a/sql/util_time.sql b/sql/util_time.sql index 5502a9023..6645971b9 100644 --- a/sql/util_time.sql +++ b/sql/util_time.sql @@ -27,37 +27,6 @@ CREATE OR REPLACE FUNCTION _timescaledb_internal.to_interval(unixtime_us BIGINT) -- Converting from int* columns to internal representation is a cast to bigint. -- Converting from timestamps to internal representation is conversion to epoch (in microseconds). --- Gets the sql code for representing the literal for the given time value (in the internal representation) as the column_type. -CREATE OR REPLACE FUNCTION _timescaledb_internal.time_literal_sql( - time_value BIGINT, - column_type REGTYPE -) - RETURNS text LANGUAGE PLPGSQL STABLE AS -$BODY$ -DECLARE - ret text; -BEGIN - IF time_value IS NULL THEN - RETURN format('%L', NULL); - END IF; - CASE column_type - WHEN 'BIGINT'::regtype, 'INTEGER'::regtype, 'SMALLINT'::regtype THEN - RETURN format('%L', time_value); -- scale determined by user. - WHEN 'TIMESTAMP'::regtype THEN - --the time_value for timestamps w/o tz does not depend on local timezones. So perform at UTC. - RETURN format('TIMESTAMP %1$L', timezone('UTC',_timescaledb_internal.to_timestamp(time_value))); -- microseconds - WHEN 'TIMESTAMPTZ'::regtype THEN - -- assume time_value is in microsec - RETURN format('TIMESTAMPTZ %1$L', _timescaledb_internal.to_timestamp(time_value)); -- microseconds - WHEN 'DATE'::regtype THEN - RETURN format('%L', timezone('UTC',_timescaledb_internal.to_timestamp(time_value))::date); - ELSE - EXECUTE 'SELECT format(''%L'', $1::' || column_type::text || ')' into ret using time_value; - RETURN ret; - END CASE; -END -$BODY$ SET search_path TO pg_catalog, pg_temp; - CREATE OR REPLACE FUNCTION _timescaledb_internal.interval_to_usec( chunk_interval INTERVAL ) diff --git a/tsl/test/shared/expected/extension.out b/tsl/test/shared/expected/extension.out index b9b0b183f..04e8ec328 100644 --- a/tsl/test/shared/expected/extension.out +++ b/tsl/test/shared/expected/extension.out @@ -92,7 +92,6 @@ ORDER BY pronamespace::regnamespace::text COLLATE "C", p.oid::regprocedure::text _timescaledb_internal.get_time_type(integer) _timescaledb_internal.health() _timescaledb_internal.hypertable_constraint_add_table_fk_constraint(name,name,name,integer) - _timescaledb_internal.hypertable_from_main_table(regclass) _timescaledb_internal.hypertable_invalidation_log_delete(integer) _timescaledb_internal.hypertable_local_size(name,name) _timescaledb_internal.hypertable_remote_size(name,name) @@ -106,9 +105,6 @@ ORDER BY pronamespace::regnamespace::text COLLATE "C", p.oid::regprocedure::text _timescaledb_internal.invalidation_process_cagg_log(integer,integer,regtype,bigint,bigint,integer[],bigint[],bigint[],text[]) _timescaledb_internal.invalidation_process_hypertable_log(integer,integer,regtype,integer[],bigint[],bigint[]) _timescaledb_internal.invalidation_process_hypertable_log(integer,integer,regtype,integer[],bigint[],bigint[],text[]) - _timescaledb_internal.is_main_table(name,name) - _timescaledb_internal.is_main_table(regclass) - _timescaledb_internal.main_table_from_hypertable(integer) _timescaledb_internal.materialization_invalidation_log_delete(integer) _timescaledb_internal.partialize_agg(anyelement) _timescaledb_internal.ping_data_node(name,interval) @@ -140,7 +136,6 @@ ORDER BY pronamespace::regnamespace::text COLLATE "C", p.oid::regprocedure::text _timescaledb_internal.start_background_workers() _timescaledb_internal.stop_background_workers() _timescaledb_internal.subtract_integer_from_now(regclass,bigint) - _timescaledb_internal.time_literal_sql(bigint,regtype) _timescaledb_internal.time_to_internal(anyelement) _timescaledb_internal.to_date(bigint) _timescaledb_internal.to_interval(bigint)