-
Notifications
You must be signed in to change notification settings - Fork 882
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
Add support for merging chunks #7433
base: main
Are you sure you want to change the base?
Conversation
ce949f8
to
581388c
Compare
@@ -44,6 +44,10 @@ CREATE OR REPLACE FUNCTION @[email protected]_chunk( | |||
if_compressed BOOLEAN = true | |||
) RETURNS REGCLASS AS '@MODULE_PATHNAME@', 'ts_decompress_chunk' LANGUAGE C STRICT VOLATILE; | |||
|
|||
CREATE OR REPLACE PROCEDURE @[email protected]_chunks( |
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 put the function in the extension schema instead of _timescaledb_functions
since it is a function in line with compress_chunk
, etc. But we could move it to _timescaledb_functions
if we want this to be less of a public feature. 🤷
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 think this is on the same level as compress_chunk
, drop_chunk
, and friends so we should keep it at the same place as these.
ba6ea6a
to
8d36316
Compare
8d36316
to
66850c7
Compare
A new procedure called `merge_chunks` is introduced that can merge an arbitrary number of chunks if the right conditions apply. Basic checks are done to ensure that the chunks can be merged from a partitioning perspective. Some more advanced cases that are potentially mergeable are not supported at this time (e.g., complicated merges of chunks with multi-dimensional partitioning). Currently, the merge defaults to taking an AccessExclusive lock on the merged chunks to prevent deadlocks and concurrent modifications. Weaker locking is supported via an anonymous settings variable, but this is mostly to prove in tests that these approaches can lead to deadlocks. The actual merging is done by rewriting all the data from multiple chunks into a (temporary) merged heap using the same approach as that implemented to support VACUUM FULL and CLUSTER. Then this new heap is swapped into one of the original relations while the rest are dropped. This approach is MVCC compliant and implements correct visibility under higher isolation levels, while also doing vacuum and leaving no garbage tuples.
66850c7
to
bd20e92
Compare
A new procedure called
merge_chunks
is introduced that can merge an arbitrary number of chunks if the right conditions apply. Basic checks are done to ensure that the chunks can be merged from a partitioningperspective. Some more advanced cases that are potentially mergeable are not supported at this time (e.g., complicated merges of chunks with multi-dimensional partitioning).
Currently, the merge defaults to taking an AccessExclusive lock on the merged chunks to prevent deadlocks and concurrent modifications. Weaker locking is supported via an anonymous settings variable, but this is mostly to prove in tests that these approaches can lead to deadlocks.
The actual merging is done by rewriting all the data from multiple chunks into a (temporary) merged heap using the same approach as that implemented to support VACUUM FULL and CLUSTER. Then this new heap is swapped into one of the original relations while the rest are dropped. This approach is MVCC compliant and implements correct visibility under higher isolation levels, while also doing vacuum and leaving no garbage tuples.