Skip to content

Unite ready subquery Sets in batched row-mask mutations - #133454

Draft
skuznetsov-clickhouse wants to merge 17 commits into
ClickHouse:masterfrom
skuznetsov-clickhouse:codex/issue-132056-mask-batching
Draft

skuznetsov-clickhouse wants to merge 17 commits into
ClickHouse:masterfrom
skuznetsov-clickhouse:codex/issue-132056-mask-batching

Conversation

@skuznetsov-clickhouse

@skuznetsov-clickhouse skuznetsov-clickhouse commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Classic lightweight DELETE statements on large AggregatingMergeTree parts can retain many separate row-mask predicates in one part mutation. This extends the existing ordered row-mask executor with an optional specialization for compatible, already-built IN (SELECT ...) Set objects. It unions the typed keys once for the main part scan while preserving the original mutation IDs, per-stage Set build gates, command order and fallback when a source is empty, already spilling, incompatible or over budget. The feature defaults to off. Table settings bound the admitted source rows, raw key bytes and number of groups. Under finite background limits, the deferred union first checks a conservative bound on result rows and peak hash-table growth, then checks the resulting Set and replacement actions against the row, byte and temporary-column limits.

The specialization is limited to compatible positive IN predicates and supported fixed-width integer or tuple keys. Arbitrary row-mask predicates, NOT IN, external, already spilled and actively spilling Set sources use the original actions. Existing tests cover interleaved inserts and changing subquery results; a combined DELETE ... IN PARTITION fallback test is still missing. This PR remains a draft pending integration with current master and broader validation.

The preceding ASan/UBSan build passed the full test_mutation_row_mask_set_limit integration module (29/29). A local replay of all 18 previously failing Fast-test cases passed on that build: 15/15 in the finite-limit batch, plus 03999, 05853 and the Keeper-backed 05851 individually (1/1 each). The 05851 test and reference comparison passed, but its test controller reported a port still unavailable immediately after server shutdown; a later check found all owned ports free. The earlier exact-head Fast CI timed 05851 at 15.53 s, above its 15 s limit, so it is tagged no-fasttest. On the current ASan/UBSan build with the pre-copy finite-limit guard, two focused SetMemoryLimit tests passed (2/2), official 05816 passed under finite background limits (1/1), and the three targeted integration cases for row, byte and temporary-column limits passed (3/3). After restoring the expanded-AST-only background profile and separating finite byte/column limits into a new fixture, four affected integration cases passed (4/4) on that same binary. After initializing the two variables flagged by exact-head arm_tidy, clickhouse and unit_tests_dbms rebuilt cleanly; both focused SetMemoryLimit tests passed (2/2) on the rebuilt ASan/UBSan binary. Earlier focused RHS-empty and Code 241 cleanup/retry tests also passed. A private two-replica SharedAggregatingMergeTree fixture passed the changing-RHS correctness oracle. On 3209fc8, Style, Fast and all four arm_tidy shards passed; Fast skipped 05851 as tagged. The ordinary targeted stateless CI then passed 05851 37/37 on arm ASan/UBSan and 39/39 on amd ASan/UBSan. Praktika run. The targeted ASan/UBSan, TSan and MSan integration jobs passed on that head. 05814 and 05815 failed in DBReplicated CI because a mixed ALTER is prohibited there. The earlier whole-test tag also skipped their core checks in Cloud and Shared Catalog. Commit 98de305 moves only the mixed-command cases to tagged 05854/05855; the untagged core tests remain eligible under DBReplicated and Cloud runner flags. The standard Shared Catalog selector still skips those tests because they use plain MergeTree engines. A separate SharedAggregatingMergeTree test, 05857, checks result correctness and the RowMaskReadySubquerySetUnionBatches counter across two replicas: OFF must remain zero and ON must be positive. Its final .sh form suppresses host-specific SYSTEM FLUSH LOGS ON CLUSTER output and pins unrelated parallel replica modes. The official private two-replica clickhouse-test --shared-catalog runner passed the final file 1/1, zero skips, with randomized settings; a separate 1/1 replay forced the four parallel replica settings that had previously failed on the disposable fixture. The part_log recorded OFF union=0 and ON union=1. The private binary is pinned but differs from this OSS branch. After commit 9bc50f7 added bounded waiting for part_log, the official two-replica runner passed the updated 05857 twice (1/1 each, exact reference, OFF union=0 and ON union=1). The final guarded run returned success and removed its owned Docker resources; the preceding official test passed but its disposable controller rejected a stale script SHA. Exact-head OSS CI for 9bc50f7 was still running when the following test-only change was prepared. Three disposable Atomic ASan/UBSan runs of the four split cases passed (12/12, no skips). A disposable DBReplicated run with the CI profile passed 05814/05815 and skipped 05854/05855 as tagged; its pinned ASan/UBSan binary predates the latest C++ commit. Exact-head DBReplicated, Cloud and Shared Catalog CI remain pending. The mixed-command cases check ordered ALTER results; they do not directly prove the same-task grouping barrier. A same-build ASan/UBSan regression reproduced a Bool/UInt8 mismatch: with typed Set union enabled, a physical key 2 remained visible after a Bool subquery Set delete. Commit d078c31055d makes incompatible key types decline the union and retain the original mutation actions. The focused 05858 test passed 1/1 with fixed settings and 3/3 with randomized settings on the patched ASan/UBSan binary; 05839 passed 1/1 and still dispatched compatible unions. One randomized disposable run initially stopped on a missing parallel_replicas cluster before checking the result; the test now disables parallel replicas only for its verification queries. The separate 04780 allocation-oracle flake is addressed by the open PR linked below. Integration with current master and managed Cloud Dev/Stage remain open.

Commit 63a090c adds bounded waiting for the UUID-scoped MutatePart entry in 05837 and starts a separate log-publication deadline in 05853; the dispatch assertions and reference output are unchanged. The official disposable x86_64 Release ASan/UBSan runner passed both updated cases 2/2, followed by five fresh cycles with 10/10 passes and no sanitizer or OOM findings. Exact-head Praktika passed 05837 in Fast, amd_debug and arm_binary parallel (1/1 each), then 50/50 times in arm ASan/UBSan; 05853 passed 5/5 in arm_binary sequential. Three more official private two-replica Shared Catalog cycles passed the updated 05857 3/3, for five official passes including the two earlier cycles, with exact references and OFF/ON union counts of 0/1. The standard OSS CI route skips 05857 because it requires Shared Catalog. The pinned local and private binaries differ from the exact PR binary; broader exact-head CI remains in progress.

A full-diff review found that the non-constant temporary-column test was not reaching its intended limit: max_rows_in_set=1 rejected the two source rows first. An initial test-only correction still failed because its reused profile had an expanded-AST cap, which raised a Code 36 exception before the column check. Commit 4a26611 uses a dedicated background profile with max_temporary_non_const_columns=12 and no competing row or AST cap. The official targeted amd ASan/UBSan Praktika integration run passed 1/1 with no skips on the pinned binary, checking zero union dispatch for both temporary-column caps and positive dispatch on the unlimited control. The full five-node module then passed 29/29, without skips or sanitizer errors. A new same-profile, same-schema positive control passed 1/1 with union dispatch under the limit of 12; paired with the wide case's zero dispatch, this checks that the original actions fit and the wider replacement is rejected. The full-module run preceded that positive control; exact-head CI remains pending. These test-only changes have no new speed or peak-memory measurement.

On earlier private candidate binaries, paired 10-million-row/8192-key runs had median MutatePart times of 6391 ms with the feature off and 1066.5 ms with it on (5.99x); median tracked mutation-task peaks were both about 40.4 MB. Two accepted opposite-order 1-billion-row/1024-key pairs observed about 22.27x lower task time with the feature on, with task peaks of roughly 33–34 MB in both modes. One OFF task overlapped delayed part cleanup, so that pair is less isolated. An earlier private binary's 2.1-million-row/1,048,576-key calibration took 1268 ms OFF and 365 ms ON (3.47x), while its tracked task peak rose from 81.1 MB to 107.6 MB (+25.3 MiB). These are local workload results, not a general latency distribution or a measurement of the latest finite-limit guard; large RHS unions have a measurable memory cost. A resident Set configured to spill may be copied before its spill starts, so hard-limit headroom during that overlap remains unverified. The cancellation-poll change was checked separately on ASan/UBSan: its paired 10-million-row time ranges overlapped, with a 0.56% median difference and effectively identical task peaks. A lower-cap pair passed in both modes, but effective memory headroom differed, so failure and retry close to the hard limit remain unresolved.

A separate same-binary Release comparison isolated standalone action batching: typed Set union and singleton coalescing were both off, with one 64-command ALTER over each fresh 10-million-row Wide/Full AggregatingMergeTree part and 4,096 RHS keys. The balanced OFF/ON/ON/OFF x2 run passed 8/8 exact mask and aggregate oracles; every sample built 64 subquery Set values, kept one mutation ID, and dispatched action batching only when enabled. Median MutatePart time was 3805 ms OFF versus 3726 ms ON (2.08% lower); wall time 3.878 versus 3.825 s (1.37% lower); whole owned-server CPU 6.225 versus 6.110 s (1.85% lower); task peak memory 24,670,435 versus 24,670,499 bytes (effectively equal). All four ON task times were below all OFF task times, but the preregistered 10% task and wall criterion was not met, so a material standalone benefit is not established. The pinned Release binary (SHA-256 215f5d3e9ac301144c79a76e33eaea1a7bee84dd7a3481167027e552644909a6) predates only the current branch's Bool typed-union guard among changed C++ files; typed union was disabled in both arms. Cache was uncontrolled, there were four samples per arm, and the peak is task memory rather than RSS.

Related: #132056
Related: #132825

Changelog category (leave one):

  • Performance Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Add an optional, bounded union of compatible ready subquery Set objects for classic lightweight DELETE mutations on MergeTree-family tables, including AggregatingMergeTree, to reduce repeated membership checks while rewriting a part. The optimization is disabled by default.


Workflow [PR]
Sync PR [sync-upstream/pr/133454]

Issue: ClickHouse#132056

Repeated `_row_exists` updates on Wide/Full parts evaluate prepared
predicates separately, making large mutation batches CPU bound.

Preserve the original mutation commands, IDs, order, Set preparation,
and affected-row semantics while batching compatible actions. Unite
compatible literal or ready subquery integer Sets within fixed budgets.
Keep both new settings experimental and disabled by default; retain the
original actions when the union admission checks decline.

Verification: private Cloud build passed; 20 adjacent stateless tests
passed with the typed union both OFF and ON; the ready-subquery test
passed under ASan/UBSan. On a disposable SharedAggregatingMergeTree
10M-row fixture, two 4096-key OFF/ON pairs were 1.890x and 1.914x
faster with unchanged task-memory peaks; 4097 keys took the original
path. A 1B-row pair was 26.68x faster, with task peaks 31,802,223 B
OFF and 31,600,662 B ON. These are workload-specific measurements.

Remaining risk: official CI, managed multi-replica Cloud, and a
confirmed cross-part cached-Set overlap remain untested. The feature
does not enable any new behavior by default.
Repeated `_row_exists` mutations on large Wide/Full parts were CPU bound.
The batching change must continue to respect upstream per-stage `Set`
preparation, including when two stages reuse the same cached `Set`.

Resolve the `MutationsInterpreter` merge around the stage-local
`CreatingSets` gate, declare the upstream subquery index-limit setting,
and add a two-stage cached-`Set` regression test. The original mutation
commands, IDs, order, and fallback semantics remain intact.

Verification on pinned upstream b166891:
Release Clang 21.1.8 `ninja clickhouse` passed; eight focused stateless
tests passed; finite `max_rows_in_set=128` OFF/ON control kept both union
dispatch counts at zero with identical exact results. On a disposable
OSS 10M-row, 64-mutation, 4096-key fixture, paired task medians were
17,707 ms OFF vs 1,376.5 ms ON (12.86x); task memory peaks were
69,300,619 B OFF vs 54,541,600 B ON (21.3% lower).

Remaining risk: full CI, managed Shared/Cloud multi-replica validation,
adaptive-spill runtime, and sanitizer coverage on this new base remain
open. The benchmark has two samples per mode and does not measure RSS.

Issue: ClickHouse#132056
The positive row-mask test used one `Tuple` column, which selects the
hashed `Set` layout. The two-column fixed-width `keys256` union path
had no positive SQL test.

Add OFF/ON checks for the `keys256` path, both original mutation IDs,
and exact physical and visible aggregate results.

Verified: `bash -n`; official stateless runner 1/1 OK on the pinned
26.12.1.1 OSS build; independent test-log audit passed.
Remaining risk: Cloud multi-replica and CI runs are pending.

Related: ClickHouse#132056
Classic lightweight `DELETE` mutations on large `AggregatingMergeTree` parts
can retain many separate membership checks during one rewrite. The first
ready-subquery union path admitted only a narrow predicate shape and fixed
limits.

Extend the ordered row-mask batch to compatible scalar and tuple `Set`
groups, preserve each original stage's build gate and mutation ID, and
decline the optimization before the rewrite when a source is empty,
spilling, incompatible or over a user-configured row, key-byte or group
budget. Poll cancellation during large `Set` copies. Cover inserts between
deletes, changing RHS snapshots, select-source variants, limits, and memory
limit cleanup.

Verification: focused stateless and ASan/UBSan integration checks passed;
the new empty-RHS-between-stages case passed 1/1 and the focused `Code 241`
cleanup/retry test passed 1/1. A two-replica disposable Shared fixture
matched OFF/ON physical and visible results. Local benchmarks showed a
workload-specific speedup and a 25.3 MiB higher task peak at 1,048,576
RHS keys. Official CI, TSan, managed Cloud and a fresh-master build remain
open.

Related: ClickHouse#132056
@clickhouse-gh

clickhouse-gh Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [63a090c]

Summary: ❌

job_name test_name status info comment
Performance Comparison (amd_release, master_head, 3/8) FAIL Performance dashboard
avro_parallel_parsing #0 FAIL dashboard
avro_parallel_parsing #1 slower query history
hash_join_with_row_store #18 unstable query history
insert_statistics_countmin #1 unstable query history
linear_regression #3 unstable query history

AI Review

Summary

Adds optional, experimental batching and bounded union of compatible row-mask Set predicates for classic lightweight DELETE mutations. Request changes for the remaining spill-pressure validation gap. No new inline findings; the existing finding below still applies to head 63a090cf8d8f12f4cbe425080b2589d41d6a84e7.

Findings

⚠️ Majors

  • src/Interpreters/Set.cpp:456–461: Spill-capable resident sources remain eligible, but the destination created at line 522 cannot spill. Copying retains the original sets and holds a source shared lock; a concurrent spillAfterBuild can allocate its disk-set state before acquiring the exclusive lock needed to release that source table. The destination growth check bounds neither this overlap nor remaining query hard-limit headroom. This needs verification under actual spill pressure before admitting these sources. Keep spill-capable sources ineligible until validated, or provide the focused evidence below.
Tests
  • ⚠️ Exercise concurrent union copying and source spilling with the same effective hard memory limit in OFF/ON runs, positive union dispatch, exact physical masks and visible aggregate results, and cleanup/retry checks. ReadyUnionReleasesMemoryAfterLimitException proves allocation-failure cleanup; ReadyUnionCopiesSpillCapableSetUntilItSpills spills only after copying. Neither covers the overlap. No additional builds or tests were run during this review.
Final Verdict

Status: ⚠️ Request changes

Validate the union/spill overlap under matched hard-limit headroom, or exclude spill-capable sources from union admission.

LLVM Coverage Report

Measured on commit 63a090c.

Metric Baseline Current Δ
Lines 91.80% 91.80% +0.00%
Functions 92.20% 92.20% +0.00%
Branches 81.40% 81.50% +0.10%

Changed lines: Changed C/C++ lines covered: 1108/1257 (88.15%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-performance Pull request with some performance improvements comp-mutations ALTER UPDATE/DELETE and mutation execution over parts (including lightweight updates/deletes). labels Nov 21, 2026
@skuznetsov-clickhouse skuznetsov-clickhouse added can be tested Allows running workflows for external contributors ci-force-all Do not skip any jobs when running labels Nov 22, 2026
CI exposed that ready subquery `Set` union stayed disabled under finite
background limits, while several new tests depended on that path. The
original gate covered both eager literal and deferred subquery unions.

Keep the eager gate, then check the deferred union against row, byte and
temporary-column limits after the original `Set`s and actions are prepared.
Permit resident spill-capable `Set`s while holding their shared locks.
Track intermediate action allocations and fix the test tag and Keeper
path reported by CI.

Verification: ASan/UBSan build, the 05816 stateless case, two focused
`SetMemoryLimit` tests and five targeted integration cases passed on ch-vm.
Full CI and spill-overlap memory stress remain to be checked.

Related: ClickHouse#132056
Individually valid ready subquery `Set`s can produce a union that exceeds
finite background row or byte limits. The previous path copied all keys
before checking the resulting `Set`, so a tight memory limit could raise
an exception before the original mutation actions were used.

Pass the finite result limits into the union helper. Reject an excessive
source row sum before allocating the destination, and reject estimated
peak hash-table growth before copying keys. Keep the final exact checks.
The preflight may conservatively skip an overlapping union that fits.

Verification: x86_64 ASan/UBSan Release `clickhouse` and
`unit_tests_dbms` builds; focused `SetMemoryLimit` tests (2/2);
official `05816` with finite background limits (1/1); three targeted
integration cases for finite row, byte and temporary-column limits.
The 18 old Fast-test failures passed separately on the preceding build.

Remaining risk: the current diff still needs official CI, TSan, and a
hard-limit stress case for otherwise eligible spill-capable sources.

Related: ClickHouse#132056
The finite `Set` byte and temporary-column limits added to the shared
background profile caused the expanded-AST test to bypass the AST guard.
Restore its AST-only profile and give the finite-limit tests a separate
background fixture.

The four affected integration selectors passed on the ASan/UBSan build
(4/4); the focused `SetMemoryLimit` tests and `05816` also passed on that
build. New official CI and current-`master` integration remain open.

Related: ClickHouse#132056
The new `arm_tidy` report rejects two uninitialized `bool` variables in
`Set::tryUniteReadyFixedWidthSets`. Initialize both to `false`. The rebuilt
ASan/UBSan `clickhouse` and `unit_tests_dbms` targets passed, as did both
focused `SetMemoryLimit` tests.

The two-replica `05851` scenario took 15.53 s in Fast test against a 15 s
limit. Tag it `no-fasttest`; its local functional run and reference comparison
passed. The normal stateless CI run and a new exact-head CI pass remain open.

Related: ClickHouse#132056
PR: ClickHouse#133454
CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=133454&sha=b8f815d69fc4dd84f46fc5699d4632c87ecbf7b2&name_0=PR&name_1=Build%20%28arm_tidy%2C%203%2F4%29
CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=133454&sha=b8f815d69fc4dd84f46fc5699d4632c87ecbf7b2&name_0=PR&name_1=Fast%20test
@clickhouse-gh

clickhouse-gh Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 63a090cf8 with master edec5a61a (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

⚠️ Significant changes: object file sizes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes ⚠️

20 object files changed (+629.82 KiB total), 1 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Interpreters/MutationsInterpreter.cpp.o 1.07 MiB 1.48 MiB +416.39 KiB (+37.99%)
src/CMakeFiles/dbms.dir/Processors/QueryPlan/RowMaskActionsBatchStep.cpp.o new 162.07 KiB +162.07 KiB
src/CMakeFiles/dbms.dir/Interpreters/Set.cpp.o 781.02 KiB 816.02 KiB +35.01 KiB (+4.48%)

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

417 translation units recompiled, 3208 s compile time in total, 416 of them have a recent master baseline.

Symbol sizes
Binary Symbol Master PR Δ
programs/clickhouse ProfileEvents::global_counters_storage 14.69 MiB 14.75 MiB +64.00 KiB (+0.43%)

Job report

`05814` and `05815` intentionally combine `UPDATE`, `DROP COLUMN`, and
`UPDATE` in one `ALTER` to test a mutation barrier. `Replicated`
databases reject this mixed command before the mutation code runs
(Code 392), so the DBReplicated CI variant fails deterministically.

Tag only these two tests `no-replicated-database`. They keep testing
the single-query barrier in supported database variants; other
row-mask tests continue to run under DBReplicated.

Checked: `bash -n` for `05815`, `git diff --check`, and the runner's
`no-replicated-database` skip rule. Exact-head CI is pending.

CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=133454&sha=3209fc8cc96fb7bdc948aeba8427b6cbbbe43880&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20s3%20storage%2C%20DBReplicated%2C%20parallel%2C%201%2F2%29
PR: ClickHouse#133454
Comment thread src/Interpreters/Set.cpp Resolved
The `DBReplicated` stateless job rejects the mixed `UPDATE`, `DROP COLUMN`,
`UPDATE` in one `ALTER` in 05814/05815 (Code 392). The previous whole-test
tag also skipped their core batching assertions in Cloud and Shared Catalog.

Move only the mixed `ALTER` checks into 05854/05855 with
`no-replicated-database`. Keep the off/on results and `part_log` dispatch
checks in 05814/05815 for all database variants. Give the separated
`part_log` assertion its own table UUID and start-time window.

Verification: `bash -n` on both shell tests; three disposable `Atomic`
ASan/UBSan runs passed all four cases (12/12, no skips). The test binary
predates the `Set.cpp` bool initialization. Exact-head `DBReplicated` and
Cloud CI remain pending. The mixed `ALTER` checks ordered results, not a
same-task grouping barrier.

CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=133454&sha=3209fc8cc96fb7bdc948aeba8427b6cbbbe43880&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20s3%20storage%2C%20DBReplicated%2C%20parallel%2C%201%2F2%29
PR: ClickHouse#133454
The split core tests use plain `MergeTree`-family engines and the standard
Shared Catalog selector skips them. Add a `SharedAggregatingMergeTree` SQL
test tagged `shared-catalog` so that this suite checks the mutation results
with `enable_row_mask_typed_set_union` both off and on. The test covers
overlapping `IN (SELECT ...)` predicates and fresh inserts at deleted keys.

The private disposable Shared Catalog runner passed the exact test and
reference: 1 passed, 0 skipped. The focused `Atomic` ASan/UBSan runs of the
split cases passed 12/12; a `DBReplicated` preflight passed both core cases
and skipped only the incompatible mixed-command barrier cases. Those
ASan/UBSan runs used an earlier binary; the private Shared build is separate
from the current OSS head. Exact-head CI and Cloud validation remain open.

Related: ClickHouse#132056
Related: ClickHouse#133454
CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=133454&sha=3209fc8cc96fb7bdc948aeba8427b6cbbbe43880&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20s3%20storage%2C%20DBReplicated%2C%20parallel%2C%201%2F2%29
`IDataType::equals` treats `Bool` and `UInt8` as equal, but a ready
`Bool` `Set` converts `UInt8(2)` to true when `transform_null_in = 0`.
Copying its raw key into a `UInt8` union `Set` left that row undeleted.

Require the type name as well as equality before uniting keys, including
tuple elements. An incompatible union declines and retains the original
mutation actions. Add a stateless regression with physical row-mask and
dispatch checks for `Bool` and mixed `Bool`/`UInt8` subquery sets.

Tests: `05858` failed on the pre-fix ASan/UBSan binary and passed on the
patched binary (one fixed-settings and three randomized-settings runs);
`05839` passed on the patched binary and still dispatched valid unions.
Exact-head CI and managed Cloud validation remain pending.

Related: ClickHouse#132056
PR: ClickHouse#133454
Prior CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=133454&sha=3209fc8cc96fb7bdc948aeba8427b6cbbbe43880&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20s3%20storage%2C%20DBReplicated%2C%20parallel%2C%201%2F2%29
The Shared Catalog result oracle could pass without exercising typed `Set`
union. Assert the `MutatePart` counter for both feature modes across replicas,
scoped by table UUID. Run `SYSTEM FLUSH LOGS ON CLUSTER` separately so its
host-specific output does not enter the reference. Pin unrelated parallel
replica modes so randomized settings do not require a missing cluster.

Verification: official private two-replica `clickhouse-test --shared-catalog`
passed `05857` 1/1 with fixed settings and 1/1 with randomized settings.
The four parallel replica settings that caused the pre-fix fixture failure
were replayed explicitly: 1/1 passed, OFF union=0, ON union=1. The pinned
private binary differs from this OSS branch; exact-head CI is pending.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=133454&sha=3209fc8cc96fb7bdc948aeba8427b6cbbbe43880&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20s3%20storage%2C%20DBReplicated%2C%20parallel%2C%201%2F2%29
PR: ClickHouse#133454
The temporary-column integration case expected the non-constant limit to
reject a ready `Set` union, but its background profile also set
`max_rows_in_set=1`. The two source rows exceeded that limit before the
replacement actions could reach the column check. An existing alternative
profile also rejected the query at its AST limit.

Add a dedicated background profile with only
`max_temporary_non_const_columns=12`. Keep the total-column case and the
unlimited positive control in the same test.

Verification: the official targeted amd ASan/UBSan integration run passed
1/1 with no skips on the pinned binary. Source restoration and scoped Docker
cleanup passed. The full module and exact-head CI remain to be checked.

CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=133454&sha=3209fc8cc96fb7bdc948aeba8427b6cbbbe43880&name_0=PR
PR: ClickHouse#133454
The wide negative case could report zero union batches if the original-action
precheck rejected the mutation before the replacement-column check. Add a
same-profile, same-schema narrow positive control that dispatches one union
under `max_temporary_non_const_columns = 12`. Together with the existing
four-group zero-dispatch case, this distinguishes replacement width from
original-action rejection.

The official targeted amd ASan/UBSan integration run passed the new control
1/1 with no skips; the prior five-node module passed 29/29 on the same binary.
The exact new-head CI and managed Cloud validation remain pending.

Related: ClickHouse#133454
CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=133454&sha=3209fc8cc96fb7bdc948aeba8427b6cbbbe43880&name_0=PR
Comment thread src/Interpreters/Set.cpp
Comment on lines +456 to +461
const auto is_ready_in_memory = [](const Set & set)
{
/// The caller holds the shared lock. A spill can start concurrently, but it cannot replace
/// the table until the lock is released.
return set.isCreated() && !set.isTruncated() && set.data && !set.data->empty()
&& !set.disk_set && !set.spill_after_build_started.load();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Major] Validate spill-capable unions under hard memory pressure

This admits resident sources configured to spill, while the destination created below has no spill settings. The original actions retain the source sets, and copying holds a source shared lock while allocating and rehashing the destination. A concurrent after-build spill can therefore allocate its disk-set state before it can release the original table. The destination's max_result_bytes check does not account for this overlap or the remaining query hard-limit headroom.

ReadyUnionReleasesMemoryAfterLimitException checks cleanup after an expected allocation failure, and ReadyUnionCopiesSpillCapableSetUntilItSpills spills only after the copy completes. Neither validates the overlap. The PR description also says the lower-cap OFF/ON runs had different effective headroom.

Please add a focused overlap test or controlled same-build mutation run with a matched effective hard limit, positive union dispatch and actual spill pressure, checking exact masks/aggregate results and cleanup/retry. Alternatively, keep spill-capable sources ineligible until this path is validated.

`mutations_sync` can finish before `MutatePart` is visible in
`system.part_log`. The test's single flush could race with log publication.
Poll for both UUID-scoped rows with a 60-second deadline, then retain the
OFF/ON dispatch-counter checks.

Verification: `bash -n` and `git diff --check` passed. The official
private two-replica `clickhouse-test` passed 05857 twice (r29 and r30);
r30 also passed the guarded controller and cleanup checks.

Remaining risk: exact-head OSS CI has not completed.

Related: ClickHouse#132056
Mutation completion can precede publication of its MutatePart entry.
05837 asserted after one log flush, while 05853 reused the mutation
completion deadline for the log wait. Under load, either dispatch check
could observe no entry even after a successful mutation.

Poll the UUID-scoped entry for up to 60 seconds in 05837 and give the
05853 log wait its own 60 seconds. Keep the existing dispatch and result
assertions and references unchanged.

Verification: bash -n, git diff --check, and official clickhouse-test
05837 and 05853 (2/2) on x86_64 Release ASan/UBSan binary
089273428869471ec78c465768876c49eedc06ebb6551a49b884555d958b3495.
Exact PR-head CI remains pending.

Related: ClickHouse#132056

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors ci-force-all Do not skip any jobs when running comp-mutations ALTER UPDATE/DELETE and mutation execution over parts (including lightweight updates/deletes). pr-performance Pull request with some performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant