diff --git a/src/backend/timeseries/sql/udfs/get_missing_partition_ranges/10.2-1.sql b/src/backend/timeseries/sql/udfs/get_missing_partition_ranges/10.2-1.sql index bea2aeaa7..caad86bea 100644 --- a/src/backend/timeseries/sql/udfs/get_missing_partition_ranges/10.2-1.sql +++ b/src/backend/timeseries/sql/udfs/get_missing_partition_ranges/10.2-1.sql @@ -12,6 +12,8 @@ DECLARE current_partition_count int; table_partition_interval INTERVAL; table_partition_column_type_name text; + manual_partition_from_value_text text; + manual_partition_to_value_text text; current_range_from_value timestamptz := NULL; current_range_to_value timestamptz := NULL; current_range_from_value_text text; @@ -146,15 +148,18 @@ BEGIN * Check whether any other partition covers from_value or to_value * That means some partitions have been created manually and we must error out. */ - PERFORM * FROM pg_catalog.time_partitions + SELECT from_value::text, to_value::text + INTO manual_partition_from_value_text, manual_partition_to_value_text + FROM pg_catalog.time_partitions WHERE ((current_range_from_value::timestamptz > from_value::timestamptz AND current_range_from_value < to_value::timestamptz) OR (current_range_to_value::timestamptz > from_value::timestamptz AND current_range_to_value::timestamptz < to_value::timestamptz)) AND parent_table = table_name; + IF found THEN RAISE 'Partition with the range from % to % has been created manually. Please remove all manually created partitions to use the table as timeseries table', - current_range_from_value::text, - current_range_to_value::text; + manual_partition_from_value_text, + manual_partition_to_value_text; END IF; /* diff --git a/src/backend/timeseries/sql/udfs/get_missing_partition_ranges/latest.sql b/src/backend/timeseries/sql/udfs/get_missing_partition_ranges/latest.sql index bea2aeaa7..caad86bea 100644 --- a/src/backend/timeseries/sql/udfs/get_missing_partition_ranges/latest.sql +++ b/src/backend/timeseries/sql/udfs/get_missing_partition_ranges/latest.sql @@ -12,6 +12,8 @@ DECLARE current_partition_count int; table_partition_interval INTERVAL; table_partition_column_type_name text; + manual_partition_from_value_text text; + manual_partition_to_value_text text; current_range_from_value timestamptz := NULL; current_range_to_value timestamptz := NULL; current_range_from_value_text text; @@ -146,15 +148,18 @@ BEGIN * Check whether any other partition covers from_value or to_value * That means some partitions have been created manually and we must error out. */ - PERFORM * FROM pg_catalog.time_partitions + SELECT from_value::text, to_value::text + INTO manual_partition_from_value_text, manual_partition_to_value_text + FROM pg_catalog.time_partitions WHERE ((current_range_from_value::timestamptz > from_value::timestamptz AND current_range_from_value < to_value::timestamptz) OR (current_range_to_value::timestamptz > from_value::timestamptz AND current_range_to_value::timestamptz < to_value::timestamptz)) AND parent_table = table_name; + IF found THEN RAISE 'Partition with the range from % to % has been created manually. Please remove all manually created partitions to use the table as timeseries table', - current_range_from_value::text, - current_range_to_value::text; + manual_partition_from_value_text, + manual_partition_to_value_text; END IF; /* diff --git a/src/test/regress/expected/timeseries_create_drop_timeseries_table.out b/src/test/regress/expected/timeseries_create_drop_timeseries_table.out index 0d2e9c791..e39c42447 100644 --- a/src/test/regress/expected/timeseries_create_drop_timeseries_table.out +++ b/src/test/regress/expected/timeseries_create_drop_timeseries_table.out @@ -53,7 +53,7 @@ ERROR: partition interval for table partitioned on date must be multiple days SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day 15 minutes'); ERROR: partition interval for table partitioned on date must be multiple days BEGIN; -SELECT create_timeseries_table('date_partitioned_table', INTERVAL '2 days'); + SELECT create_timeseries_table('date_partitioned_table', INTERVAL '2 days'); create_timeseries_table --------------------------------------------------------------------- @@ -61,7 +61,7 @@ SELECT create_timeseries_table('date_partitioned_table', INTERVAL '2 days'); ROLLBACK; BEGIN; -SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 week'); + SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 week'); create_timeseries_table --------------------------------------------------------------------- @@ -69,7 +69,7 @@ SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 week'); ROLLBACK; BEGIN; -SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 month'); + SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 month'); create_timeseries_table --------------------------------------------------------------------- @@ -77,7 +77,7 @@ SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 month'); ROLLBACK; BEGIN; -SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 month 15 weeks 3 days'); + SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 month 15 weeks 3 days'); create_timeseries_table --------------------------------------------------------------------- @@ -85,7 +85,7 @@ SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 month 15 we ROLLBACK; BEGIN; -SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 year 1 month 15 weeks 3 days'); + SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 year 1 month 15 weeks 3 days'); create_timeseries_table --------------------------------------------------------------------- @@ -94,7 +94,7 @@ SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 year 1 mont ROLLBACK; DROP TABLE date_partitioned_table; -- 2) retention threshold must be greater than compression threshold and --- compresstion threshold must be greater than partition interval +-- compression threshold must be greater than partition interval -- With date partitioned table CREATE TABLE ts_comp_date_partitioned_table( measureid integer, @@ -107,7 +107,7 @@ ERROR: retention threshold must be greater than compression threshold and compr SELECT create_timeseries_table('ts_comp_date_partitioned_table', INTERVAL '1 week', retention_threshold => INTERVAL '5 days'); ERROR: retention threshold must be greater than compression threshold and compression threshold must be greater than partition interval BEGIN; -SELECT create_timeseries_table('ts_comp_date_partitioned_table', INTERVAL '1 week', compression_threshold => INTERVAL '10 days'); + SELECT create_timeseries_table('ts_comp_date_partitioned_table', INTERVAL '1 week', compression_threshold => INTERVAL '10 days'); create_timeseries_table --------------------------------------------------------------------- @@ -115,7 +115,7 @@ SELECT create_timeseries_table('ts_comp_date_partitioned_table', INTERVAL '1 wee ROLLBACK; BEGIN; -SELECT create_timeseries_table('ts_comp_date_partitioned_table', INTERVAL '1 week', compression_threshold => INTERVAL '10 days', retention_threshold => INTERVAL '15 days'); + SELECT create_timeseries_table('ts_comp_date_partitioned_table', INTERVAL '1 week', compression_threshold => INTERVAL '10 days', retention_threshold => INTERVAL '15 days'); create_timeseries_table --------------------------------------------------------------------- @@ -135,7 +135,7 @@ ERROR: retention threshold must be greater than compression threshold and compr SELECT create_timeseries_table('ts_comp_tstz_partitioned_table', INTERVAL '2 hours', retention_threshold => INTERVAL '1 hour'); ERROR: retention threshold must be greater than compression threshold and compression threshold must be greater than partition interval BEGIN; -SELECT create_timeseries_table('ts_comp_tstz_partitioned_table', INTERVAL '2 hours', compression_threshold => INTERVAL '6 hours'); + SELECT create_timeseries_table('ts_comp_tstz_partitioned_table', INTERVAL '2 hours', compression_threshold => INTERVAL '6 hours'); create_timeseries_table --------------------------------------------------------------------- @@ -143,7 +143,7 @@ SELECT create_timeseries_table('ts_comp_tstz_partitioned_table', INTERVAL '2 hou ROLLBACK; BEGIN; -SELECT create_timeseries_table('ts_comp_tstz_partitioned_table', INTERVAL '90 minutes', compression_threshold => INTERVAL '180 minutes', retention_threshold => INTERVAL '360 minutes'); + SELECT create_timeseries_table('ts_comp_tstz_partitioned_table', INTERVAL '90 minutes', compression_threshold => INTERVAL '180 minutes', retention_threshold => INTERVAL '360 minutes'); create_timeseries_table --------------------------------------------------------------------- @@ -159,7 +159,7 @@ CREATE TABLE param_test_partitioned_table( SELECT create_timeseries_table('param_test_partitioned_table', INTERVAL '90 minutes', premake_interval_count => 7, start_from => now()); ERROR: either premake_interval_count or start_from should be provided BEGIN; -SELECT create_timeseries_table('param_test_partitioned_table', INTERVAL '90 minutes', premake_interval_count => 7); + SELECT create_timeseries_table('param_test_partitioned_table', INTERVAL '90 minutes', premake_interval_count => 7); create_timeseries_table --------------------------------------------------------------------- @@ -167,7 +167,7 @@ SELECT create_timeseries_table('param_test_partitioned_table', INTERVAL '90 minu ROLLBACK; BEGIN; -SELECT create_timeseries_table('param_test_partitioned_table', INTERVAL '90 minutes', start_from => now()); + SELECT create_timeseries_table('param_test_partitioned_table', INTERVAL '90 minutes', start_from => now()); create_timeseries_table --------------------------------------------------------------------- @@ -181,15 +181,15 @@ CREATE TABLE count_test_partitioned_table( eventdatetime timestamp with time zone, measure_data integer) PARTITION BY RANGE(eventdatetime); BEGIN; -SELECT create_timeseries_table('count_test_partitioned_table', INTERVAL '1 minute', postmake_interval_count => 0, premake_interval_count => 0); + SELECT create_timeseries_table('count_test_partitioned_table', INTERVAL '1 minute', postmake_interval_count => 0, premake_interval_count => 0); create_timeseries_table --------------------------------------------------------------------- (1 row) -SELECT count(*) -FROM pg_catalog.time_partitions -WHERE parent_table = 'count_test_partitioned_table'::regclass; + SELECT count(*) + FROM pg_catalog.time_partitions + WHERE parent_table = 'count_test_partitioned_table'::regclass; count --------------------------------------------------------------------- 1 @@ -197,15 +197,15 @@ WHERE parent_table = 'count_test_partitioned_table'::regclass; ROLLBACK; BEGIN; -SELECT create_timeseries_table('count_test_partitioned_table', INTERVAL '1 hour', postmake_interval_count => 0, premake_interval_count => 5); + SELECT create_timeseries_table('count_test_partitioned_table', INTERVAL '1 hour', postmake_interval_count => 0, premake_interval_count => 5); create_timeseries_table --------------------------------------------------------------------- (1 row) -SELECT count(*) -FROM pg_catalog.time_partitions -WHERE parent_table = 'count_test_partitioned_table'::regclass; + SELECT count(*) + FROM pg_catalog.time_partitions + WHERE parent_table = 'count_test_partitioned_table'::regclass; count --------------------------------------------------------------------- 6 @@ -213,15 +213,15 @@ WHERE parent_table = 'count_test_partitioned_table'::regclass; ROLLBACK; BEGIN; -SELECT create_timeseries_table('count_test_partitioned_table', INTERVAL '2 weeks', postmake_interval_count => 5, premake_interval_count => 0); + SELECT create_timeseries_table('count_test_partitioned_table', INTERVAL '2 weeks', postmake_interval_count => 5, premake_interval_count => 0); create_timeseries_table --------------------------------------------------------------------- (1 row) -SELECT count(*) -FROM pg_catalog.time_partitions -WHERE parent_table = 'count_test_partitioned_table'::regclass; + SELECT count(*) + FROM pg_catalog.time_partitions + WHERE parent_table = 'count_test_partitioned_table'::regclass; count --------------------------------------------------------------------- 6 @@ -229,15 +229,15 @@ WHERE parent_table = 'count_test_partitioned_table'::regclass; ROLLBACK; BEGIN; -SELECT create_timeseries_table('count_test_partitioned_table', INTERVAL '2 months', postmake_interval_count => 3, premake_interval_count => 4); + SELECT create_timeseries_table('count_test_partitioned_table', INTERVAL '2 months', postmake_interval_count => 3, premake_interval_count => 4); create_timeseries_table --------------------------------------------------------------------- (1 row) -SELECT count(*) -FROM pg_catalog.time_partitions -WHERE parent_table = 'count_test_partitioned_table'::regclass; + SELECT count(*) + FROM pg_catalog.time_partitions + WHERE parent_table = 'count_test_partitioned_table'::regclass; count --------------------------------------------------------------------- 8 @@ -251,121 +251,121 @@ CREATE TABLE range_check_test_partitioned_table( eventdatetime timestamp with time zone, measure_data integer) PARTITION BY RANGE(eventdatetime); BEGIN; -SELECT create_timeseries_table('range_check_test_partitioned_table', INTERVAL '1 hour'); + SELECT create_timeseries_table('range_check_test_partitioned_table', INTERVAL '1 hour'); create_timeseries_table --------------------------------------------------------------------- (1 row) -SELECT partition, - date_trunc('hour',now()) - from_value::timestamptz as from_diff, - date_trunc('hour', now()) - to_value::timestamptz as to_diff -FROM pg_catalog.time_partitions -ORDER BY 1; - partition | from_diff | to_diff + SELECT partition, + date_trunc('hour',now()) - from_value::timestamptz as from_diff, + date_trunc('hour', now()) - to_value::timestamptz as to_diff + FROM pg_catalog.time_partitions + ORDER BY 1; + partition | from_diff | to_diff --------------------------------------------------------------------- - range_check_test_partitioned_table_0 | @ 7 hours | @ 6 hours - range_check_test_partitioned_table_1 | @ 6 hours | @ 5 hours - range_check_test_partitioned_table_2 | @ 5 hours | @ 4 hours - range_check_test_partitioned_table_3 | @ 4 hours | @ 3 hours - range_check_test_partitioned_table_4 | @ 3 hours | @ 2 hours - range_check_test_partitioned_table_5 | @ 2 hours | @ 1 hour - range_check_test_partitioned_table_6 | @ 1 hour | @ 0 - range_check_test_partitioned_table_7 | @ 0 | @ 1 hour ago - range_check_test_partitioned_table_8 | @ 1 hour ago | @ 2 hours ago - range_check_test_partitioned_table_9 | @ 2 hours ago | @ 3 hours ago - range_check_test_partitioned_table_10 | @ 3 hours ago | @ 4 hours ago - range_check_test_partitioned_table_11 | @ 4 hours ago | @ 5 hours ago - range_check_test_partitioned_table_12 | @ 5 hours ago | @ 6 hours ago - range_check_test_partitioned_table_13 | @ 6 hours ago | @ 7 hours ago - range_check_test_partitioned_table_14 | @ 7 hours ago | @ 8 hours ago + range_check_test_partit_2021_08_31_20_00_00_2021_08_31_21_00_00 | @ 7 hours | @ 6 hours + range_check_test_partit_2021_08_31_21_00_00_2021_08_31_22_00_00 | @ 6 hours | @ 5 hours + range_check_test_partit_2021_08_31_22_00_00_2021_08_31_23_00_00 | @ 5 hours | @ 4 hours + range_check_test_partit_2021_08_31_23_00_00_2021_09_01_00_00_00 | @ 4 hours | @ 3 hours + range_check_test_partit_2021_09_01_00_00_00_2021_09_01_01_00_00 | @ 3 hours | @ 2 hours + range_check_test_partit_2021_09_01_01_00_00_2021_09_01_02_00_00 | @ 2 hours | @ 1 hour + range_check_test_partit_2021_09_01_02_00_00_2021_09_01_03_00_00 | @ 1 hour | @ 0 + range_check_test_partit_2021_09_01_03_00_00_2021_09_01_04_00_00 | @ 0 | @ 1 hour ago + range_check_test_partit_2021_09_01_04_00_00_2021_09_01_05_00_00 | @ 1 hour ago | @ 2 hours ago + range_check_test_partit_2021_09_01_05_00_00_2021_09_01_06_00_00 | @ 2 hours ago | @ 3 hours ago + range_check_test_partit_2021_09_01_06_00_00_2021_09_01_07_00_00 | @ 3 hours ago | @ 4 hours ago + range_check_test_partit_2021_09_01_07_00_00_2021_09_01_08_00_00 | @ 4 hours ago | @ 5 hours ago + range_check_test_partit_2021_09_01_08_00_00_2021_09_01_09_00_00 | @ 5 hours ago | @ 6 hours ago + range_check_test_partit_2021_09_01_09_00_00_2021_09_01_10_00_00 | @ 6 hours ago | @ 7 hours ago + range_check_test_partit_2021_09_01_10_00_00_2021_09_01_11_00_00 | @ 7 hours ago | @ 8 hours ago (15 rows) ROLLBACK; BEGIN; -SELECT create_timeseries_table('range_check_test_partitioned_table', INTERVAL '1 day', postmake_interval_count => 5); + SELECT create_timeseries_table('range_check_test_partitioned_table', INTERVAL '1 day', postmake_interval_count => 5); create_timeseries_table --------------------------------------------------------------------- (1 row) -SELECT partition, - date_trunc('day',now()) - from_value::timestamptz as from_diff, - date_trunc('day', now()) - to_value::timestamptz as to_diff -FROM pg_catalog.time_partitions -ORDER BY 1; - partition | from_diff | to_diff + SELECT partition, + date_trunc('day',now()) - from_value::timestamptz as from_diff, + date_trunc('day', now()) - to_value::timestamptz as to_diff + FROM pg_catalog.time_partitions + ORDER BY 1; + partition | from_diff | to_diff --------------------------------------------------------------------- - range_check_test_partitioned_table_0 | @ 7 days | @ 6 days - range_check_test_partitioned_table_1 | @ 6 days | @ 5 days - range_check_test_partitioned_table_2 | @ 5 days | @ 4 days - range_check_test_partitioned_table_3 | @ 4 days | @ 3 days - range_check_test_partitioned_table_4 | @ 3 days | @ 2 days - range_check_test_partitioned_table_5 | @ 2 days | @ 1 day - range_check_test_partitioned_table_6 | @ 1 day | @ 0 - range_check_test_partitioned_table_7 | @ 0 | @ 1 day ago - range_check_test_partitioned_table_8 | @ 1 day ago | @ 2 days ago - range_check_test_partitioned_table_9 | @ 2 days ago | @ 3 days ago - range_check_test_partitioned_table_10 | @ 3 days ago | @ 4 days ago - range_check_test_partitioned_table_11 | @ 4 days ago | @ 5 days ago - range_check_test_partitioned_table_12 | @ 5 days ago | @ 6 days ago + range_check_test_partit_2021_08_25_00_00_00_2021_08_26_00_00_00 | @ 7 days | @ 6 days + range_check_test_partit_2021_08_26_00_00_00_2021_08_27_00_00_00 | @ 6 days | @ 5 days + range_check_test_partit_2021_08_27_00_00_00_2021_08_28_00_00_00 | @ 5 days | @ 4 days + range_check_test_partit_2021_08_28_00_00_00_2021_08_29_00_00_00 | @ 4 days | @ 3 days + range_check_test_partit_2021_08_29_00_00_00_2021_08_30_00_00_00 | @ 3 days | @ 2 days + range_check_test_partit_2021_08_30_00_00_00_2021_08_31_00_00_00 | @ 2 days | @ 1 day + range_check_test_partit_2021_08_31_00_00_00_2021_09_01_00_00_00 | @ 1 day | @ 0 + range_check_test_partit_2021_09_01_00_00_00_2021_09_02_00_00_00 | @ 0 | @ 1 day ago + range_check_test_partit_2021_09_02_00_00_00_2021_09_03_00_00_00 | @ 1 day ago | @ 2 days ago + range_check_test_partit_2021_09_03_00_00_00_2021_09_04_00_00_00 | @ 2 days ago | @ 3 days ago + range_check_test_partit_2021_09_04_00_00_00_2021_09_05_00_00_00 | @ 3 days ago | @ 4 days ago + range_check_test_partit_2021_09_05_00_00_00_2021_09_06_00_00_00 | @ 4 days ago | @ 5 days ago + range_check_test_partit_2021_09_06_00_00_00_2021_09_07_00_00_00 | @ 5 days ago | @ 6 days ago (13 rows) ROLLBACK; BEGIN; -SELECT create_timeseries_table('range_check_test_partitioned_table', INTERVAL '1 week', premake_interval_count => 3); + SELECT create_timeseries_table('range_check_test_partitioned_table', INTERVAL '1 week', premake_interval_count => 3); create_timeseries_table --------------------------------------------------------------------- (1 row) -SELECT partition, - date_trunc('week',now()) - from_value::timestamptz as from_diff, - date_trunc('week', now()) - to_value::timestamptz as to_diff -FROM pg_catalog.time_partitions -ORDER BY 1; - partition | from_diff | to_diff + SELECT partition, + date_trunc('week',now()) - from_value::timestamptz as from_diff, + date_trunc('week', now()) - to_value::timestamptz as to_diff + FROM pg_catalog.time_partitions + ORDER BY 1; + partition | from_diff | to_diff --------------------------------------------------------------------- - range_check_test_partitioned_table_0 | @ 21 days | @ 14 days - range_check_test_partitioned_table_1 | @ 14 days | @ 7 days - range_check_test_partitioned_table_2 | @ 7 days | @ 0 - range_check_test_partitioned_table_3 | @ 0 | @ 7 days ago - range_check_test_partitioned_table_4 | @ 7 days ago | @ 14 days ago - range_check_test_partitioned_table_5 | @ 14 days ago | @ 21 days ago - range_check_test_partitioned_table_6 | @ 21 days ago | @ 28 days ago - range_check_test_partitioned_table_7 | @ 28 days ago | @ 35 days ago - range_check_test_partitioned_table_8 | @ 35 days ago | @ 42 days ago - range_check_test_partitioned_table_9 | @ 42 days ago | @ 49 days ago - range_check_test_partitioned_table_10 | @ 49 days ago | @ 56 days ago + range_check_test_partit_2021_08_09_00_00_00_2021_08_16_00_00_00 | @ 21 days | @ 14 days + range_check_test_partit_2021_08_16_00_00_00_2021_08_23_00_00_00 | @ 14 days | @ 7 days + range_check_test_partit_2021_08_23_00_00_00_2021_08_30_00_00_00 | @ 7 days | @ 0 + range_check_test_partit_2021_08_30_00_00_00_2021_09_06_00_00_00 | @ 0 | @ 7 days ago + range_check_test_partit_2021_09_06_00_00_00_2021_09_13_00_00_00 | @ 7 days ago | @ 14 days ago + range_check_test_partit_2021_09_13_00_00_00_2021_09_20_00_00_00 | @ 14 days ago | @ 21 days ago + range_check_test_partit_2021_09_20_00_00_00_2021_09_27_00_00_00 | @ 21 days ago | @ 28 days ago + range_check_test_partit_2021_09_27_00_00_00_2021_10_04_00_00_00 | @ 28 days ago | @ 35 days ago + range_check_test_partit_2021_10_04_00_00_00_2021_10_11_00_00_00 | @ 35 days ago | @ 42 days ago + range_check_test_partit_2021_10_11_00_00_00_2021_10_18_00_00_00 | @ 42 days ago | @ 49 days ago + range_check_test_partit_2021_10_18_00_00_00_2021_10_25_00_00_00 | @ 49 days ago | @ 56 days ago (11 rows) ROLLBACK; BEGIN; -SELECT create_timeseries_table('range_check_test_partitioned_table', INTERVAL '1 week', start_from => now() - INTERVAL '4 weeks'); + SELECT create_timeseries_table('range_check_test_partitioned_table', INTERVAL '1 week', start_from => now() - INTERVAL '4 weeks'); create_timeseries_table --------------------------------------------------------------------- (1 row) -SELECT partition, - date_trunc('week',now()) - from_value::timestamptz as from_diff, - date_trunc('week', now()) - to_value::timestamptz as to_diff -FROM pg_catalog.time_partitions -ORDER BY 1; - partition | from_diff | to_diff + SELECT partition, + date_trunc('week',now()) - from_value::timestamptz as from_diff, + date_trunc('week', now()) - to_value::timestamptz as to_diff + FROM pg_catalog.time_partitions + ORDER BY 1; + partition | from_diff | to_diff --------------------------------------------------------------------- - range_check_test_partitioned_table_0 | @ 28 days | @ 21 days - range_check_test_partitioned_table_1 | @ 21 days | @ 14 days - range_check_test_partitioned_table_2 | @ 14 days | @ 7 days - range_check_test_partitioned_table_3 | @ 7 days | @ 0 - range_check_test_partitioned_table_4 | @ 0 | @ 7 days ago - range_check_test_partitioned_table_5 | @ 7 days ago | @ 14 days ago - range_check_test_partitioned_table_6 | @ 14 days ago | @ 21 days ago - range_check_test_partitioned_table_7 | @ 21 days ago | @ 28 days ago - range_check_test_partitioned_table_8 | @ 28 days ago | @ 35 days ago - range_check_test_partitioned_table_9 | @ 35 days ago | @ 42 days ago - range_check_test_partitioned_table_10 | @ 42 days ago | @ 49 days ago - range_check_test_partitioned_table_11 | @ 49 days ago | @ 56 days ago + range_check_test_partit_2021_08_02_00_00_00_2021_08_09_00_00_00 | @ 28 days | @ 21 days + range_check_test_partit_2021_08_09_00_00_00_2021_08_16_00_00_00 | @ 21 days | @ 14 days + range_check_test_partit_2021_08_16_00_00_00_2021_08_23_00_00_00 | @ 14 days | @ 7 days + range_check_test_partit_2021_08_23_00_00_00_2021_08_30_00_00_00 | @ 7 days | @ 0 + range_check_test_partit_2021_08_30_00_00_00_2021_09_06_00_00_00 | @ 0 | @ 7 days ago + range_check_test_partit_2021_09_06_00_00_00_2021_09_13_00_00_00 | @ 7 days ago | @ 14 days ago + range_check_test_partit_2021_09_13_00_00_00_2021_09_20_00_00_00 | @ 14 days ago | @ 21 days ago + range_check_test_partit_2021_09_20_00_00_00_2021_09_27_00_00_00 | @ 21 days ago | @ 28 days ago + range_check_test_partit_2021_09_27_00_00_00_2021_10_04_00_00_00 | @ 28 days ago | @ 35 days ago + range_check_test_partit_2021_10_04_00_00_00_2021_10_11_00_00_00 | @ 35 days ago | @ 42 days ago + range_check_test_partit_2021_10_11_00_00_00_2021_10_18_00_00_00 | @ 42 days ago | @ 49 days ago + range_check_test_partit_2021_10_18_00_00_00_2021_10_25_00_00_00 | @ 49 days ago | @ 56 days ago (12 rows) ROLLBACK; @@ -393,26 +393,72 @@ SELECT * FROM timeseries.tables; (0 rows) BEGIN; -CREATE TABLE drop_check_test_partitioned_table( + CREATE TABLE drop_check_test_partitioned_table( + measureid integer, + eventdatetime timestamp with time zone, + measure_data integer) PARTITION BY RANGE(eventdatetime); + SELECT create_timeseries_table('drop_check_test_partitioned_table', INTERVAL '2 hours'); + create_timeseries_table +--------------------------------------------------------------------- + +(1 row) + + SELECT * FROM timeseries.tables; + logicalrelid | partitioninterval | postmakeintervalcount | premakeintervalcount | startfrom | compressionthreshold | retentionthreshold +--------------------------------------------------------------------- + drop_check_test_partitioned_table | @ 2 hours | 7 | 7 | | | +(1 row) + + DROP TABLE drop_check_test_partitioned_table; + SELECT * FROM timeseries.tables; + logicalrelid | partitioninterval | postmakeintervalcount | premakeintervalcount | startfrom | compressionthreshold | retentionthreshold +--------------------------------------------------------------------- +(0 rows) + +COMMIT; +-- Check distributed partitioned table +CREATE TABLE distributed_partitioned_table( measureid integer, - eventdatetime timestamp with time zone, - measure_data integer) PARTITION BY RANGE(eventdatetime); -SELECT create_timeseries_table('drop_check_test_partitioned_table', INTERVAL '2 hours'); + eventdate date, + measure_data integer) PARTITION BY RANGE(eventdate); +SELECT create_distributed_table('distributed_partitioned_table', 'measureid'); + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + +SELECT create_timeseries_table('distributed_partitioned_table', INTERVAL '1 day'); create_timeseries_table --------------------------------------------------------------------- (1 row) SELECT * FROM timeseries.tables; - logicalrelid | partitioninterval | postmakeintervalcount | premakeintervalcount | startfrom | compressionthreshold | retentionthreshold + logicalrelid | partitioninterval | postmakeintervalcount | premakeintervalcount | startfrom | compressionthreshold | retentionthreshold --------------------------------------------------------------------- - drop_check_test_partitioned_table | @ 2 hours | 7 | 7 | | | + distributed_partitioned_table | @ 1 day | 7 | 7 | | | (1 row) -DROP TABLE drop_check_test_partitioned_table; +-- We should have 512 shards since we have 15 partitions and 1 parent table +SELECT count(*) +FROM pg_dist_shard +WHERE logicalrelid::text LIKE 'distributed_partitioned_table%'; + count +--------------------------------------------------------------------- + 64 +(1 row) + +DROP TABLE distributed_partitioned_table; SELECT * FROM timeseries.tables; logicalrelid | partitioninterval | postmakeintervalcount | premakeintervalcount | startfrom | compressionthreshold | retentionthreshold --------------------------------------------------------------------- (0 rows) -COMMIT; \ No newline at end of file +-- Show that partitioned reference tables are not supported +CREATE TABLE partitioned_reference_table( + measureid integer, + eventdate date, + measure_data integer) PARTITION BY RANGE(eventdate); +SELECT create_reference_table('partitioned_reference_table'); +ERROR: distributing partitioned tables in only supported for hash-distributed tables +DROP TABLE partitioned_reference_table; diff --git a/src/test/regress/expected/timeseries_create_missing_partitions.out b/src/test/regress/expected/timeseries_create_missing_partitions.out index 9259e6123..1f874c746 100644 --- a/src/test/regress/expected/timeseries_create_missing_partitions.out +++ b/src/test/regress/expected/timeseries_create_missing_partitions.out @@ -724,10 +724,9 @@ BEGIN; SELECT * FROM pg_catalog.time_partitions WHERE parent_table = 'absolute_times_partitioned_table'::regclass - ORDER BY 1,2,3; + ORDER BY 3; parent_table | partition_column | partition | from_value | to_value | access_method --------------------------------------------------------------------- - absolute_times_partitioned_table | eventdate | absolute_times_partitioned_table_2021_01_01_2021_02_01 | 01-01-2021 | 02-01-2021 | heap absolute_times_partitioned_table | eventdate | absolute_times_partitioned_table_2021_02_01_2021_03_01 | 02-01-2021 | 03-01-2021 | heap absolute_times_partitioned_table | eventdate | absolute_times_partitioned_table_2021_03_01_2021_04_01 | 03-01-2021 | 04-01-2021 | heap absolute_times_partitioned_table | eventdate | absolute_times_partitioned_table_2021_04_01_2021_05_01 | 04-01-2021 | 05-01-2021 | heap @@ -742,6 +741,7 @@ BEGIN; absolute_times_partitioned_table | eventdate | absolute_times_partitioned_table_2022_01_01_2022_02_01 | 01-01-2022 | 02-01-2022 | heap absolute_times_partitioned_table | eventdate | absolute_times_partitioned_table_2022_02_01_2022_03_01 | 02-01-2022 | 03-01-2022 | heap absolute_times_partitioned_table | eventdate | absolute_times_partitioned_table_2022_03_01_2022_04_01 | 03-01-2022 | 04-01-2022 | heap + absolute_times_partitioned_table | eventdate | absolute_times_partitioned_table_2022_04_01_2022_05_01 | 04-01-2022 | 05-01-2022 | heap absolute_times_partitioned_table | eventdate | absolute_times_partitioned_table_2020_01_01_2020_02_01 | 01-01-2020 | 02-01-2020 | heap absolute_times_partitioned_table | eventdate | absolute_times_partitioned_table_2020_02_01_2020_03_01 | 02-01-2020 | 03-01-2020 | heap absolute_times_partitioned_table | eventdate | absolute_times_partitioned_table_2020_03_01_2020_04_01 | 03-01-2020 | 04-01-2020 | heap @@ -754,7 +754,7 @@ BEGIN; absolute_times_partitioned_table | eventdate | absolute_times_partitioned_table_2020_10_01_2020_11_01 | 10-01-2020 | 11-01-2020 | heap absolute_times_partitioned_table | eventdate | absolute_times_partitioned_table_2020_11_01_2020_12_01 | 11-01-2020 | 12-01-2020 | heap absolute_times_partitioned_table | eventdate | absolute_times_partitioned_table_2020_12_01_2021_01_01 | 12-01-2020 | 01-01-2021 | heap - absolute_times_partitioned_table | eventdate | absolute_times_partitioned_table_2022_04_01_2022_05_01 | 04-01-2022 | 05-01-2022 | heap + absolute_times_partitioned_table | eventdate | absolute_times_partitioned_table_2021_01_01_2021_02_01 | 01-01-2021 | 02-01-2021 | heap absolute_times_partitioned_table | eventdate | absolute_times_partitioned_table_2022_05_01_2022_06_01 | 05-01-2022 | 06-01-2022 | heap absolute_times_partitioned_table | eventdate | absolute_times_partitioned_table_2022_06_01_2022_07_01 | 06-01-2022 | 07-01-2022 | heap absolute_times_partitioned_table | eventdate | absolute_times_partitioned_table_2022_07_01_2022_08_01 | 07-01-2022 | 08-01-2022 | heap diff --git a/src/test/regress/expected/timeseries_get_missing_partition_ranges.out b/src/test/regress/expected/timeseries_get_missing_partition_ranges.out index f59f81da6..3d4530e1b 100644 --- a/src/test/regress/expected/timeseries_get_missing_partition_ranges.out +++ b/src/test/regress/expected/timeseries_get_missing_partition_ranges.out @@ -110,14 +110,14 @@ BEGIN; (1 row) - CREATE TABLE date_partitioned_table_manual_partition PARTITION OF date_partitioned_table FOR VALUES FROM (now() + INTERVAL '15 days') TO (now() + INTERVAL '30 days'); + CREATE TABLE date_partitioned_table_manual_partition PARTITION OF date_partitioned_table FOR VALUES FROM '2030-01-01'::date TO '2040-01-01'::date; +ERROR: syntax error at or near "'2030-01-01'" SELECT date_trunc('day', now()) - range_from_value::date as from_diff, date_trunc('day', now()) - range_to_value::date as to_diff - FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '20 days', now() - INTERVAL '20 days') + FROM get_missing_partition_ranges('date_partitioned_table', '2031-01-01'::date, '2021-01-01'::date) ORDER BY 1,2; -ERROR: Partition with the range from Wed Sep 15 00:00:00 2021 PDT to Thu Sep 16 00:00:00 2021 PDT has been created manually. Please remove all manually created partitions to use the table as timeseries table -CONTEXT: PL/pgSQL function get_missing_partition_ranges(regclass,timestamp with time zone,timestamp with time zone) line XX at RAISE +ERROR: current transaction is aborted, commands ignored until end of transaction block ROLLBACK; DROP TABLE date_partitioned_table; -- Show range values for timestamptz partitioned table @@ -300,14 +300,14 @@ BEGIN; (1 row) - CREATE TABLE tstz_partitioned_table_manual_partition PARTITION OF tstz_partitioned_table FOR VALUES FROM (now() + INTERVAL '15 days') TO (now() + INTERVAL '30 days'); + CREATE TABLE tstz_partitioned_table_manual_partition PARTITION OF tstz_partitioned_table FOR VALUES FROM '2030-01-01'::timestamptz TO '2040-01-01'::timestamptz; +ERROR: syntax error at or near "'2030-01-01'" SELECT date_trunc('day', now()) - range_from_value::timestamp with time zone as from_diff, date_trunc('day', now()) - range_to_value::timestamp with time zone as to_diff - FROM get_missing_partition_ranges('tstz_partitioned_table', now() + INTERVAL '20 days', now() - INTERVAL '20 days') + FROM get_missing_partition_ranges('tstz_partitioned_table', '2031-01-01'::timestamptz, '2021-01-01'::timestamptz) ORDER BY 1,2; -ERROR: Partition with the range from Wed Sep 15 00:00:00 2021 PDT to Thu Sep 16 00:00:00 2021 PDT has been created manually. Please remove all manually created partitions to use the table as timeseries table -CONTEXT: PL/pgSQL function get_missing_partition_ranges(regclass,timestamp with time zone,timestamp with time zone) line XX at RAISE +ERROR: current transaction is aborted, commands ignored until end of transaction block ROLLBACK; -- Test with different time zones SET timezone TO 'UTC'; diff --git a/src/test/regress/sql/timeseries_create_drop_timeseries_table.sql b/src/test/regress/sql/timeseries_create_drop_timeseries_table.sql index c3bd8cfa3..643fd5bb9 100644 --- a/src/test/regress/sql/timeseries_create_drop_timeseries_table.sql +++ b/src/test/regress/sql/timeseries_create_drop_timeseries_table.sql @@ -238,3 +238,30 @@ BEGIN; DROP TABLE drop_check_test_partitioned_table; SELECT * FROM timeseries.tables; COMMIT; + +-- Check distributed partitioned table +CREATE TABLE distributed_partitioned_table( + measureid integer, + eventdate date, + measure_data integer) PARTITION BY RANGE(eventdate); + +SELECT create_distributed_table('distributed_partitioned_table', 'measureid'); +SELECT create_timeseries_table('distributed_partitioned_table', INTERVAL '1 day'); +SELECT * FROM timeseries.tables; + +-- We should have 512 shards since we have 15 partitions and 1 parent table +SELECT count(*) +FROM pg_dist_shard +WHERE logicalrelid::text LIKE 'distributed_partitioned_table%'; + +DROP TABLE distributed_partitioned_table; +SELECT * FROM timeseries.tables; + +-- Show that partitioned reference tables are not supported +CREATE TABLE partitioned_reference_table( + measureid integer, + eventdate date, + measure_data integer) PARTITION BY RANGE(eventdate); + +SELECT create_reference_table('partitioned_reference_table'); +DROP TABLE partitioned_reference_table; diff --git a/src/test/regress/sql/timeseries_create_missing_partitions.sql b/src/test/regress/sql/timeseries_create_missing_partitions.sql index 5893caef6..f5de2f676 100644 --- a/src/test/regress/sql/timeseries_create_missing_partitions.sql +++ b/src/test/regress/sql/timeseries_create_missing_partitions.sql @@ -205,7 +205,7 @@ BEGIN; SELECT * FROM pg_catalog.time_partitions WHERE parent_table = 'absolute_times_partitioned_table'::regclass - ORDER BY 1,2,3; + ORDER BY 3; ROLLBACK; DROP TABLE absolute_times_partitioned_table; diff --git a/src/test/regress/sql/timeseries_get_missing_partition_ranges.sql b/src/test/regress/sql/timeseries_get_missing_partition_ranges.sql index d279d5d06..75b76c8e9 100644 --- a/src/test/regress/sql/timeseries_get_missing_partition_ranges.sql +++ b/src/test/regress/sql/timeseries_get_missing_partition_ranges.sql @@ -47,11 +47,11 @@ ROLLBACK; -- Show that table must not have manual partitions BEGIN; SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); - CREATE TABLE date_partitioned_table_manual_partition PARTITION OF date_partitioned_table FOR VALUES FROM (now() + INTERVAL '15 days') TO (now() + INTERVAL '30 days'); + CREATE TABLE date_partitioned_table_manual_partition PARTITION OF date_partitioned_table FOR VALUES FROM '2030-01-01'::date TO '2040-01-01'::date; SELECT date_trunc('day', now()) - range_from_value::date as from_diff, date_trunc('day', now()) - range_to_value::date as to_diff - FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '20 days', now() - INTERVAL '20 days') + FROM get_missing_partition_ranges('date_partitioned_table', '2031-01-01'::date, '2021-01-01'::date) ORDER BY 1,2; ROLLBACK; @@ -112,11 +112,11 @@ ROLLBACK; -- Show that table must not have manual partitions BEGIN; SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 day'); - CREATE TABLE tstz_partitioned_table_manual_partition PARTITION OF tstz_partitioned_table FOR VALUES FROM (now() + INTERVAL '15 days') TO (now() + INTERVAL '30 days'); + CREATE TABLE tstz_partitioned_table_manual_partition PARTITION OF tstz_partitioned_table FOR VALUES FROM '2030-01-01'::timestamptz TO '2040-01-01'::timestamptz; SELECT date_trunc('day', now()) - range_from_value::timestamp with time zone as from_diff, date_trunc('day', now()) - range_to_value::timestamp with time zone as to_diff - FROM get_missing_partition_ranges('tstz_partitioned_table', now() + INTERVAL '20 days', now() - INTERVAL '20 days') + FROM get_missing_partition_ranges('tstz_partitioned_table', '2031-01-01'::timestamptz, '2021-01-01'::timestamptz) ORDER BY 1,2; ROLLBACK;