-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement encode/decode for ID columns #730
base: development
Are you sure you want to change the base?
Conversation
@@ -18,7 +18,6 @@ v_analyze boolean := FALSE; | |||
v_check_subpart int; | |||
v_child_timestamp timestamptz; | |||
v_control_type text; | |||
v_time_encoder text; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this variable since it isn't used anywhere.
-- avoids the need for a functional index using to_timestamp or decoder on control column to quickly find the max | ||
v_max_control_expression := CASE | ||
WHEN v_row.epoch = 'seconds' THEN format('to_timestamp(max(%I))', v_row.control) | ||
WHEN v_row.epoch = 'milliseconds' THEN format('to_timestamp((max(%I)/1000)::float)', v_row.control) | ||
WHEN v_row.epoch = 'microseconds' THEN format('to_timestamp((max(%I)/1000000)::float)', v_row.control) | ||
WHEN v_row.epoch = 'nanoseconds' THEN format('to_timestamp((max(%I)/1000000000)::float)', v_row.control) | ||
WHEN v_row.epoch = 'func' THEN format('%s(max(%I))', v_time_decoder, v_row.control) | ||
ELSE format('max(%I)', v_row.control) | ||
END; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should remove the need for a functional index to find the maximum, provided there is an index on the underlying column. That should be a safe assumption to make since postgres prohibits creating a unique index or primary key on a partitioned table that doesn't contain the partition key.
If this works in all scenarios, it should also be ported to partition_data_time()
Marking as draft because this still needs tests for smaller integer types |
Thank you! Will be a bit busy over the next month or so, so may not get to dig into this for a bit. Just reading your notes, though, it is possible to have unique indexes on non-control columns for individual tables using the template table system in partman. May also want to keep in mind that it may be possible in core in the future as well. So not sure if that will affect what you've done. |
Unique indexes on individual partitions or on non-control columns won't affect anything in this PR. The intent is to optimize the check by using pg_partman/sql/functions/partition_data_time.sql Lines 131 to 159 in 1192e93
One other improvement I want to make is a round-trip and ordering sanity check for the passed functions, and an assert that the functions are at least marked Also, I think Julian dates might make an interesting example for 32-bit IDs, so I will play with that for a daily test. |
This PR allows users to specify the special value of 'func' for p_epoch to use custom functions to encode/decode time-ordered integers other than the classic seconds, ms, us or ns since the UNIX epoch. Resolves pgpartman#729.
5d85138
to
9f8dfa2
Compare
9f8dfa2
to
c592b2b
Compare
This PR allows users to specify the special value of 'func' for p_epoch to use custom functions to encode/decode time-ordered integers other than the classic seconds, ms, us or ns since the UNIX epoch.
Resolves #729.