Refactor partition suffix logic to allow custom child prefixes - #830
pavan-postgres wants to merge 2 commits into
Conversation
|
Don't think I'm going to be able to get this into the next release, but I do like the idea. Will come back to review this after next release is out. Thank you! |
|
Apologies for the delay in response. Reviewing this again, so this doesn't really allow custom prefixes to the child name suffix, it just allows the removal of the "p" in the suffix name. It also doesn't boil up to a point where it actually allows the user to put the setting into effect. So on second thought I'm not sure I'd like to implement this as is for now. If maybe you wanted to redo this to actually allow full customization of the prefix to the childname suffix naming pattern, I may consider that. Although I am a little hesitant on adding more flags to the create_partition() function right now. Can you perhaps more clearly state the intended usage of this? |
Updated the logic for determining suffixes of partitioned tables.
Previous implementation always appended '_p' for partitioned tables:
v_suffix := format('%s%s', CASE WHEN p_table_partition THEN '_p' END, p_suffix);
New logic allows using a simple naming convention for child tables without affecting existing behavior:
v_suffix := format('%s%s',
CASE
WHEN p_table_partition AND p_simple_naming THEN '_'
WHEN p_table_partition THEN '_p'
END,
p_suffix
);
This change enables specifying a custom prefix/suffix for child table names (via `p_suffix`) while preserving the original '_p' behavior for partitions that do not use simple naming. It makes the code more flexible without breaking existing functionality.
Addresses review feedback on this PR: the previous p_simple_naming flag only let you toggle between '_p' and '_', and never actually took effect anywhere since nothing exposed it past check_name_length(). This replaces it with a real, arbitrary child_table_prefix column on part_config (default '_p', so existing partition sets are unaffected) that is threaded through every place child table names are generated: create_partition_time(), create_partition_id(), show_partition_name(), partition_data_time(), partition_data_id(), and dump_partitioned_table_definition(). It intentionally does not add a new parameter to create_partition()/ create_parent() - like other settings not exposed there (retention, optimize_constraint, etc.), it's set afterwards with UPDATE part_config SET child_table_prefix = '...' WHERE parent_table = ... Also adds pgTAP coverage for both time- and id-based partitioning, a migration script, and doc/changelog updates. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1447a42 to
0bc5691
Compare
|
Sorry for the slow follow-up, and thanks for the detailed feedback — both points are fair, so I reworked this instead of just patching around them. "Doesn't really allow custom prefixes" — agreed, "Doesn't boil up to where the user can actually use it" — also agreed. It's now backed by a real On the "hesitant to add more flags to UPDATE part_config SET child_table_prefix = '_' WHERE parent_table = 'my_schema.my_table';Intended usage: anyone who wants child tables named Scope-wise I kept this to top-level partition sets only (not Added pgTAP coverage(took Claude's help) for both time- and id-based partitioning, a migration script, and doc/changelog updates. Ran the full test suite locally (PG17, |
Updated the logic for determining suffixes of partitioned tables.
Previous implementation always appended '_p' for partitioned tables:
New logic allows using a simple naming convention for child tables without affecting existing behavior:
This change enables specifying a custom prefix/suffix for child table names (via
p_suffix) while preserving the original '_p' behavior for partitions that do not use simple naming. It makes the code more flexible without breaking existing functionality.