pg_partman icon indicating copy to clipboard operation
pg_partman copied to clipboard

[Feature request] create_parent: add an offset in the partitions

Open javiEsteban1993 opened this issue 4 years ago • 6 comments

Hi,

I needed to create partitions by id, but the first partition starts for id 0 and I needed the first partition to be for id 1, so I suggest adding an offset in the create_parent function to select the first partition, this offset will be a parameter obtained by argument.

In the create_parent function, add a new variable integer called offset initialized to 0 to keep current use, then add the following code on line 576: v_starting_partition_id := v_max - (v_max % v_id_interval); v_starting_partition_id := v_starting_partition_id + offset; FOR i IN 0..p_premake LOOP

javiEsteban1993 avatar Feb 09 '21 08:02 javiEsteban1993

Initially I thought the p_start_partition parameter would handle that, but apparently it still started at zero. I'll look into it when I have a chance or if you'd like to make a patch I'd be happy to review it.

keithf4 avatar Feb 10 '21 21:02 keithf4

I think one issue with this that I'm still unsure of is do you need that offset just for the first partition or do you need that offset to continue forward? Like if the interval was 10, the child tables would normally be spaced like

0 10 20 30

Do you want that offset just for the first table like this?

1 10 20 30

Or for all going forward?

1 11 21 31

If you just want the first one, I honestly don't really see the need for it. While the table may have a lower boundary of 0, that doesn't mean it has to insert that zero value. If that was a concern just for that first child table, you could add a one-off constraint to that first child to prevent it.

If it needs to be a permanent offset for the entire partition set, that I could possibly look into.

keithf4 avatar Apr 07 '21 14:04 keithf4

My idea was add an offset, because if I want to start the partition, for example with ID 15 and an interval of 10 I would like to get: 15 25 35 Then I solved it adding this: In the create_parent function on line 576: v_starting_partition_id := v_max - (v_max % v_id_interval); v_starting_partition_id := v_starting_partition_id + offset; FOR i IN 0..p_premake LOOP

javiEsteban1993 avatar Apr 07 '21 14:04 javiEsteban1993

Ok. Just wanted some clarification. Thanks!

keithf4 avatar Apr 07 '21 15:04 keithf4

For any question ask me, Thanks in advance

javiEsteban1993 avatar Apr 07 '21 15:04 javiEsteban1993

Marking this as a feature to look into for 5.0. If I get a chance to look at it before then I will try.

keithf4 avatar Jun 25 '22 21:06 keithf4