Repository navigation
Coalesce adjacent singleton row-mask updates during part mutation - #122718
Conversation
Repeated singleton IN predicates in a part mutation evaluate separate sets for each command. Coalesce adjacent compatible predicates for part-local execution, while preserving persisted mutation records, barriers, and original file planning. Bound group and input sizes and bypass unsupported part formats and settings. The preceding mirror-master candidate passed matched Release SQL checks and a repeated synthetic Wide Full benchmark. This public-master port adapts to the current splitAndModifyMutationCommands signature. Public CI, SharedMergeTree integration, mixed-version validation, and a production canary remain pending.
The public repository has no SharedMergeTree engine registration or call site for its scheduling failpoint, so the imported stateless test cannot run here. Existing stateless and ReplicatedMergeTree integration tests cover the public mutation behavior. Cloud-specific validation remains a separate rollout gate.
|
Workflow [PR], commit [bf82ae5] Summary: ✅
AI ReviewSummaryThis PR adds a bounded part-local optimization that coalesces adjacent singleton Final Verdict
LLVM Coverage ReportMeasured on commit bf82ae5.
Changed lines: Changed C/C++ lines covered: 263/283 (92.93%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes4 object files changed (+91.92 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units8 translation units recompiled, 32 s compile time in total, 8 of them have a recent master baseline. |
| || (settings[Setting::max_expanded_ast_elements] && settings[Setting::max_expanded_ast_elements] < 4096)) | ||
| return commands; | ||
|
|
||
| size_t max_keys_per_command = 256; |
There was a problem hiding this comment.
This should be a configurable MergeTree setting
| bool key_from_uint128_array_join = false; | ||
| }; | ||
|
|
||
| static constexpr size_t max_combined_key_bytes = 64 * 1024; |
There was a problem hiding this comment.
This should be a configurable MergeTree setting.
| /// remains a grouping barrier. Keep file-rename planning based on the | ||
| /// original commands, including one `UPDATE` entry per original command. | ||
| bool can_coalesce_row_mask_updates = ctx->commands_for_part.size() > 1 | ||
| && ctx->commands_for_part.size() <= 4096 |
There was a problem hiding this comment.
One more magic constant, it's not clear why we use it.
| size_t input_bytes = 0; | ||
| for (const auto & command : ctx->commands_for_part) | ||
| { | ||
| if (command.ast_text.size() > (1 << 20) - input_bytes) |
There was a problem hiding this comment.
One more magic constant 1 << 20, not clear why exactly this and why we need it at all
Many singleton IN row-mask updates repeatedly evaluate predicates over a large Wide Full part. The original fast path also lacked table-level bounds and an off switch, and alias or expanded-AST cases could change behavior. Add MergeTree controls and bounded fallback, reject unsafe alias/subquery shapes, and retain original commands under an explicitly configured finite expanded query-tree limit. Extend stateless and integration coverage for the new guards and settings. Verified with a Release build, SQL references 05256-05258, an expanded-AST limit-100 reproducer, and same-binary synthetic OFF/ON benchmarks. The targeted integration module could not start because the isolated dev VM could not pull the uncached ZooKeeper image; upstream CI remains pending.
The generated MergeTree setting description said Wide even though the existing execution gate requires both Wide format and Full storage. Name the Full storage requirement so users do not expect the optimization on Packed parts. Verification: staged diff and whitespace checks passed, and the wording was compared with the unchanged execution gate. No C++ build was run for this raw-string documentation edit; PR CI will validate the new head.
|
📊 Cloud Performance Report ✅ AI verdict: This PR changes only how mutations run. It merges adjacent single-key UPDATE _row_exists = 0 commands while rewriting Wide parts (MutateTask::prepare) and adds new MergeTree settings to control that. No ClickBench or TPC-H SELECT runs that code, and neither benchmark has a performance change to report. The three flagged ClickBench queries are all small, noise-level improvements: Q33 (-5.7%) and Q34 (-5.5%) fall inside master's normal range, and Q28 (-5.3%) is borderline because the two tests disagree, with CPU time essentially flat in all three. Those within-range rulings fit the diff, and nothing in this PR justifies challenging them. clickbenchFlagged queries (1 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
Backport #122718 to 26.8: Coalesce adjacent singleton row-mask updates during part mutation
Backport #122718 to 26.9: Coalesce adjacent singleton row-mask updates during part mutation
…ask updates during part mutation
Many separately queued singleton
UPDATE _row_exists = 0 WHERE ... IN (...)commands can reach one large part in a single mutation task. Each command otherwise evaluates its ownINpredicate over that part. This change coalesces adjacent compatible commands for part-local execution while preserving persisted mutation records, version barriers, and original file planning.The path is limited to Wide Full parts, supported constant predicates, and stable physical key types. It rejects aliases that could change predicate resolution and SELECT modifiers that could make a nominally singleton subquery return multiple rows. Other inputs use the existing path.
MergeTree table settings control the optimization and its resource bounds:
enable_row_mask_update_coalescing(defaulttruein 26.10;falseundercompatibility=26.9)max_row_mask_update_coalescing_keys(default 256; also respects the effective backgroundmax_rows_in_set)max_row_mask_update_coalescing_key_bytes(default 64 KiB)max_row_mask_update_coalescing_commands(default 4,096)max_row_mask_update_coalescing_ast_bytes(default 1 MiB)The optimization also respects effective background Set and AST limits. It skips coalescing when an explicitly configured finite
max_expanded_ast_elementslimit is in effect, because the raw mutation AST does not bound the analyzer's expanded query tree.An isolated Release build of the merged source completed on the dev VM (
26.10.1.1; binary SHA-2565b4ec3e84e15c4811bee09cea14ba177c2aa9eb9bbdc125f0e4d4367ed0c5b40). The expanded-tree reproducer used ten singleton updates plusMATERIALIZE INDEXwith a backgroundmax_expanded_ast_elementsof 100: OFF and ON both completed all 11 mutation records, returned the same remaining row, and showed no QueryTree error or coalescing. SQL references05256–05258matched, covering the assignment-alias case, subquery behavior, and separate mutation records. The targeted integration module did not start because its runner could not pull the uncachedzookeeper:3.6.2image through the dev VM's restricted network. Upstream CI is pending.On the same tested binary, a synthetic 2,000,000-row, 200-command, 0.24 GiB Wide Full part workload on 4 CPU had OFF post-START median 3.606 s (range 3.585–4.009 s) and ON median 0.813 s (range 0.803–0.950 s) across three alternating repetitions, about 4.4x on the median. Trace sampling confirmed
200 → 1commands when enabled. On a smaller 0.07 GiB part the medians were 1.174 s OFF and 1.120 s ON with overlapping ranges, so that workload did not establish a speedup. Two bypass workloads also had overlapping ranges: 200 non-singleton Wide commands had medians 1.194 s OFF and 1.113 s ON; Compact Full parts had 1.744 s OFF and 1.838 s ON. Trace sampling confirmed no coalescing in either bypass workload. These synthetic results are not a production speedup estimate or a tight overhead bound.The PR head
bf82ae53f7b9e803edc345b59591a5596a2d6ae5adds only a setting-description correction for the Wide and Full storage requirement to tested code commit90c10588d04a88c81aa4ca8fb068ec3acddae505. The Release build and runtime checks above were on that code commit; the documentation-only follow-up was not rebuilt locally. The code commit includes mergefc1399de3a324ce7c735dc0a9417ab90c9600d10from master snapshotbd202925d0d4a9e560455035284251b5f7be1cd7. All 14 PR paths, including two new integration config files, matched the separately merged dev VM source before the successful build. Upstream CI results are pending for the current head.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Reduce repeated
INevaluation when many adjacent singleton row-mask updates are applied to one part.Workflow [PR]
Sync PR [sync-upstream/pr/122718]
Version info
26.10.1.1579-master(included in26.10and later)26.9.23.15,26.8.32.14