Skip to content

Commit

Permalink
Add compression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmp85 committed May 15, 2024
1 parent e11ca55 commit 7dc0c4f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
14 changes: 8 additions & 6 deletions sql/timeseries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,13 @@ SELECT pt.parentrelid as table_id,
pg_get_expr(c.relpartbound, c.oid) AS part_range,
pg_table_size(pt.relid) AS table_size_bytes,
pg_indexes_size(pt.relid) AS index_size_bytes,
pg_total_relation_size(pt.relid) AS total_size_bytes
pg_total_relation_size(pt.relid) AS total_size_bytes,
am.amname AS access_method
FROM @[email protected]_config tsc,
pg_partition_tree(tsc.table_id) pt,
pg_class c
WHERE pt.isleaf AND pt.relid = c.oid
pg_class c,
pg_am am
WHERE pt.isleaf AND pt.relid = c.oid AND c.relam = am.oid
ORDER BY 2 ASC;

-- Unlike the above view, this sums partitions for each time-series table.
Expand Down Expand Up @@ -506,7 +508,7 @@ CREATE OR REPLACE AGGREGATE last(value anyelement, rank anycompatible) (
-- other than that row's date bin value.
--
-- The target table must be time-series enabled.
CREATE OR REPLACE FUNCTION public.date_bin_table (target_table_elem anyelement, time_stride interval, time_range tstzrange)
CREATE OR REPLACE FUNCTION @extschema@.date_bin_table (target_table_elem anyelement, time_stride interval, time_range tstzrange)
RETURNS SETOF anyelement
LANGUAGE plpgsql
AS $function$
Expand All @@ -533,7 +535,7 @@ BEGIN
END IF;

PERFORM *
FROM public.ts_config
FROM @extschema@.ts_config
WHERE "table_id"=target_table_id;
IF NOT FOUND THEN
RAISE object_not_in_prerequisite_state USING
Expand Down Expand Up @@ -596,7 +598,7 @@ $function$;
-- Function implementation for LOCF: last-observed carry-forward.
-- Intended for use on the output of date_bin_table in order to
-- fill NULL rows with the last observed value.
CREATE OR REPLACE FUNCTION public.locf_agg(state anyelement, value anyelement)
CREATE OR REPLACE FUNCTION @extschema@.locf_agg(state anyelement, value anyelement)
RETURNS anyelement
LANGUAGE plpgsql
AS $function$
Expand Down
20 changes: 19 additions & 1 deletion test/expected/basic_usage.out
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ SELECT COUNT(*) > 10 AS has_partitions FROM ts_part_info;
t
(1 row)

SELECT COUNT(*) > 0 AS "compressed?" FROM ts_part_info WHERE access_method = 'columnar';
compressed?
-------------
f
(1 row)

SELECT set_ts_retention_policy('measurements', '90 days');
set_ts_retention_policy
-------------------------
Expand Down Expand Up @@ -119,7 +125,19 @@ SELECT premake FROM part_config WHERE parent_table='public.measurements';
1
(1 row)

SELECT set_ts_retention_policy('measurements', '1 days');
SELECT apply_compression_policy('measurements', '1 day');
apply_compression_policy
--------------------------

(1 row)

SELECT COUNT(*) > 0 AS "compressed?" FROM ts_part_info WHERE access_method = 'columnar';
compressed?
-------------
t
(1 row)

SELECT set_ts_retention_policy('measurements', '1 day');
set_ts_retention_policy
-------------------------

Expand Down
6 changes: 5 additions & 1 deletion test/sql/basic_usage.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ SELECT partition_duration, partition_lead_time FROM ts_config ORDER BY table_id:
SELECT partition_interval, premake FROM part_config WHERE parent_table='public.measurements';

SELECT COUNT(*) > 10 AS has_partitions FROM ts_part_info;
SELECT COUNT(*) > 0 AS "compressed?" FROM ts_part_info WHERE access_method = 'columnar';

SELECT set_ts_retention_policy('measurements', '90 days');
SELECT retention_duration FROM ts_config WHERE table_id='measurements'::regclass;
Expand All @@ -45,7 +46,10 @@ SELECT set_ts_lead_time('measurements', '1 day');
SELECT partition_lead_time FROM ts_config WHERE table_id='measurements'::regclass;
SELECT premake FROM part_config WHERE parent_table='public.measurements';

SELECT set_ts_retention_policy('measurements', '1 days');
SELECT apply_compression_policy('measurements', '1 day');
SELECT COUNT(*) > 0 AS "compressed?" FROM ts_part_info WHERE access_method = 'columnar';

SELECT set_ts_retention_policy('measurements', '1 day');
SELECT run_maintenance();
SELECT COUNT(*) < 10 AS fewer_partitions FROM ts_part_info;

Expand Down

0 comments on commit 7dc0c4f

Please sign in to comment.