Skip to content

Commit

Permalink
Remove get_chunk_colstats and get_chunk_relstats
Browse files Browse the repository at this point in the history
These 2 functions were used in the multinode context and are no longer
used now.
  • Loading branch information
svenklemm committed Mar 3, 2024
1 parent 5d63aea commit c87be4a
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 237 deletions.
11 changes: 0 additions & 11 deletions sql/chunk.sql
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,6 @@ CREATE OR REPLACE FUNCTION _timescaledb_functions.create_chunk(
RETURNS TABLE(chunk_id INTEGER, hypertable_id INTEGER, schema_name NAME, table_name NAME, relkind "char", slices JSONB, created BOOLEAN)
AS '@MODULE_PATHNAME@', 'ts_chunk_create' LANGUAGE C VOLATILE;

-- Get chunk stats.
CREATE OR REPLACE FUNCTION _timescaledb_functions.get_chunk_relstats(relid REGCLASS)
RETURNS TABLE(chunk_id INTEGER, hypertable_id INTEGER, num_pages INTEGER, num_tuples REAL, num_allvisible INTEGER)
AS '@MODULE_PATHNAME@', 'ts_chunk_get_relstats' LANGUAGE C VOLATILE;

CREATE OR REPLACE FUNCTION _timescaledb_functions.get_chunk_colstats(relid REGCLASS)
RETURNS TABLE(chunk_id INTEGER, hypertable_id INTEGER, att_num INTEGER, nullfrac REAL, width INTEGER, distinctval REAL, slotkind INTEGER[], slotopstrings CSTRING[], slotcollations OID[],
slot1numbers FLOAT4[], slot2numbers FLOAT4[], slot3numbers FLOAT4[], slot4numbers FLOAT4[], slot5numbers FLOAT4[],
slotvaluetypetrings CSTRING[], slot1values CSTRING[], slot2values CSTRING[], slot3values CSTRING[], slot4values CSTRING[], slot5values CSTRING[])
AS '@MODULE_PATHNAME@', 'ts_chunk_get_colstats' LANGUAGE C VOLATILE;

CREATE OR REPLACE FUNCTION _timescaledb_functions.create_chunk_table(
hypertable REGCLASS,
slices JSONB,
Expand Down
20 changes: 0 additions & 20 deletions sql/compat.sql
Original file line number Diff line number Diff line change
Expand Up @@ -258,26 +258,6 @@ END$$
SET search_path TO pg_catalog,pg_temp;


CREATE OR REPLACE FUNCTION _timescaledb_internal.get_chunk_colstats(relid regclass) RETURNS TABLE(chunk_id INTEGER, hypertable_id INTEGER, att_num INTEGER, nullfrac REAL, width INTEGER, distinctval REAL, slotkind INTEGER[], slotopstrings CSTRING[], slotcollations OID[], slot1numbers FLOAT4[], slot2numbers FLOAT4[], slot3numbers FLOAT4[], slot4numbers FLOAT4[], slot5numbers FLOAT4[], slotvaluetypetrings CSTRING[], slot1values CSTRING[], slot2values CSTRING[], slot3values CSTRING[], slot4values CSTRING[], slot5values CSTRING[]) LANGUAGE PLPGSQL AS $$
BEGIN
IF current_setting('timescaledb.enable_deprecation_warnings', true)::bool THEN
RAISE WARNING 'function _timescaledb_internal.get_chunk_colstats(regclass) is deprecated and has been moved to _timescaledb_functions schema. this compatibility function will be removed in a future version.';
END IF;
RETURN QUERY SELECT * FROM _timescaledb_functions.get_chunk_colstats($1);
END$$
SET search_path TO pg_catalog,pg_temp;


CREATE OR REPLACE FUNCTION _timescaledb_internal.get_chunk_relstats(relid regclass) RETURNS TABLE(chunk_id INTEGER, hypertable_id INTEGER, num_pages INTEGER, num_tuples REAL, num_allvisible INTEGER) LANGUAGE PLPGSQL AS $$
BEGIN
IF current_setting('timescaledb.enable_deprecation_warnings', true)::bool THEN
RAISE WARNING 'function _timescaledb_internal.get_chunk_relstats(regclass) is deprecated and has been moved to _timescaledb_functions schema. this compatibility function will be removed in a future version.';
END IF;
RETURN QUERY SELECT * FROM _timescaledb_functions.get_chunk_relstats($1);
END$$
SET search_path TO pg_catalog,pg_temp;


CREATE OR REPLACE FUNCTION _timescaledb_internal.get_compressed_chunk_index_for_recompression(uncompressed_chunk regclass) RETURNS regclass LANGUAGE PLPGSQL AS $$
BEGIN
IF current_setting('timescaledb.enable_deprecation_warnings', true)::bool THEN
Expand Down
7 changes: 7 additions & 0 deletions sql/updates/latest-dev.sql
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,10 @@ UPDATE _timescaledb_catalog.continuous_aggs_bucket_function SET bucket_timezone
-- So far, there were no difference between 0 and -1 retries. Since now on, 0 means no retries. Updating the retry
-- count of existing jobs to -1 to keep the current semantics.
UPDATE _timescaledb_config.bgw_job SET max_retries = -1 WHERE max_retries = 0;

DROP FUNCTION IF EXISTS _timescaledb_functions.get_chunk_relstats;
DROP FUNCTION IF EXISTS _timescaledb_functions.get_chunk_colstats;
DROP FUNCTION IF EXISTS _timescaledb_internal.get_chunk_relstats;
DROP FUNCTION IF EXISTS _timescaledb_internal.get_chunk_colstats;


11 changes: 11 additions & 0 deletions sql/updates/reverse-dev.sql
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,14 @@ ANALYZE _timescaledb_catalog.continuous_aggs_bucket_function;
UPDATE _timescaledb_catalog.continuous_aggs_bucket_function
SET origin = origin::timestamptz::timestamp::text
WHERE length(origin) > 1;

-- only create stub
CREATE FUNCTION _timescaledb_functions.get_chunk_relstats(relid REGCLASS)
RETURNS TABLE(chunk_id INTEGER, hypertable_id INTEGER, num_pages INTEGER, num_tuples REAL, num_allvisible INTEGER)
AS $$BEGIN END$$ LANGUAGE plpgsql SET search_path = pg_catalog, pg_temp;

CREATE FUNCTION _timescaledb_functions.get_chunk_colstats(relid REGCLASS)
RETURNS TABLE(chunk_id INTEGER, hypertable_id INTEGER, att_num INTEGER, nullfrac REAL, width INTEGER, distinctval REAL, slotkind INTEGER[], slotopstrings CSTRING[], slotcollations OID[], slot1numbers FLOAT4[], slot2numbers FLOAT4[], slot3numbers FLOAT4[], slot4numbers FLOAT4[], slot5numbers FLOAT4[], slotvaluetypetrings CSTRING[], slot1values CSTRING[], slot2values CSTRING[], slot3values CSTRING[], slot4values CSTRING[], slot5values CSTRING[])
AS $$BEGIN END$$ LANGUAGE plpgsql SET search_path = pg_catalog, pg_temp;


4 changes: 0 additions & 4 deletions src/cross_module_fn.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ CROSSMODULE_WRAPPER(cagg_try_repair);
CROSSMODULE_WRAPPER(chunk_freeze_chunk);
CROSSMODULE_WRAPPER(chunk_unfreeze_chunk);

CROSSMODULE_WRAPPER(chunk_get_relstats);
CROSSMODULE_WRAPPER(chunk_get_colstats);
CROSSMODULE_WRAPPER(chunk_create_empty_table);

CROSSMODULE_WRAPPER(recompress_chunk_segmentwise);
Expand Down Expand Up @@ -364,8 +362,6 @@ TSDLLEXPORT CrossModuleFunctions ts_cm_functions_default = {
.create_chunk = error_no_default_fn_pg_community,
.chunk_freeze_chunk = error_no_default_fn_pg_community,
.chunk_unfreeze_chunk = error_no_default_fn_pg_community,
.chunk_get_relstats = error_no_default_fn_pg_community,
.chunk_get_colstats = error_no_default_fn_pg_community,
.chunk_create_empty_table = error_no_default_fn_pg_community,
.recompress_chunk_segmentwise = error_no_default_fn_pg_community,
.get_compressed_chunk_index_for_recompression = error_no_default_fn_pg_community,
Expand Down
2 changes: 0 additions & 2 deletions src/cross_module_fn.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ typedef struct CrossModuleFunctions
PGFunction create_chunk;
PGFunction show_chunk;

PGFunction chunk_get_relstats;
PGFunction chunk_get_colstats;
PGFunction chunk_create_empty_table;
PGFunction chunk_freeze_chunk;
PGFunction chunk_unfreeze_chunk;
Expand Down
2 changes: 0 additions & 2 deletions tsl/src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ CrossModuleFunctions tsl_cm_functions = {
.chunk_freeze_chunk = chunk_freeze_chunk,
.chunk_unfreeze_chunk = chunk_unfreeze_chunk,
.set_rel_pathlist = tsl_set_rel_pathlist,
.chunk_get_relstats = chunk_api_get_chunk_relstats,
.chunk_get_colstats = chunk_api_get_chunk_colstats,
.chunk_create_empty_table = chunk_create_empty_table,
.recompress_chunk_segmentwise = tsl_recompress_chunk_segmentwise,
.get_compressed_chunk_index_for_recompression =
Expand Down
131 changes: 2 additions & 129 deletions tsl/test/expected/chunk_api.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ GRANT CREATE ON DATABASE :"TEST_DBNAME" TO :ROLE_DEFAULT_PERM_USER;
SET ROLE :ROLE_DEFAULT_PERM_USER;
CREATE SCHEMA "ChunkSchema";
-- Use range types as well for columns
CREATE TABLE chunkapi (time timestamptz, device int, temp float, rng int8range);
CREATE TABLE chunkapi(time timestamptz not null, device int, temp float, rng int8range);
SELECT * FROM create_hypertable('chunkapi', 'time', 'device', 2);
NOTICE: adding not-null constraint to column "time"
hypertable_id | schema_name | table_name | created
---------------+-------------+------------+---------
1 | public | chunkapi | t
Expand Down Expand Up @@ -128,131 +127,6 @@ SELECT * FROM _timescaledb_functions.create_chunk('chunkapi',' {"time": [1515024
(1 row)

SET ROLE :ROLE_DEFAULT_PERM_USER;
\set VERBOSITY terse
SELECT (_timescaledb_functions.show_chunk(show_chunks)).*
FROM show_chunks('chunkapi')
ORDER BY chunk_id;
chunk_id | hypertable_id | schema_name | table_name | relkind | slices
----------+---------------+-----------------------+---------------------+---------+----------------------------------------------------------------------------------------------
1 | 1 | _timescaledb_internal | _hyper_1_1_chunk | r | {"time": [1514419200000000, 1515024000000000], "device": [-9223372036854775808, 1073741823]}
2 | 1 | ChunkSchema | My_chunk_Table_name | r | {"time": [1515024000000000, 1519024000000000], "device": [-9223372036854775808, 1073741823]}
(2 rows)

-- Show the new chunks
\dt public.*
List of relations
Schema | Name | Type | Owner
--------+----------+-------+-------------------
public | chunkapi | table | default_perm_user
(1 row)

\dt "ChunkSchema".*
List of relations
Schema | Name | Type | Owner
-------------+---------------------+-------+-------------------
ChunkSchema | My_chunk_Table_name | table | default_perm_user
(1 row)

-- Make ANALYZE deterministic
SELECT setseed(1);
setseed
---------

(1 row)

-- Test getting relation stats for chunks. First get stats
-- chunk-by-chunk. Note that the table isn't ANALYZED, so no stats
-- present yet.
SELECT (_timescaledb_functions.get_chunk_relstats(show_chunks)).*
FROM show_chunks('chunkapi')
ORDER BY chunk_id;
chunk_id | hypertable_id | num_pages | num_tuples | num_allvisible
----------+---------------+-----------+------------+----------------
1 | 1 | 0 | 0 | 0
2 | 1 | 0 | 0 | 0
(2 rows)

SELECT (_timescaledb_functions.get_chunk_colstats(show_chunks)).*
FROM show_chunks('chunkapi')
ORDER BY chunk_id;
chunk_id | hypertable_id | att_num | nullfrac | width | distinctval | slotkind | slotopstrings | slotcollations | slot1numbers | slot2numbers | slot3numbers | slot4numbers | slot5numbers | slotvaluetypetrings | slot1values | slot2values | slot3values | slot4values | slot5values
----------+---------------+---------+----------+-------+-------------+----------+---------------+----------------+--------------+--------------+--------------+--------------+--------------+---------------------+-------------+-------------+-------------+-------------+-------------
(0 rows)

-- Get the same stats but by giving the hypertable as input
SELECT * FROM _timescaledb_functions.get_chunk_relstats('chunkapi');
chunk_id | hypertable_id | num_pages | num_tuples | num_allvisible
----------+---------------+-----------+------------+----------------
1 | 1 | 0 | 0 | 0
2 | 1 | 0 | 0 | 0
(2 rows)

SELECT * FROM _timescaledb_functions.get_chunk_colstats('chunkapi');
chunk_id | hypertable_id | att_num | nullfrac | width | distinctval | slotkind | slotopstrings | slotcollations | slot1numbers | slot2numbers | slot3numbers | slot4numbers | slot5numbers | slotvaluetypetrings | slot1values | slot2values | slot3values | slot4values | slot5values
----------+---------------+---------+----------+-------+-------------+----------+---------------+----------------+--------------+--------------+--------------+--------------+--------------+---------------------+-------------+-------------+-------------+-------------+-------------
(0 rows)

-- reltuples is -1 on PG14 when no VACUUM/ANALYZE has run yet
SELECT relname, CASE WHEN reltuples > 0 THEN reltuples ELSE 0 END AS reltuples, relpages, relallvisible FROM pg_class WHERE relname IN
(SELECT (_timescaledb_functions.show_chunk(show_chunks)).table_name
FROM show_chunks('chunkapi'))
ORDER BY relname;
relname | reltuples | relpages | relallvisible
---------------------+-----------+----------+---------------
My_chunk_Table_name | 0 | 0 | 0
_hyper_1_1_chunk | 0 | 0 | 0
(2 rows)

SELECT tablename, attname, inherited, null_frac, avg_width, n_distinct
FROM pg_stats WHERE tablename IN
(SELECT (_timescaledb_functions.show_chunk(show_chunks)).table_name
FROM show_chunks('chunkapi'))
ORDER BY tablename, attname;
tablename | attname | inherited | null_frac | avg_width | n_distinct
-----------+---------+-----------+-----------+-----------+------------
(0 rows)

-- Show stats after analyze
ANALYZE chunkapi;
SELECT * FROM _timescaledb_functions.get_chunk_relstats('chunkapi');
chunk_id | hypertable_id | num_pages | num_tuples | num_allvisible
----------+---------------+-----------+------------+----------------
1 | 1 | 1 | 1 | 0
2 | 1 | 0 | 0 | 0
(2 rows)

SELECT * FROM _timescaledb_functions.get_chunk_colstats('chunkapi');
chunk_id | hypertable_id | att_num | nullfrac | width | distinctval | slotkind | slotopstrings | slotcollations | slot1numbers | slot2numbers | slot3numbers | slot4numbers | slot5numbers | slotvaluetypetrings | slot1values | slot2values | slot3values | slot4values | slot5values
----------+---------------+---------+----------+-------+-------------+-------------+----------------------------------------------------+----------------+--------------+--------------+--------------+--------------+--------------+---------------------+-------------+-------------+-------------+-------------+-------------
1 | 1 | 1 | 0 | 8 | -1 | {0,0,0,0,0} | {} | {0,0,0,0,0} | | | | | | {} | | | | |
1 | 1 | 2 | 0 | 4 | -1 | {0,0,0,0,0} | {} | {0,0,0,0,0} | | | | | | {} | | | | |
1 | 1 | 3 | 0 | 8 | -1 | {0,0,0,0,0} | {} | {0,0,0,0,0} | | | | | | {} | | | | |
1 | 1 | 4 | 0 | 22 | -1 | {6,0,0,0,0} | {<,pg_catalog,float8,pg_catalog,float8,pg_catalog} | {0,0,0,0,0} | {0} | | | | | {} | | | | |
(4 rows)

SELECT relname, reltuples, relpages, relallvisible FROM pg_class WHERE relname IN
(SELECT (_timescaledb_functions.show_chunk(show_chunks)).table_name
FROM show_chunks('chunkapi'))
ORDER BY relname;
relname | reltuples | relpages | relallvisible
---------------------+-----------+----------+---------------
My_chunk_Table_name | 0 | 0 | 0
_hyper_1_1_chunk | 1 | 1 | 0
(2 rows)

SELECT tablename, attname, inherited, null_frac, avg_width, n_distinct
FROM pg_stats WHERE tablename IN
(SELECT (_timescaledb_functions.show_chunk(show_chunks)).table_name
FROM show_chunks('chunkapi'))
ORDER BY tablename, attname;
tablename | attname | inherited | null_frac | avg_width | n_distinct
------------------+---------+-----------+-----------+-----------+------------
_hyper_1_1_chunk | device | f | 0 | 4 | -1
_hyper_1_1_chunk | rng | f | 0 | 22 | -1
_hyper_1_1_chunk | temp | f | 0 | 8 | -1
_hyper_1_1_chunk | time | f | 0 | 8 | -1
(4 rows)

-- Test create_chunk_table to recreate the chunk table and show dimension slices
SET ROLE :ROLE_DEFAULT_PERM_USER;
SELECT * FROM chunkapi ORDER BY time;
Expand Down Expand Up @@ -320,9 +194,8 @@ ERROR: relation "_hyper_1_1_chunk" already exists
-- Test create_chunk_table on a hypertable where the chunk didn't exist before
DROP TABLE chunkapi;
DROP TABLE :CHUNK_SCHEMA.:CHUNK_NAME;
CREATE TABLE chunkapi (time timestamptz, device int, temp float);
CREATE TABLE chunkapi(time timestamptz not null, device int, temp float);
SELECT * FROM create_hypertable('chunkapi', 'time', 'device', 2);
NOTICE: adding not-null constraint to column "time"
hypertable_id | schema_name | table_name | created
---------------+-------------+------------+---------
2 | public | chunkapi | t
Expand Down
6 changes: 0 additions & 6 deletions tsl/test/shared/expected/compat.out
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,6 @@ WARNING: function _timescaledb_internal.get_approx_row_count(regclass) is depre
0
(1 row)

SELECT _timescaledb_internal.get_chunk_colstats(0);
WARNING: function _timescaledb_internal.get_chunk_colstats(regclass) is deprecated and has been moved to _timescaledb_functions schema. this compatibility function will be removed in a future version.
ERROR: invalid table
SELECT _timescaledb_internal.get_chunk_relstats(0);
WARNING: function _timescaledb_internal.get_chunk_relstats(regclass) is deprecated and has been moved to _timescaledb_functions schema. this compatibility function will be removed in a future version.
ERROR: invalid table
SELECT _timescaledb_internal.get_compressed_chunk_index_for_recompression(0);
WARNING: function _timescaledb_internal.get_compressed_chunk_index_for_recompression(regclass) is deprecated and has been moved to _timescaledb_functions schema. this compatibility function will be removed in a future version.
ERROR: invalid Oid
Expand Down
4 changes: 0 additions & 4 deletions tsl/test/shared/expected/extension.out
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ ORDER BY pronamespace::regnamespace::text COLLATE "C", p.oid::regprocedure::text
_timescaledb_functions.freeze_chunk(regclass)
_timescaledb_functions.generate_uuid()
_timescaledb_functions.get_approx_row_count(regclass)
_timescaledb_functions.get_chunk_colstats(regclass)
_timescaledb_functions.get_chunk_relstats(regclass)
_timescaledb_functions.get_compressed_chunk_index_for_recompression(regclass)
_timescaledb_functions.get_create_command(name)
_timescaledb_functions.get_git_commit()
Expand Down Expand Up @@ -161,8 +159,6 @@ ORDER BY pronamespace::regnamespace::text COLLATE "C", p.oid::regprocedure::text
_timescaledb_internal.freeze_chunk(regclass)
_timescaledb_internal.generate_uuid()
_timescaledb_internal.get_approx_row_count(regclass)
_timescaledb_internal.get_chunk_colstats(regclass)
_timescaledb_internal.get_chunk_relstats(regclass)
_timescaledb_internal.get_compressed_chunk_index_for_recompression(regclass)
_timescaledb_internal.get_create_command(name)
_timescaledb_internal.get_git_commit()
Expand Down
2 changes: 0 additions & 2 deletions tsl/test/shared/sql/compat.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ SELECT _timescaledb_internal.drop_chunk(0);
SELECT _timescaledb_internal.freeze_chunk(0);
SELECT FROM _timescaledb_internal.generate_uuid();
SELECT _timescaledb_internal.get_approx_row_count(0);
SELECT _timescaledb_internal.get_chunk_colstats(0);
SELECT _timescaledb_internal.get_chunk_relstats(0);
SELECT _timescaledb_internal.get_compressed_chunk_index_for_recompression(0);
SELECT _timescaledb_internal.get_create_command(NULL);
SELECT pg_typeof(_timescaledb_internal.get_git_commit());
Expand Down

0 comments on commit c87be4a

Please sign in to comment.