Repository navigation
Conversation
…ation seal Aggregator::sealPendingChunks coalesces staged mini-chunks by cloning its destination from the first source and then calling prepareForSquashing and insertRangeFrom, both of which assert_cast every source to the destination's class. That assumes all minis share one physical representation per aggregate argument position, and only ColumnConst was stripped. Lazy column replication is decided per block: HashJoinResult materializes the blocks whose replication does not grow the output and leaves the others wrapped in ColumnReplicated. The staging path preserves the wrapper (recursiveRemoveSparse keeps it and ColumnReplicated::index returns a ColumnReplicated), and the frozen kernel receives the raw block columns rather than the unwrapped copies prepareAggregateInstructions builds. So one stream legitimately mixes wrapped and dense columns at the same position and the cast aborts: Bad cast from type DB::ColumnReplicated to DB::ColumnString Received signal Aborted (6) Two sites abort, both reproduced: prepareForSquashing for String, Nullable, Array, Map, Tuple, Variant, Dynamic and Object, and insertRangeFrom for the numeric vectors, which do not override prepareForSquashing. Normalizing the whole sources vector including the front, before the destination is cloned, covers both and keeps destination and sources drawn from the same normalized set. The structureEquals gate leaves the homogeneous case allocation-free, so lazy replication keeps its benefit wherever it is uniform. This mirrors the treatment Squashing already applies to the identical hazard. In a release build assert_cast degrades to static_cast, so the same input reads a ColumnReplicated through a ColumnVector layout and copies from a bogus data pointer instead of failing loudly. Found by CI in Stress test (arm_msan) on an unrelated pull request. The aborting file was added to master by ClickHouse#111459 and is on no release branch, so no backport applies.
The test asserted only the aggregated values, and those are produced whether or not several staged batches are ever buffered together. sealPendingChunks publishes a lone batch through an earlier return, and a lone lazily replicated batch is unwrapped downstream, so a configuration that keeps the backlog at one batch never reaches the code this change fixes and the test passes on an unfixed build. Either external-aggregation threshold produces that configuration by draining the backlog as it grows, and the test runner randomizes both, so the test was green on a broken binary for a routinely drawn setting combination. Pin the settings the coalescing depends on, following the convention of the other tests in this family, and add an assertion that the coalescing actually ran: AdaptiveAggregationSealedChunks is incremented after the single-batch return, so a non-zero count means at least one seal saw two or more batches. The counter is read from query_log through a log_comment carried by the adaptive arms alone. Measured on the reverted source: with an external threshold forced, the test without these changes passes 6 of 6 while this version fails 5 of 11, every failure carrying a Bad cast signature. Reverting only the threshold pin turns the new assertion to zero and fails the test while all nine value lines still match, so the assertion is what closes the gap rather than the pins alone.
The test asserted that a multi-batch seal ran, which is necessary but not sufficient: the coalescing only normalizes when the buffered batches disagree at an argument position, and a wrapped first batch absorbs the mix on its own. On the unfixed server such a run produces correct values and a non-zero sealed-chunk count, so the test could pass while the code it covers was broken. Count the normalizations separately and assert that count per argument representation, so a normalized seal in one arm cannot vouch for another. Pin the table layout in the CREATE and the remaining join-shape settings. Lazy replication is decided per output block, and the reader's block size follows the table's granularity settings, which the test runner randomizes; leaving them open made a mixed batch a coin flip. With the layout pinned the unfixed server aborts on 10 of 10 runs, against 3 of 8 before. Co-Authored-By: Claude Opus 5 <[email protected]>
The test asserts ProfileEvents from its own query_log. With parallel replicas the partial aggregation runs on the replicas, and their counters never reach the initiator's query_log, so those assertions read zero on a correct server. The dedicated job takes its parallel replicas settings from the default profile, so a SET in the test body cannot turn them off. The tag both excludes the test from that job and forces the setting off everywhere else. Verified in both senses against a corrupted-tag control, since a malformed tags line is silently ignored. Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review (4 rounds, all findings resolved)This change went through four independent cold-review rounds, each paired with a second-model gate
Test validation, each measurement against a control: the test fails 8 of 8 on the unfixed binary, Session id: cron:clickhouse-review-slot-48:20260816-194000 |
|
Workflow [PR], commit [dc9795b] Summary: ✅
AI ReviewSummaryThis PR fixes Final Verdict
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 13/16 (81.25%) · Uncovered code |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20260816-185800 |
|
cc @nihalzp @Avogar, could you review this? |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units8 translation units recompiled, 14 s compile time in total, 8 of them have a recent master baseline. |
CI finish ledger - dc9795bCI is fully finished on this head and it is clean: 177 check-runs, 157 success / 20 skipped,
Those two CIDB rows are historical, not open. Both predate the label being applied; the same The regression test Session id: cron:our-pr-ci-monitor:20260817-020000 |
68f372e
…ree arms 04676_adaptive_aggregation_replicated_argument asserted AdaptiveAggregationSealNormalizations > 0 separately for each of its three argument representations. That counter is incremented in Aggregator::sealPendingChunks only when the batches one producer has buffered together disagree in physical representation at that argument position, which requires three things: at least two batches buffered in one producer, both representations reachable, and one producer holding blocks of both classes. The test pins the settings governing the second condition. The first depends on the staged payload size, since stageChunk publishes a batch as-is above a byte threshold and sealPendingChunks returns before either counter when only one mini chunk is buffered. The third is a read pool and thread scheduling outcome. So a non-zero count for a single query is not an engine guarantee, and the per-arm assertion asserted a property the engine does not promise. It failed on about 1.9% of the runs the test appeared in, 19 times across 19 unrelated pull requests in 14 days, always one line flipping 1 to 0. Randomization is not the cause. The failure reproduces with randomized settings disabled and with enable_lazy_columns_replication 0, the very setting the test pins, so there is nothing to clamp and a no-random-settings tag would hide the flake rather than address it. Summing the counter over the three arms states the property that does hold: the seal normalized somewhere in the query set. The three queries stay separate, so each keeps its own value comparison and its own abort site, and the aggregate sealed chunks assertion, the six value lines and the tags are unchanged. The same LIKE predicate the sealed chunks assertion already uses is reused, and the three log_comment values are kept so per-arm attribution remains available in query_log. What this gives up is the per-run guarantee that every representation exercised the normalization. Across CI runs each arm still does in about 99.4% of runs, and a binary without the normalization fix aborts on whichever position first sees heterogeneity. Validated locally on a debug build: the old form failed 2 of 300 runs in the same interleaved loop where the new form passed 300 of 300; of 600 runs 6 had an arm at zero and all 6 still had a non-zero total; with the normalization loop reverted the new form aborts 20 of 20 with Bad cast from type DB::ColumnReplicated to DB::ColumnVector in sealPendingChunks, so the regression oracle still detects the original defect. 50 runs with randomized settings and 50 without both pass. The test was added by ClickHouse#115034.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Aggregator::sealPendingChunkscoalesces several staged mini-chunks into one, concatenating eachaggregate argument column across the minis. It clones the destination from the first source and
then calls
prepareForSquashingandinsertRangeFrom, both of whichassert_castevery source tothe destination's class. That assumes all minis share one physical representation per position.
They do not. Lazy column replication is decided per block: a join materializes a block whose
replication does not grow the output and leaves the others wrapped in
ColumnReplicated(
HashJoinResult.cpp), so one stream legitimately mixes wrapped and dense blocks for the samecolumn.
recursiveRemoveSparsein the staging path deliberately preserves the wrapper, so the mixreaches the seal and the cast aborts:
Two sites abort, both reproduced locally:
insertRangeFromfor the numeric vectors, which do notoverride
prepareForSquashing(the signature above), andprepareForSquashingitself for String,Nullable, Array, Map, Tuple, Variant, Dynamic and Object. The fix normalizes the whole
sourcesvector, including the front, before the destination is cloned, so one gate covers both sites and
destination and sources stay drawn from the same normalized set. The
structureEqualsgate keepsthe homogeneous case allocation-free, so lazy replication keeps its benefit where it is uniform,
and mirrors what
Squashing.cppalready does for the identical hazard.Reachable from ordinary SQL: a
JOINfeeding aGROUP BYwithenable_adaptive_aggregator = 1and
enable_lazy_columns_replication = 1, both defaults. In a release buildassert_castdegradesto
static_cast, so the same input reads aColumnReplicatedthrough aColumnVectorlayout andcopies from a bogus data pointer instead of failing loudly.
AdaptiveAggregation.cppwas added by #111459 and is on no release branch, so no backport applies.Found by CI in
Stress test (arm_msan)on an unrelated pull request:report,
fatal.log.
Version info
26.8.1.1525(included in26.8and later)