From 2e625164bad9acf0c3c02185d8f141e4d433bb11 Mon Sep 17 00:00:00 2001 From: Keith Fiske Date: Thu, 7 Nov 2024 13:04:43 -0500 Subject: [PATCH] fix: add additional parent table properties for child inheritance --- CHANGELOG.md | 1 + sql/functions/create_parent.sql | 2 +- sql/functions/create_partition_id.sql | 3 +-- sql/functions/create_partition_time.sql | 2 +- test/test-dump-definition.sql | 2 +- updates/pg_partman--5.1.0--5.2.0.sql | 8 ++++---- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff0128f..a230150 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ NEW FEATURES - Do not create partitions during a maintenance run that aren't going to be kept as part of retention anyway. (Github Issue #649) - Removed `default_table` column from `part_config` table. It's only necessary in `part_config_sub` to determine whether future sub-partition parents should have defaults made. Adjusted other code to look up whether a default table actually exists to determine its behavior. (Github Issue #637) - Allow the control column to be NULL. This is not advised without very careful review and an explicit use-case defined as it can cause unexpected behavior or excessive data in the DEFAULT child partition. A new flag `p_control_not_null` has been added to the `create_parent()` and `create_sub_parent()` functions. +- Include the following additional parent table properties on newly created child tables: COMPRESSION, STORAGE, and STATISTICS. Note this is only for newly created child tables. Existing child tables will have to be updated manually. (Github Issue #683) BUG FIXES --------- diff --git a/sql/functions/create_parent.sql b/sql/functions/create_parent.sql index 83e8727..41305e3 100644 --- a/sql/functions/create_parent.sql +++ b/sql/functions/create_parent.sql @@ -610,7 +610,7 @@ IF p_default_table THEN */ -- Same INCLUDING list is used in create_partition_*(). INDEXES is handled when partition is attached if it's supported. - v_sql := v_sql || format(' TABLE %I.%I (LIKE %I.%I INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING STORAGE INCLUDING COMMENTS INCLUDING GENERATED)' + v_sql := v_sql || format(' TABLE %I.%I (LIKE %I.%I INCLUDING COMMENTS INCLUDING COMPRESSION INCLUDING CONSTRAINTS INCLUDING DEFAULTS INCLUDING GENERATED INCLUDING STATISTICS INCLUDING STORAGE)' , v_parent_schema, v_default_partition, v_parent_schema, v_parent_tablename); IF v_parent_tablespace IS NOT NULL THEN v_sql := format('%s TABLESPACE %I ', v_sql, v_parent_tablespace); diff --git a/sql/functions/create_partition_id.sql b/sql/functions/create_partition_id.sql index 518eea3..61b7d74 100644 --- a/sql/functions/create_partition_id.sql +++ b/sql/functions/create_partition_id.sql @@ -126,9 +126,8 @@ FOREACH v_id IN ARRAY p_partition_ids LOOP v_step_id := add_step(v_job_id, 'Creating new partition '||v_partition_name||' with interval from '||v_id||' to '||(v_id + v_partition_interval)-1); END IF; - -- Close parentheses on LIKE are below due to differing requirements of subpartitioning -- Same INCLUDING list is used in create_parent() - v_sql := format('CREATE TABLE %I.%I (LIKE %I.%I INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING STORAGE INCLUDING COMMENTS INCLUDING GENERATED) ' + v_sql := format('CREATE TABLE %I.%I (LIKE %I.%I INCLUDING COMMENTS INCLUDING COMPRESSION INCLUDING CONSTRAINTS INCLUDING DEFAULTS INCLUDING GENERATED INCLUDING STATISTICS INCLUDING STORAGE) ' , v_parent_schema , v_partition_name , v_parent_schema diff --git a/sql/functions/create_partition_time.sql b/sql/functions/create_partition_time.sql index b229c05..e8a02de 100644 --- a/sql/functions/create_partition_time.sql +++ b/sql/functions/create_partition_time.sql @@ -186,7 +186,7 @@ FOREACH v_time IN ARRAY p_partition_times LOOP */ -- Same INCLUDING list is used in create_parent() - v_sql := v_sql || format(' TABLE %I.%I (LIKE %I.%I INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING STORAGE INCLUDING COMMENTS INCLUDING GENERATED) ' + v_sql := v_sql || format(' TABLE %I.%I (LIKE %I.%I INCLUDING COMMENTS INCLUDING COMPRESSION INCLUDING CONSTRAINTS INCLUDING DEFAULTS INCLUDING GENERATED INCLUDING STATISTICS INCLUDING STORAGE) ' , v_parent_schema , v_partition_name , v_parent_schema diff --git a/test/test-dump-definition.sql b/test/test-dump-definition.sql index f2c3d02..95a3d11 100644 --- a/test/test-dump-definition.sql +++ b/test/test-dump-definition.sql @@ -80,7 +80,7 @@ E'SELECT partman.create_parent( p_template_table := ''partman.template_partman_test_declarative_objects'', p_jobmon := ''t'', p_date_trunc_interval := NULL, - p_control_not_null := ''t'' + p_control_not_null := ''t'' ); UPDATE partman.part_config SET optimize_constraint = 30, diff --git a/updates/pg_partman--5.1.0--5.2.0.sql b/updates/pg_partman--5.1.0--5.2.0.sql index 67b0011..67e4ffa 100644 --- a/updates/pg_partman--5.1.0--5.2.0.sql +++ b/updates/pg_partman--5.1.0--5.2.0.sql @@ -1,5 +1,6 @@ -- TODO - add test for PR#650 - not creating partitions that aren't being retained anyway -- - add test to ensure sub partitioning preserves default table settings and not null enforcement +-- - add test for constraint exclusion with integer-based partitioning -- TODO PRESERVE PRIVILEGES DROP FUNCTION @extschema@.create_parent(text, text, text, text, text, int, text, boolean, text, text[], text, boolean, text); @@ -2383,7 +2384,7 @@ IF p_default_table THEN */ -- Same INCLUDING list is used in create_partition_*(). INDEXES is handled when partition is attached if it's supported. - v_sql := v_sql || format(' TABLE %I.%I (LIKE %I.%I INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING STORAGE INCLUDING COMMENTS INCLUDING GENERATED)' + v_sql := v_sql || format(' TABLE %I.%I (LIKE %I.%I INCLUDING COMMENTS INCLUDING COMPRESSION INCLUDING CONSTRAINTS INCLUDING DEFAULTS INCLUDING GENERATED INCLUDING STATISTICS INCLUDING STORAGE)' , v_parent_schema, v_default_partition, v_parent_schema, v_parent_tablename); IF v_parent_tablespace IS NOT NULL THEN v_sql := format('%s TABLESPACE %I ', v_sql, v_parent_tablespace); @@ -2794,9 +2795,8 @@ FOREACH v_id IN ARRAY p_partition_ids LOOP v_step_id := add_step(v_job_id, 'Creating new partition '||v_partition_name||' with interval from '||v_id||' to '||(v_id + v_partition_interval)-1); END IF; - -- Close parentheses on LIKE are below due to differing requirements of subpartitioning -- Same INCLUDING list is used in create_parent() - v_sql := format('CREATE TABLE %I.%I (LIKE %I.%I INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING STORAGE INCLUDING COMMENTS INCLUDING GENERATED) ' + v_sql := format('CREATE TABLE %I.%I (LIKE %I.%I INCLUDING COMMENTS INCLUDING COMPRESSION INCLUDING CONSTRAINTS INCLUDING DEFAULTS INCLUDING GENERATED INCLUDING STATISTICS INCLUDING STORAGE) ' , v_parent_schema , v_partition_name , v_parent_schema @@ -3171,7 +3171,7 @@ FOREACH v_time IN ARRAY p_partition_times LOOP */ -- Same INCLUDING list is used in create_parent() - v_sql := v_sql || format(' TABLE %I.%I (LIKE %I.%I INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING STORAGE INCLUDING COMMENTS INCLUDING GENERATED) ' + v_sql := v_sql || format(' TABLE %I.%I (LIKE %I.%I INCLUDING COMMENTS INCLUDING COMPRESSION INCLUDING CONSTRAINTS INCLUDING DEFAULTS INCLUDING GENERATED INCLUDING STATISTICS INCLUDING STORAGE) ' , v_parent_schema , v_partition_name , v_parent_schema