Skip to content

Commit

Permalink
fix: add additional parent table properties for child inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
keithf4 committed Nov 7, 2024
1 parent 06d17cb commit 2e62516
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------
Expand Down
2 changes: 1 addition & 1 deletion sql/functions/create_parent.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions sql/functions/create_partition_id.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sql/functions/create_partition_time.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/test-dump-definition.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions updates/pg_partman--5.1.0--5.2.0.sql
Original file line number Diff line number Diff line change
@@ -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 @[email protected]_parent(text, text, text, text, text, int, text, boolean, text, text[], text, boolean, text);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2e62516

Please sign in to comment.