v.21.7Improvement

Add max_parts_to_merge_at_once Setting to Limit Background Merges

Add merge tree setting max_parts_to_merge_at_once which limits the number of parts that can be merged in the background at once. Doesn't affect OPTIMIZE FINAL query. Fixes #1820. #24496 (alesapin).
Introduced the merge tree setting max_parts_to_merge_at_once to limit the number of parts merged concurrently in the background, improving control over background merges without affecting OPTIMIZE FINAL operations.

Why it matters

This setting addresses the issue of uncontrolled background merges potentially impacting system resources by allowing users to cap the number of parts merged at once in a merge tree. It helps optimize resource usage and system performance by preventing excessive simultaneous merges.

How to use it

To apply this feature, set the max_parts_to_merge_at_once parameter in the merge tree table settings. This limits the background merges to the specified number of parts. Note that this setting does not affect OPTIMIZE FINAL queries, which will merge all parts regardless of this limit.

Example:
ALTER TABLE <table_name> MODIFY SETTING max_parts_to_merge_at_once = <number>;