{{ message }}
Fix flaky test 03800_use_const_adaptive_granularity_vertical_merge#100641
Merged
pufit merged 2 commits intoMar 26, 2026
Conversation
Use OPTIMIZE TABLE ... FINAL instead of bare OPTIMIZE TABLE. Without FINAL, OPTIMIZE TABLE uses the regular merge selector which can silently be a no-op when the merge pool is saturated (returns max_source_parts_bytes_for_merge == 0) in parallel test environments. With FINAL, the code bypasses the merge selector via selectAllPartsToMergeWithinPartition and retries if parts are currently being merged, making it reliable under load. The test's purpose is verifying use_const_adaptive_granularity with vertical merge — the OPTIMIZE is just a means to trigger the merge, not the subject under test. The nested variant of this test already uses OPTIMIZE TABLE ... FINAL. 13 failures across 4 unrelated PRs + master in the last 30 days.
Contributor
|
Workflow [PR], commit [904299f] Summary: ✅ AI ReviewSummaryThis PR updates ClickHouse RulesFinal Verdict
|
1 task
alexey-milovidov
approved these changes
Mar 25, 2026
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Use
OPTIMIZE TABLE ... FINALinstead of bareOPTIMIZE TABLE.Without
FINAL, theoptimize()code path callsselect_without_hint(), which checksmax_source_parts_bytes_for_mergefromCompactionStatistics::getMaxSourcePartsBytesForMerge(). When the background merge pool is saturated by parallel tests (the CI runs dozens of stateless tests concurrently), this value drops to zero andOPTIMIZE TABLEsilently returns without merging anything — the parts stay as-is.With
FINAL, the code path goes throughselect_in_partition()→selectAllPartsToMergeWithinPartition(), which bypasses the merge-selector resource check entirely and also retries with a wait loop if parts are currently being merged by background threads.The test's purpose is verifying
use_const_adaptive_granularitywith vertical merge — theOPTIMIZEis just a means to trigger the merge, not the subject under test. The nested variant of this test (03800_..._nested.sql.j2) already usesOPTIMIZE TABLE ... FINAL.Reproduction: adding
max_bytes_to_merge_at_max_space_in_pool = 0to the table'sSETTINGS(simulating a saturated merge pool) makes the original test fail deterministically with the exact diff seen in CI; the fixed version passes under the same conditions.13 failures across 4 unrelated PRs + master over the last 30 days.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Documentation entry for user-facing changes
Version info
26.4.1.275