mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-15 18:13:18 +08:00
Add hypertable_index_size function
Function to compute the size for a specific index of a hypertable
This commit is contained in:
parent
e40d70716e
commit
eecc93f3b6
@ -74,7 +74,7 @@ RETURNS TABLE (
|
||||
index_bytes bigint,
|
||||
toast_bytes bigint,
|
||||
total_bytes bigint)
|
||||
LANGUAGE PLPGSQL STABLE STRICT AS
|
||||
LANGUAGE PLPGSQL VOLATILE STRICT AS
|
||||
$BODY$
|
||||
BEGIN
|
||||
RETURN QUERY
|
||||
@ -118,7 +118,7 @@ RETURNS TABLE (
|
||||
toast_bytes bigint,
|
||||
total_bytes bigint,
|
||||
node_name NAME)
|
||||
LANGUAGE PLPGSQL STABLE STRICT AS
|
||||
LANGUAGE PLPGSQL VOLATILE STRICT AS
|
||||
$BODY$
|
||||
BEGIN
|
||||
RETURN QUERY
|
||||
@ -169,8 +169,8 @@ RETURNS TABLE (table_bytes BIGINT,
|
||||
toast_bytes BIGINT,
|
||||
total_bytes BIGINT,
|
||||
node_name NAME
|
||||
) LANGUAGE PLPGSQL STABLE STRICT
|
||||
AS
|
||||
)
|
||||
LANGUAGE PLPGSQL VOLATILE STRICT AS
|
||||
$BODY$
|
||||
DECLARE
|
||||
table_name NAME;
|
||||
@ -197,7 +197,7 @@ CREATE OR REPLACE FUNCTION hypertable_size(
|
||||
main_table REGCLASS
|
||||
)
|
||||
RETURNS BIGINT
|
||||
LANGUAGE PLPGSQL STABLE STRICT AS
|
||||
LANGUAGE PLPGSQL VOLATILE STRICT AS
|
||||
$BODY$
|
||||
DECLARE
|
||||
num_bytes BIGINT;
|
||||
@ -219,7 +219,7 @@ RETURNS TABLE (
|
||||
index_bytes bigint,
|
||||
toast_bytes bigint,
|
||||
total_bytes bigint)
|
||||
LANGUAGE PLPGSQL STABLE STRICT AS
|
||||
LANGUAGE PLPGSQL VOLATILE STRICT AS
|
||||
$BODY$
|
||||
BEGIN
|
||||
RETURN QUERY
|
||||
@ -253,7 +253,7 @@ RETURNS TABLE (
|
||||
toast_bytes bigint,
|
||||
total_bytes bigint,
|
||||
node_name NAME)
|
||||
LANGUAGE PLPGSQL STABLE STRICT AS
|
||||
LANGUAGE PLPGSQL VOLATILE STRICT AS
|
||||
$BODY$
|
||||
BEGIN
|
||||
RETURN QUERY
|
||||
@ -310,8 +310,7 @@ RETURNS TABLE (
|
||||
toast_bytes BIGINT,
|
||||
total_bytes BIGINT,
|
||||
node_name NAME)
|
||||
LANGUAGE PLPGSQL STABLE STRICT
|
||||
AS
|
||||
LANGUAGE PLPGSQL VOLATILE STRICT AS
|
||||
$BODY$
|
||||
DECLARE
|
||||
table_name NAME;
|
||||
@ -338,53 +337,6 @@ END;
|
||||
$BODY$;
|
||||
---------- end of detailed size functions ------
|
||||
|
||||
-- Get sizes of indexes on a hypertable
|
||||
--
|
||||
-- main_table - hypertable to get index sizes of
|
||||
--
|
||||
-- Returns:
|
||||
-- index_name - index on hyper table
|
||||
-- total_bytes - size of index on disk
|
||||
|
||||
CREATE OR REPLACE FUNCTION indexes_relation_size(
|
||||
main_table REGCLASS
|
||||
)
|
||||
RETURNS TABLE (index_name TEXT,
|
||||
total_bytes BIGINT)
|
||||
LANGUAGE PLPGSQL STABLE STRICT
|
||||
AS
|
||||
$BODY$
|
||||
<<main>>
|
||||
DECLARE
|
||||
table_name NAME;
|
||||
schema_name NAME;
|
||||
BEGIN
|
||||
SELECT relname, nspname
|
||||
INTO STRICT table_name, schema_name
|
||||
FROM pg_class c
|
||||
INNER JOIN pg_namespace n ON (n.OID = c.relnamespace)
|
||||
WHERE c.OID = main_table;
|
||||
|
||||
RETURN QUERY
|
||||
SELECT format('%I.%I', h.schema_name, ci.hypertable_index_name),
|
||||
sum(pg_relation_size(c.oid))::bigint
|
||||
FROM
|
||||
pg_class c,
|
||||
pg_namespace n,
|
||||
_timescaledb_catalog.hypertable h,
|
||||
_timescaledb_catalog.chunk ch,
|
||||
_timescaledb_catalog.chunk_index ci
|
||||
WHERE ch.schema_name = n.nspname
|
||||
AND c.relnamespace = n.oid
|
||||
AND c.relname = ci.index_name
|
||||
AND ch.id = ci.chunk_id
|
||||
AND h.id = ci.hypertable_id
|
||||
AND h.schema_name = main.schema_name
|
||||
AND h.table_name = main.table_name
|
||||
GROUP BY h.schema_name, ci.hypertable_index_name;
|
||||
END;
|
||||
$BODY$;
|
||||
|
||||
CREATE OR REPLACE FUNCTION _timescaledb_internal.range_value_to_pretty(
|
||||
time_value BIGINT,
|
||||
column_type REGTYPE
|
||||
@ -682,3 +634,122 @@ BEGIN
|
||||
END;
|
||||
$BODY$;
|
||||
|
||||
-------------Get index size for hypertables -------
|
||||
--schema_name - schema_name for hypertable index
|
||||
-- index_name - index on hyper table
|
||||
---note that the query matches against the hypertable's schema name as
|
||||
-- the input is on the hypertable index nd not the chunk index.
|
||||
CREATE OR REPLACE FUNCTION _timescaledb_internal.indexes_local_size(
|
||||
schema_name_in NAME,
|
||||
index_name_in NAME
|
||||
)
|
||||
RETURNS TABLE ( hypertable_id INTEGER,
|
||||
total_bytes BIGINT )
|
||||
LANGUAGE PLPGSQL VOLATILE STRICT AS
|
||||
$BODY$
|
||||
BEGIN
|
||||
RETURN QUERY
|
||||
SELECT ci.hypertable_id, sum(pg_relation_size(c.oid))::bigint
|
||||
FROM
|
||||
pg_class c,
|
||||
pg_namespace n,
|
||||
_timescaledb_catalog.hypertable h,
|
||||
_timescaledb_catalog.chunk ch,
|
||||
_timescaledb_catalog.chunk_index ci
|
||||
WHERE ch.schema_name = n.nspname
|
||||
AND c.relnamespace = n.oid
|
||||
AND c.relname = ci.index_name
|
||||
AND ch.id = ci.chunk_id
|
||||
AND h.id = ci.hypertable_id
|
||||
AND h.schema_name = schema_name_in
|
||||
AND ci.hypertable_index_name = index_name_in
|
||||
GROUP BY ci.hypertable_id;
|
||||
END;
|
||||
$BODY$;
|
||||
|
||||
CREATE OR REPLACE FUNCTION _timescaledb_internal.data_node_index_size (node_name name, schema_name_in name, index_name_in name)
|
||||
RETURNS TABLE ( hypertable_id INTEGER, total_bytes BIGINT)
|
||||
AS '@MODULE_PATHNAME@' , 'ts_dist_remote_hypertable_index_info' LANGUAGE C VOLATILE STRICT;
|
||||
|
||||
CREATE OR REPLACE FUNCTION _timescaledb_internal.indexes_remote_size(
|
||||
schema_name_in NAME,
|
||||
table_name_in NAME,
|
||||
index_name_in NAME
|
||||
)
|
||||
RETURNS BIGINT
|
||||
LANGUAGE PLPGSQL VOLATILE STRICT AS
|
||||
$BODY$
|
||||
DECLARE
|
||||
total_bytes BIGINT;
|
||||
BEGIN
|
||||
SELECT
|
||||
sum(entry.total_bytes)::bigint AS total_bytes
|
||||
INTO total_bytes
|
||||
FROM (
|
||||
SELECT
|
||||
s.node_name,
|
||||
_timescaledb_internal.ping_data_node (s.node_name) AS node_up
|
||||
FROM
|
||||
_timescaledb_catalog.hypertable AS ht,
|
||||
_timescaledb_catalog.hypertable_data_node AS s
|
||||
WHERE
|
||||
ht.schema_name = schema_name_in
|
||||
AND ht.table_name = table_name_in
|
||||
AND s.hypertable_id = ht.id
|
||||
) AS srv
|
||||
JOIN LATERAL _timescaledb_internal.data_node_index_size(
|
||||
CASE WHEN srv.node_up THEN
|
||||
srv.node_name
|
||||
ELSE
|
||||
NULL
|
||||
END, schema_name_in, index_name_in) entry ON TRUE ;
|
||||
RETURN total_bytes;
|
||||
END;
|
||||
$BODY$;
|
||||
|
||||
-- Get sizes of indexes on a hypertable
|
||||
--
|
||||
-- index_name - index on hyper table
|
||||
--
|
||||
-- Returns:
|
||||
-- total_bytes - size of index on disk
|
||||
|
||||
CREATE OR REPLACE FUNCTION hypertable_index_size(
|
||||
index_name REGCLASS
|
||||
)
|
||||
RETURNS BIGINT
|
||||
LANGUAGE PLPGSQL VOLATILE STRICT AS
|
||||
$BODY$
|
||||
DECLARE
|
||||
ht_index_name NAME;
|
||||
ht_schema_name NAME;
|
||||
ht_name NAME;
|
||||
is_distributed BOOL;
|
||||
ht_id INTEGER;
|
||||
index_bytes BIGINT;
|
||||
BEGIN
|
||||
|
||||
SELECT c.relname, cl.relname, nsp.nspname
|
||||
INTO STRICT ht_index_name, ht_name, ht_schema_name
|
||||
FROM pg_class c, pg_index cind, pg_class cl, pg_namespace nsp
|
||||
WHERE c.oid = cind.indexrelid AND cind.indrelid = cl.oid
|
||||
AND cl.relnamespace = nsp.oid AND c.oid = index_name;
|
||||
|
||||
SELECT replication_factor > 0
|
||||
INTO STRICT is_distributed
|
||||
FROM _timescaledb_catalog.hypertable ht
|
||||
WHERE ht.schema_name = ht_schema_name AND ht.table_name = ht_name;
|
||||
|
||||
CASE WHEN is_distributed THEN
|
||||
SELECT _timescaledb_internal.indexes_remote_size(ht_schema_name, ht_name, ht_index_name)
|
||||
INTO index_bytes ;
|
||||
ELSE
|
||||
SELECT il.total_bytes
|
||||
INTO index_bytes
|
||||
FROM _timescaledb_internal.indexes_local_size(ht_schema_name, ht_index_name) il;
|
||||
END CASE;
|
||||
RETURN index_bytes;
|
||||
END;
|
||||
$BODY$;
|
||||
|
||||
-------------End index size for hypertables -------
|
||||
|
@ -83,6 +83,7 @@ CROSSMODULE_WRAPPER(remote_connection_cache_show);
|
||||
CROSSMODULE_WRAPPER(dist_remote_hypertable_info);
|
||||
CROSSMODULE_WRAPPER(dist_remote_chunk_info);
|
||||
CROSSMODULE_WRAPPER(dist_remote_compressed_chunk_info);
|
||||
CROSSMODULE_WRAPPER(dist_remote_hypertable_index_info);
|
||||
CROSSMODULE_WRAPPER(distributed_exec);
|
||||
CROSSMODULE_WRAPPER(hypertable_distributed_set_replication_factor);
|
||||
|
||||
@ -415,6 +416,7 @@ TSDLLEXPORT CrossModuleFunctions ts_cm_functions_default = {
|
||||
.dist_remote_hypertable_info = error_no_default_fn_pg_community,
|
||||
.dist_remote_chunk_info = error_no_default_fn_pg_community,
|
||||
.dist_remote_compressed_chunk_info = error_no_default_fn_pg_community,
|
||||
.dist_remote_hypertable_index_info = error_no_default_fn_pg_community,
|
||||
.validate_as_data_node = error_no_default_fn_community,
|
||||
.func_call_on_data_nodes = func_call_on_data_nodes_default,
|
||||
.chunk_get_relstats = error_no_default_fn_pg_community,
|
||||
|
@ -150,6 +150,7 @@ typedef struct CrossModuleFunctions
|
||||
PGFunction dist_remote_hypertable_info;
|
||||
PGFunction dist_remote_chunk_info;
|
||||
PGFunction dist_remote_compressed_chunk_info;
|
||||
PGFunction dist_remote_hypertable_index_info;
|
||||
void (*validate_as_data_node)(void);
|
||||
void (*func_call_on_data_nodes)(FunctionCallInfo fcinfo, List *data_node_oids);
|
||||
PGFunction distributed_exec;
|
||||
|
@ -47,8 +47,8 @@ WHERE oid IN (
|
||||
hypertable_approximate_row_count
|
||||
hypertable_compression_stats
|
||||
hypertable_detailed_size
|
||||
hypertable_index_size
|
||||
hypertable_size
|
||||
indexes_relation_size
|
||||
interpolate
|
||||
last
|
||||
locf
|
||||
|
@ -164,12 +164,17 @@ SELECT * FROM "testSchema0".hypertable_detailed_size('test_ts');
|
||||
(1 row)
|
||||
|
||||
-- testing hypertable_detailed_size END
|
||||
SELECT * FROM "testSchema0".indexes_relation_size('test_ts') ORDER BY index_name;
|
||||
index_name | total_bytes
|
||||
--------------------------------+-------------
|
||||
public.test_ts_device_time_idx | 32768
|
||||
public.test_ts_time_idx | 32768
|
||||
(2 rows)
|
||||
SELECT * FROM "testSchema0".hypertable_index_size('test_ts_time_idx');
|
||||
hypertable_index_size
|
||||
-----------------------
|
||||
32768
|
||||
(1 row)
|
||||
|
||||
SELECT * FROM "testSchema0".hypertable_index_size('test_ts_device_time_idx');
|
||||
hypertable_index_size
|
||||
-----------------------
|
||||
32768
|
||||
(1 row)
|
||||
|
||||
CREATE SCHEMA "testSchema";
|
||||
\set ON_ERROR_STOP 0
|
||||
|
@ -48,17 +48,47 @@ SELECT * FROM hypertable_detailed_size('"public"."two_Partitions"');
|
||||
32768 | 417792 | 32768 | 483328 |
|
||||
(1 row)
|
||||
|
||||
SELECT * FROM indexes_relation_size('"public"."two_Partitions"');
|
||||
index_name | total_bytes
|
||||
----------------------------------------------------+-------------
|
||||
public."two_Partitions_device_id_timeCustom_idx" | 65536
|
||||
public."two_Partitions_timeCustom_device_id_idx" | 65536
|
||||
public."two_Partitions_timeCustom_idx" | 65536
|
||||
public."two_Partitions_timeCustom_series_0_idx" | 65536
|
||||
public."two_Partitions_timeCustom_series_1_idx" | 65536
|
||||
public."two_Partitions_timeCustom_series_2_idx" | 40960
|
||||
public."two_Partitions_timeCustom_series_bool_idx" | 49152
|
||||
(7 rows)
|
||||
SELECT * FROM hypertable_index_size('"public"."two_Partitions_device_id_timeCustom_idx"');
|
||||
hypertable_index_size
|
||||
-----------------------
|
||||
65536
|
||||
(1 row)
|
||||
|
||||
SELECT * FROM hypertable_index_size('"public"."two_Partitions_timeCustom_device_id_idx"');
|
||||
hypertable_index_size
|
||||
-----------------------
|
||||
65536
|
||||
(1 row)
|
||||
|
||||
SELECT * FROM hypertable_index_size('"public"."two_Partitions_timeCustom_idx"');
|
||||
hypertable_index_size
|
||||
-----------------------
|
||||
65536
|
||||
(1 row)
|
||||
|
||||
SELECT * FROM hypertable_index_size('"public"."two_Partitions_timeCustom_series_0_idx"');
|
||||
hypertable_index_size
|
||||
-----------------------
|
||||
65536
|
||||
(1 row)
|
||||
|
||||
SELECT * FROM hypertable_index_size('"public"."two_Partitions_timeCustom_series_1_idx"');
|
||||
hypertable_index_size
|
||||
-----------------------
|
||||
65536
|
||||
(1 row)
|
||||
|
||||
SELECT * FROM hypertable_index_size('"public"."two_Partitions_timeCustom_series_2_idx"');
|
||||
hypertable_index_size
|
||||
-----------------------
|
||||
40960
|
||||
(1 row)
|
||||
|
||||
SELECT * FROM hypertable_index_size('"public"."two_Partitions_timeCustom_series_bool_idx"');
|
||||
hypertable_index_size
|
||||
-----------------------
|
||||
49152
|
||||
(1 row)
|
||||
|
||||
SELECT * FROM chunks_detailed_size('"public"."two_Partitions"') order by chunk_name;
|
||||
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
|
||||
@ -179,8 +209,14 @@ SELECT * FROM hypertable_detailed_size(NULL);
|
||||
-------------+-------------+-------------+-------------+-----------
|
||||
(0 rows)
|
||||
|
||||
SELECT * FROM indexes_relation_size(NULL);
|
||||
index_name | total_bytes
|
||||
------------+-------------
|
||||
(0 rows)
|
||||
SELECT * FROM hypertable_index_size(NULL);
|
||||
hypertable_index_size
|
||||
-----------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
-- tests with tables that are not hypertables
|
||||
CREATE TABLE regtab( a integer, b integer);
|
||||
CREATE INDEX regtab_idx ON regtab( a);
|
||||
SELECT * FROM hypertable_index_size('regtab_idx');
|
||||
ERROR: query returned no rows
|
||||
|
@ -6,10 +6,10 @@ step I1: INSERT INTO ts_index_test VALUES (31, 6.4, 1);
|
||||
step Ic: COMMIT;
|
||||
step Bc: ROLLBACK;
|
||||
step CI: <... completed>
|
||||
step P: SELECT pg_size_pretty(total_bytes) as total_size FROM indexes_relation_size('ts_index_test');
|
||||
total_size
|
||||
step P: SELECT * FROM hypertable_index_size('test_index');
|
||||
hypertable_index_size
|
||||
|
||||
64 kB
|
||||
65536
|
||||
step Sc: COMMIT;
|
||||
|
||||
starting permutation: I1 CI Bc Ic P Sc
|
||||
@ -18,10 +18,10 @@ step CI: CREATE INDEX test_index ON ts_index_test(location) WITH (timescaledb.tr
|
||||
step Bc: ROLLBACK;
|
||||
step Ic: COMMIT;
|
||||
step CI: <... completed>
|
||||
step P: SELECT pg_size_pretty(total_bytes) as total_size FROM indexes_relation_size('ts_index_test');
|
||||
total_size
|
||||
step P: SELECT * FROM hypertable_index_size('test_index');
|
||||
hypertable_index_size
|
||||
|
||||
64 kB
|
||||
65536
|
||||
step Sc: COMMIT;
|
||||
|
||||
starting permutation: S1 CI Bc Sc P Ic
|
||||
@ -35,10 +35,10 @@ step CI: CREATE INDEX test_index ON ts_index_test(location) WITH (timescaledb.tr
|
||||
step Bc: ROLLBACK;
|
||||
step CI: <... completed>
|
||||
step Sc: COMMIT;
|
||||
step P: SELECT pg_size_pretty(total_bytes) as total_size FROM indexes_relation_size('ts_index_test');
|
||||
total_size
|
||||
step P: SELECT * FROM hypertable_index_size('test_index');
|
||||
hypertable_index_size
|
||||
|
||||
48 kB
|
||||
49152
|
||||
step Ic: COMMIT;
|
||||
|
||||
starting permutation: F CI DI Bc P Ic Sc
|
||||
@ -48,9 +48,8 @@ step DI: DROP INDEX test_index; <waiting ...>
|
||||
step Bc: ROLLBACK;
|
||||
step CI: <... completed>
|
||||
step DI: <... completed>
|
||||
step P: SELECT pg_size_pretty(total_bytes) as total_size FROM indexes_relation_size('ts_index_test');
|
||||
total_size
|
||||
|
||||
step P: SELECT * FROM hypertable_index_size('test_index');
|
||||
ERROR: relation "test_index" does not exist
|
||||
step Ic: COMMIT;
|
||||
step Sc: COMMIT;
|
||||
|
||||
@ -60,9 +59,9 @@ step RI: ALTER TABLE test_index RENAME COLUMN location TO height; <waiting ...>
|
||||
step Bc: ROLLBACK;
|
||||
step CI: <... completed>
|
||||
step RI: <... completed>
|
||||
step P: SELECT pg_size_pretty(total_bytes) as total_size FROM indexes_relation_size('ts_index_test');
|
||||
total_size
|
||||
step P: SELECT * FROM hypertable_index_size('test_index');
|
||||
hypertable_index_size
|
||||
|
||||
48 kB
|
||||
49152
|
||||
step Ic: COMMIT;
|
||||
step Sc: COMMIT;
|
||||
|
@ -42,7 +42,7 @@ session "RENAME COLUMN"
|
||||
step "RI" { ALTER TABLE test_index RENAME COLUMN location TO height; }
|
||||
|
||||
session "COUNT INDEXES"
|
||||
step "P" { SELECT pg_size_pretty(total_bytes) as total_size FROM indexes_relation_size('ts_index_test'); }
|
||||
step "P" { SELECT * FROM hypertable_index_size('test_index'); }
|
||||
|
||||
# we need to COMMIT every transaction started in setup regardless of whether we use them
|
||||
# inserts work between chunks
|
||||
|
@ -76,7 +76,8 @@ SELECT * FROM test_dt ORDER BY time;
|
||||
SELECT * FROM "testSchema0".hypertable_detailed_size('test_ts');
|
||||
-- testing hypertable_detailed_size END
|
||||
|
||||
SELECT * FROM "testSchema0".indexes_relation_size('test_ts') ORDER BY index_name;
|
||||
SELECT * FROM "testSchema0".hypertable_index_size('test_ts_time_idx');
|
||||
SELECT * FROM "testSchema0".hypertable_index_size('test_ts_device_time_idx');
|
||||
|
||||
CREATE SCHEMA "testSchema";
|
||||
|
||||
|
@ -5,7 +5,13 @@
|
||||
\ir include/insert_two_partitions.sql
|
||||
|
||||
SELECT * FROM hypertable_detailed_size('"public"."two_Partitions"');
|
||||
SELECT * FROM indexes_relation_size('"public"."two_Partitions"');
|
||||
SELECT * FROM hypertable_index_size('"public"."two_Partitions_device_id_timeCustom_idx"');
|
||||
SELECT * FROM hypertable_index_size('"public"."two_Partitions_timeCustom_device_id_idx"');
|
||||
SELECT * FROM hypertable_index_size('"public"."two_Partitions_timeCustom_idx"');
|
||||
SELECT * FROM hypertable_index_size('"public"."two_Partitions_timeCustom_series_0_idx"');
|
||||
SELECT * FROM hypertable_index_size('"public"."two_Partitions_timeCustom_series_1_idx"');
|
||||
SELECT * FROM hypertable_index_size('"public"."two_Partitions_timeCustom_series_2_idx"');
|
||||
SELECT * FROM hypertable_index_size('"public"."two_Partitions_timeCustom_series_bool_idx"');
|
||||
SELECT * FROM chunks_detailed_size('"public"."two_Partitions"') order by chunk_name;
|
||||
|
||||
CREATE TABLE timestamp_partitioned(time TIMESTAMP, value TEXT);
|
||||
@ -56,4 +62,9 @@ SELECT * FROM hypertable_approximate_row_count(NULL);
|
||||
|
||||
SELECT * FROM chunks_detailed_size(NULL);
|
||||
SELECT * FROM hypertable_detailed_size(NULL);
|
||||
SELECT * FROM indexes_relation_size(NULL);
|
||||
SELECT * FROM hypertable_index_size(NULL);
|
||||
|
||||
-- tests with tables that are not hypertables
|
||||
CREATE TABLE regtab( a integer, b integer);
|
||||
CREATE INDEX regtab_idx ON regtab( a);
|
||||
SELECT * FROM hypertable_index_size('regtab_idx');
|
||||
|
@ -254,6 +254,26 @@ dist_util_remote_compressed_chunk_info(PG_FUNCTION_ARGS)
|
||||
return dist_util_remote_srf_query(fcinfo, node_name, query_str->data);
|
||||
}
|
||||
|
||||
Datum
|
||||
dist_util_remote_hypertable_index_info(PG_FUNCTION_ARGS)
|
||||
{
|
||||
char *node_name;
|
||||
StringInfo query_str;
|
||||
Name schema_name, index_name;
|
||||
/* Strict function */
|
||||
if (PG_NARGS() != 3 || PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2))
|
||||
PG_RETURN_NULL();
|
||||
schema_name = PG_GETARG_NAME(1);
|
||||
index_name = PG_GETARG_NAME(2);
|
||||
query_str = makeStringInfo();
|
||||
appendStringInfo(query_str,
|
||||
"SELECT * from _timescaledb_internal.indexes_local_size( %s, %s );",
|
||||
quote_literal_cstr(NameStr(*schema_name)),
|
||||
quote_literal_cstr(NameStr(*index_name)));
|
||||
node_name = NameStr(*PG_GETARG_NAME(0));
|
||||
return dist_util_remote_srf_query(fcinfo, node_name, query_str->data);
|
||||
}
|
||||
|
||||
void
|
||||
validate_data_node_settings(void)
|
||||
{
|
||||
|
@ -33,6 +33,7 @@ bool dist_util_is_frontend_session(void);
|
||||
Datum dist_util_remote_hypertable_info(PG_FUNCTION_ARGS);
|
||||
Datum dist_util_remote_chunk_info(PG_FUNCTION_ARGS);
|
||||
Datum dist_util_remote_compressed_chunk_info(PG_FUNCTION_ARGS);
|
||||
Datum dist_util_remote_hypertable_index_info(PG_FUNCTION_ARGS);
|
||||
|
||||
void validate_data_node_settings(void);
|
||||
bool dist_util_is_compatible_version(const char *data_node_version, const char *access_node_version,
|
||||
|
@ -177,6 +177,7 @@ CrossModuleFunctions tsl_cm_functions = {
|
||||
.dist_remote_hypertable_info = dist_util_remote_hypertable_info,
|
||||
.dist_remote_chunk_info = dist_util_remote_chunk_info,
|
||||
.dist_remote_compressed_chunk_info = dist_util_remote_compressed_chunk_info,
|
||||
.dist_remote_hypertable_index_info = dist_util_remote_hypertable_index_info,
|
||||
.validate_as_data_node = validate_data_node_settings,
|
||||
.distributed_exec = ts_dist_cmd_exec,
|
||||
.func_call_on_data_nodes = ts_dist_cmd_func_call_on_data_nodes,
|
||||
|
@ -6,31 +6,31 @@
|
||||
---------------------------------------------------
|
||||
\c :TEST_DBNAME :ROLE_CLUSTER_SUPERUSER
|
||||
SET client_min_messages TO ERROR;
|
||||
DROP DATABASE IF EXISTS data_node_1;
|
||||
DROP DATABASE IF EXISTS data_node_2;
|
||||
DROP DATABASE IF EXISTS data_node_3;
|
||||
SELECT * FROM add_data_node('data_node_1', host => 'localhost',
|
||||
database => 'data_node_1');
|
||||
DROP DATABASE IF EXISTS view_node_1;
|
||||
DROP DATABASE IF EXISTS view_node_2;
|
||||
DROP DATABASE IF EXISTS view_node_3;
|
||||
SELECT * FROM add_data_node('view_node_1', host => 'localhost',
|
||||
database => 'view_node_1');
|
||||
node_name | host | port | database | node_created | database_created | extension_created
|
||||
-------------+-----------+-------+-------------+--------------+------------------+-------------------
|
||||
data_node_1 | localhost | 55432 | data_node_1 | t | t | t
|
||||
view_node_1 | localhost | 55432 | view_node_1 | t | t | t
|
||||
(1 row)
|
||||
|
||||
SELECT * FROM add_data_node('data_node_2', host => 'localhost',
|
||||
database => 'data_node_2');
|
||||
SELECT * FROM add_data_node('view_node_2', host => 'localhost',
|
||||
database => 'view_node_2');
|
||||
node_name | host | port | database | node_created | database_created | extension_created
|
||||
-------------+-----------+-------+-------------+--------------+------------------+-------------------
|
||||
data_node_2 | localhost | 55432 | data_node_2 | t | t | t
|
||||
view_node_2 | localhost | 55432 | view_node_2 | t | t | t
|
||||
(1 row)
|
||||
|
||||
SELECT * FROM add_data_node('data_node_3', host => 'localhost',
|
||||
database => 'data_node_3');
|
||||
SELECT * FROM add_data_node('view_node_3', host => 'localhost',
|
||||
database => 'view_node_3');
|
||||
node_name | host | port | database | node_created | database_created | extension_created
|
||||
-------------+-----------+-------+-------------+--------------+------------------+-------------------
|
||||
data_node_3 | localhost | 55432 | data_node_3 | t | t | t
|
||||
view_node_3 | localhost | 55432 | view_node_3 | t | t | t
|
||||
(1 row)
|
||||
|
||||
GRANT USAGE ON FOREIGN SERVER data_node_1, data_node_2, data_node_3 TO :ROLE_1;
|
||||
GRANT USAGE ON FOREIGN SERVER view_node_1, view_node_2, view_node_3 TO :ROLE_1;
|
||||
SET client_min_messages TO NOTICE;
|
||||
SET ROLE :ROLE_1;
|
||||
SELECT setseed(1);
|
||||
@ -50,7 +50,7 @@ NOTICE: adding not-null constraint to column "time"
|
||||
INSERT INTO dist_table SELECT t, (abs(timestamp_hash(t::timestamp)) % 10) + 1, 80
|
||||
FROM generate_series('2018-03-02 1:00'::TIMESTAMPTZ, '2018-03-04 1:00', '1 hour') t;
|
||||
ALTER TABLE dist_table SET (timescaledb.compress, timescaledb.compress_segmentby='device', timescaledb.compress_orderby = 'time DESC');
|
||||
-- Test that compression is rolled back on aborted transaction
|
||||
-- Test views with compression
|
||||
BEGIN;
|
||||
SELECT compress_chunk(chunk)
|
||||
FROM show_chunks('dist_table') AS chunk
|
||||
@ -65,16 +65,16 @@ SELECT * FROM timescaledb_information.hypertables
|
||||
WHERE table_name = 'dist_table';
|
||||
table_schema | table_name | owner | num_dimensions | num_chunks | compression_enabled | is_distributed | replication_factor | data_nodes | tablespaces
|
||||
--------------+------------+-------------+----------------+------------+---------------------+----------------+--------------------+---------------------------------------+-------------
|
||||
public | dist_table | test_role_1 | 2 | 3 | f | t | 2 | {data_node_1,data_node_2,data_node_3} |
|
||||
public | dist_table | test_role_1 | 2 | 3 | f | t | 2 | {view_node_1,view_node_2,view_node_3} |
|
||||
(1 row)
|
||||
|
||||
SELECT * from timescaledb_information.chunks
|
||||
ORDER BY hypertable_name, chunk_name;
|
||||
hypertable_schema | hypertable_name | chunk_schema | chunk_name | primary_dimension | primary_dimension_type | range_start | range_end | range_start_integer | range_end_integer | is_compressed | chunk_tablespace | data_nodes
|
||||
-------------------+-----------------+-----------------------+-----------------------+-------------------+--------------------------+------------------------------+------------------------------+---------------------+-------------------+---------------+------------------+---------------------------
|
||||
public | dist_table | _timescaledb_internal | _dist_hyper_1_1_chunk | time | timestamp with time zone | Wed Feb 28 16:00:00 2018 PST | Wed Mar 07 16:00:00 2018 PST | | | false | | {data_node_1,data_node_2}
|
||||
public | dist_table | _timescaledb_internal | _dist_hyper_1_2_chunk | time | timestamp with time zone | Wed Feb 28 16:00:00 2018 PST | Wed Mar 07 16:00:00 2018 PST | | | false | | {data_node_2,data_node_3}
|
||||
public | dist_table | _timescaledb_internal | _dist_hyper_1_3_chunk | time | timestamp with time zone | Wed Feb 28 16:00:00 2018 PST | Wed Mar 07 16:00:00 2018 PST | | | false | | {data_node_1,data_node_3}
|
||||
public | dist_table | _timescaledb_internal | _dist_hyper_1_1_chunk | time | timestamp with time zone | Wed Feb 28 16:00:00 2018 PST | Wed Mar 07 16:00:00 2018 PST | | | false | | {view_node_1,view_node_2}
|
||||
public | dist_table | _timescaledb_internal | _dist_hyper_1_2_chunk | time | timestamp with time zone | Wed Feb 28 16:00:00 2018 PST | Wed Mar 07 16:00:00 2018 PST | | | false | | {view_node_2,view_node_3}
|
||||
public | dist_table | _timescaledb_internal | _dist_hyper_1_3_chunk | time | timestamp with time zone | Wed Feb 28 16:00:00 2018 PST | Wed Mar 07 16:00:00 2018 PST | | | false | | {view_node_1,view_node_3}
|
||||
(3 rows)
|
||||
|
||||
SELECT * from timescaledb_information.dimensions
|
||||
@ -89,20 +89,21 @@ SELECT * FROM chunks_detailed_size('dist_table'::regclass)
|
||||
ORDER BY chunk_name, node_name;
|
||||
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
|
||||
-----------------------+-----------------------+-------------+-------------+-------------+-------------+-------------
|
||||
_timescaledb_internal | _dist_hyper_1_1_chunk | 8192 | 32768 | 8192 | 49152 | data_node_1
|
||||
_timescaledb_internal | _dist_hyper_1_1_chunk | 8192 | 32768 | 8192 | 49152 | data_node_2
|
||||
_timescaledb_internal | _dist_hyper_1_2_chunk | 8192 | 32768 | 0 | 40960 | data_node_2
|
||||
_timescaledb_internal | _dist_hyper_1_2_chunk | 8192 | 32768 | 0 | 40960 | data_node_3
|
||||
_timescaledb_internal | _dist_hyper_1_3_chunk | 8192 | 32768 | 0 | 40960 | data_node_1
|
||||
_timescaledb_internal | _dist_hyper_1_3_chunk | 8192 | 32768 | 0 | 40960 | data_node_3
|
||||
_timescaledb_internal | _dist_hyper_1_1_chunk | 8192 | 32768 | 8192 | 49152 | view_node_1
|
||||
_timescaledb_internal | _dist_hyper_1_1_chunk | 8192 | 32768 | 8192 | 49152 | view_node_2
|
||||
_timescaledb_internal | _dist_hyper_1_2_chunk | 8192 | 32768 | 0 | 40960 | view_node_2
|
||||
_timescaledb_internal | _dist_hyper_1_2_chunk | 8192 | 32768 | 0 | 40960 | view_node_3
|
||||
_timescaledb_internal | _dist_hyper_1_3_chunk | 8192 | 32768 | 0 | 40960 | view_node_1
|
||||
_timescaledb_internal | _dist_hyper_1_3_chunk | 8192 | 32768 | 0 | 40960 | view_node_3
|
||||
(6 rows)
|
||||
|
||||
SELECT * FROM hypertable_detailed_size('dist_table'::regclass);
|
||||
SELECT * FROM hypertable_detailed_size('dist_table'::regclass)
|
||||
ORDER BY node_name;;
|
||||
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
|
||||
-------------+-------------+-------------+-------------+-------------
|
||||
16384 | 65536 | 8192 | 90112 | data_node_1
|
||||
16384 | 65536 | 0 | 81920 | data_node_3
|
||||
16384 | 65536 | 8192 | 90112 | data_node_2
|
||||
16384 | 65536 | 8192 | 90112 | view_node_1
|
||||
16384 | 65536 | 8192 | 90112 | view_node_2
|
||||
16384 | 65536 | 0 | 81920 | view_node_3
|
||||
(3 rows)
|
||||
|
||||
---tables with special characters in the name ----
|
||||
@ -118,15 +119,15 @@ INSERT into "quote'tab" select generate_series( '2020-02-02 10:00', '2020-02-05
|
||||
SELECT * FROM chunks_detailed_size( '"quote''tab"') ORDER BY chunk_name, node_name;
|
||||
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
|
||||
-----------------------+-----------------------+-------------+-------------+-------------+-------------+-------------
|
||||
_timescaledb_internal | _dist_hyper_2_4_chunk | 8192 | 32768 | 0 | 40960 | data_node_1
|
||||
_timescaledb_internal | _dist_hyper_2_4_chunk | 8192 | 32768 | 0 | 40960 | data_node_2
|
||||
_timescaledb_internal | _dist_hyper_2_5_chunk | 8192 | 32768 | 0 | 40960 | data_node_1
|
||||
_timescaledb_internal | _dist_hyper_2_5_chunk | 8192 | 32768 | 0 | 40960 | data_node_2
|
||||
_timescaledb_internal | _dist_hyper_2_6_chunk | 8192 | 32768 | 0 | 40960 | data_node_1
|
||||
_timescaledb_internal | _dist_hyper_2_6_chunk | 8192 | 32768 | 0 | 40960 | data_node_2
|
||||
_timescaledb_internal | _dist_hyper_2_7_chunk | 8192 | 32768 | 0 | 40960 | data_node_1
|
||||
_timescaledb_internal | _dist_hyper_2_7_chunk | 8192 | 32768 | 0 | 40960 | data_node_2
|
||||
| | | | | | data_node_3
|
||||
_timescaledb_internal | _dist_hyper_2_4_chunk | 8192 | 32768 | 0 | 40960 | view_node_1
|
||||
_timescaledb_internal | _dist_hyper_2_4_chunk | 8192 | 32768 | 0 | 40960 | view_node_2
|
||||
_timescaledb_internal | _dist_hyper_2_5_chunk | 8192 | 32768 | 0 | 40960 | view_node_1
|
||||
_timescaledb_internal | _dist_hyper_2_5_chunk | 8192 | 32768 | 0 | 40960 | view_node_2
|
||||
_timescaledb_internal | _dist_hyper_2_6_chunk | 8192 | 32768 | 0 | 40960 | view_node_1
|
||||
_timescaledb_internal | _dist_hyper_2_6_chunk | 8192 | 32768 | 0 | 40960 | view_node_2
|
||||
_timescaledb_internal | _dist_hyper_2_7_chunk | 8192 | 32768 | 0 | 40960 | view_node_1
|
||||
_timescaledb_internal | _dist_hyper_2_7_chunk | 8192 | 32768 | 0 | 40960 | view_node_2
|
||||
| | | | | | view_node_3
|
||||
(9 rows)
|
||||
|
||||
CREATE TABLE "special#tab" ( a timestamp, b integer);
|
||||
@ -141,14 +142,20 @@ INSERT into "special#tab" select generate_series( '2020-02-02 10:00', '2020-02-0
|
||||
SELECT * FROM chunks_detailed_size( '"special#tab"') ORDER BY chunk_name, node_name;
|
||||
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
|
||||
-----------------------+------------------------+-------------+-------------+-------------+-------------+-------------
|
||||
_timescaledb_internal | _dist_hyper_3_10_chunk | 8192 | 32768 | 0 | 40960 | data_node_1
|
||||
_timescaledb_internal | _dist_hyper_3_10_chunk | 8192 | 32768 | 0 | 40960 | data_node_2
|
||||
_timescaledb_internal | _dist_hyper_3_11_chunk | 8192 | 32768 | 0 | 40960 | data_node_1
|
||||
_timescaledb_internal | _dist_hyper_3_11_chunk | 8192 | 32768 | 0 | 40960 | data_node_2
|
||||
_timescaledb_internal | _dist_hyper_3_8_chunk | 8192 | 32768 | 0 | 40960 | data_node_1
|
||||
_timescaledb_internal | _dist_hyper_3_8_chunk | 8192 | 32768 | 0 | 40960 | data_node_2
|
||||
_timescaledb_internal | _dist_hyper_3_9_chunk | 8192 | 32768 | 0 | 40960 | data_node_1
|
||||
_timescaledb_internal | _dist_hyper_3_9_chunk | 8192 | 32768 | 0 | 40960 | data_node_2
|
||||
| | | | | | data_node_3
|
||||
_timescaledb_internal | _dist_hyper_3_10_chunk | 8192 | 32768 | 0 | 40960 | view_node_1
|
||||
_timescaledb_internal | _dist_hyper_3_10_chunk | 8192 | 32768 | 0 | 40960 | view_node_2
|
||||
_timescaledb_internal | _dist_hyper_3_11_chunk | 8192 | 32768 | 0 | 40960 | view_node_1
|
||||
_timescaledb_internal | _dist_hyper_3_11_chunk | 8192 | 32768 | 0 | 40960 | view_node_2
|
||||
_timescaledb_internal | _dist_hyper_3_8_chunk | 8192 | 32768 | 0 | 40960 | view_node_1
|
||||
_timescaledb_internal | _dist_hyper_3_8_chunk | 8192 | 32768 | 0 | 40960 | view_node_2
|
||||
_timescaledb_internal | _dist_hyper_3_9_chunk | 8192 | 32768 | 0 | 40960 | view_node_1
|
||||
_timescaledb_internal | _dist_hyper_3_9_chunk | 8192 | 32768 | 0 | 40960 | view_node_2
|
||||
| | | | | | view_node_3
|
||||
(9 rows)
|
||||
|
||||
SELECT * FROM hypertable_index_size( 'dist_table_time_idx') ;
|
||||
hypertable_index_size
|
||||
-----------------------
|
||||
81920
|
||||
(1 row)
|
||||
|
||||
|
@ -9,6 +9,7 @@ set(TEST_FILES
|
||||
gapfill.sql
|
||||
partialize_finalize.sql
|
||||
plan_gapfill.sql
|
||||
dist_views.sql
|
||||
)
|
||||
|
||||
set(TEST_FILES_DEBUG
|
||||
@ -124,7 +125,6 @@ set(SOLO_TESTS
|
||||
dist_hypertable_am
|
||||
dist_hypertable_with_oids
|
||||
dist_partial_agg
|
||||
dist_views.sql
|
||||
issues
|
||||
read_only
|
||||
remote_connection_cache
|
||||
|
@ -8,17 +8,17 @@
|
||||
\c :TEST_DBNAME :ROLE_CLUSTER_SUPERUSER
|
||||
|
||||
SET client_min_messages TO ERROR;
|
||||
DROP DATABASE IF EXISTS data_node_1;
|
||||
DROP DATABASE IF EXISTS data_node_2;
|
||||
DROP DATABASE IF EXISTS data_node_3;
|
||||
SELECT * FROM add_data_node('data_node_1', host => 'localhost',
|
||||
database => 'data_node_1');
|
||||
SELECT * FROM add_data_node('data_node_2', host => 'localhost',
|
||||
database => 'data_node_2');
|
||||
SELECT * FROM add_data_node('data_node_3', host => 'localhost',
|
||||
database => 'data_node_3');
|
||||
DROP DATABASE IF EXISTS view_node_1;
|
||||
DROP DATABASE IF EXISTS view_node_2;
|
||||
DROP DATABASE IF EXISTS view_node_3;
|
||||
SELECT * FROM add_data_node('view_node_1', host => 'localhost',
|
||||
database => 'view_node_1');
|
||||
SELECT * FROM add_data_node('view_node_2', host => 'localhost',
|
||||
database => 'view_node_2');
|
||||
SELECT * FROM add_data_node('view_node_3', host => 'localhost',
|
||||
database => 'view_node_3');
|
||||
|
||||
GRANT USAGE ON FOREIGN SERVER data_node_1, data_node_2, data_node_3 TO :ROLE_1;
|
||||
GRANT USAGE ON FOREIGN SERVER view_node_1, view_node_2, view_node_3 TO :ROLE_1;
|
||||
SET client_min_messages TO NOTICE;
|
||||
SET ROLE :ROLE_1;
|
||||
SELECT setseed(1);
|
||||
@ -29,7 +29,7 @@ INSERT INTO dist_table SELECT t, (abs(timestamp_hash(t::timestamp)) % 10) + 1, 8
|
||||
FROM generate_series('2018-03-02 1:00'::TIMESTAMPTZ, '2018-03-04 1:00', '1 hour') t;
|
||||
ALTER TABLE dist_table SET (timescaledb.compress, timescaledb.compress_segmentby='device', timescaledb.compress_orderby = 'time DESC');
|
||||
|
||||
-- Test that compression is rolled back on aborted transaction
|
||||
-- Test views with compression
|
||||
BEGIN;
|
||||
SELECT compress_chunk(chunk)
|
||||
FROM show_chunks('dist_table') AS chunk
|
||||
@ -45,7 +45,8 @@ ORDER BY hypertable_name, dimension_number;
|
||||
|
||||
SELECT * FROM chunks_detailed_size('dist_table'::regclass)
|
||||
ORDER BY chunk_name, node_name;
|
||||
SELECT * FROM hypertable_detailed_size('dist_table'::regclass);
|
||||
SELECT * FROM hypertable_detailed_size('dist_table'::regclass)
|
||||
ORDER BY node_name;;
|
||||
|
||||
---tables with special characters in the name ----
|
||||
CREATE TABLE "quote'tab" ( a timestamp, b integer);
|
||||
@ -57,4 +58,4 @@ CREATE TABLE "special#tab" ( a timestamp, b integer);
|
||||
SELECT create_hypertable( 'special#tab', 'a', 'b', replication_factor=>2, chunk_time_interval=>INTERVAL '1 day');
|
||||
INSERT into "special#tab" select generate_series( '2020-02-02 10:00', '2020-02-05 10:00' , '1 day'::interval), 10;
|
||||
SELECT * FROM chunks_detailed_size( '"special#tab"') ORDER BY chunk_name, node_name;
|
||||
|
||||
SELECT * FROM hypertable_index_size( 'dist_table_time_idx') ;
|
||||
|
Loading…
x
Reference in New Issue
Block a user