Repository navigation
Fix LimitTransform WITH TIES assertion on empty virtual-row chunk - #105102
alexey-milovidov merged 10 commits into
Conversation
`LimitTransform::makeChunkWithPreviousRow` asserts `row < chunk.getNumRows()` and is called from `preparePair` with `data.current_chunk.getNumRows() - 1` whenever `with_ties && rows_read == offset + limit`. This silently assumes the current chunk has at least one row. The read-in-order pipeline violates that assumption. With settings `optimize_read_in_order = 1`, `read_in_order_use_virtual_row = 1` and `read_in_order_use_virtual_row_per_block = 1`, `VirtualRowTransform` emits zero-row chunks carrying `MergeTreeReadInfo` as sort-key markers for `MergingSortedTransform`. In the single-stream case there is no merging, so `RemoveVirtualRowTransform` is inserted to clean up — but it only stripped the `ChunkInfo` and left the empty chunk on the pipeline. When such a chunk arrived at `LimitTransform` after the previous data chunk had pushed `rows_read` to exactly `offset + limit`, the call became `makeChunkWithPreviousRow(empty_chunk, 0 - 1)` and the `UInt64` underflow tripped the assertion (server abort in debug builds; surfaces as a `LOGICAL_ERROR` in release builds). The AST fuzzer hit this on master across multiple unrelated PRs (ClickHouse#99495, ClickHouse#104268, ClickHouse#101158) over the past 30 days. Minimal reproducer: CREATE TABLE t (id UInt64, m Map(String, String), INDEX idx_mk mapKeys(m) TYPE bloom_filter GRANULARITY 1) ENGINE = MergeTree ORDER BY id SETTINGS index_granularity = 1; INSERT INTO t VALUES (1, {'1':'1'}); INSERT INTO t VALUES (2, {'2':'2'}); INSERT INTO t VALUES (3, {'3':'3'}); SELECT id FROM t PREWHERE mapContains(m, toFixedString('1', 1)) ORDER BY id ASC LIMIT 1 WITH TIES SETTINGS optimize_read_in_order = 1, read_in_order_use_virtual_row = 1, read_in_order_use_virtual_row_per_block = 1; Two fixes: 1. `LimitTransform.cpp`: skip the `makeChunkWithPreviousRow` call when the current chunk has zero rows. There is no row to remember and the `previous_row_chunk` saved from the prior non-empty chunk is still the correct tie key for the boundary. 2. `RemoveVirtualRowTransform` (`SortingStep.cpp`): actually consume the virtual-row chunk — `chunk.clear()` it and enable `skip_empty_chunks` on the base `ISimpleTransform` so it is not re-emitted. This matches the existing comment ("we need to remove virtual row before output") and protects other downstream transforms from receiving these pointless markers. Regression test `04247_99495_limit_with_ties_virtual_row_empty_chunk` aborts master in debug builds and passes after this change. CI report: https://s3.amazonaws.com/clickhouse-test-reports/PRs/99495/b699481fd40feb67d515e47725de159f20dd1ff0/ast_fuzzer_amd_debug/ Related: ClickHouse#99495 (sighting PR)
|
Pre-PR validation gate (TASK.md §Phase 4 Step 9): a) Deterministic repro? Yes. Three single-row inserts (separate parts) into a b) Root cause explained? Yes. c) Fix matches root cause? Yes, at two levels. d) Test intent preserved? / New tests added? New regression test e) Demonstrated in both directions? Yes. Pre-fix binary: server abort, stack trace matches CIDB ( f) Fix is general, not a narrow patch? Yes. The same anti-pattern (assuming a chunk has rows after Session: |
|
cc @KochetovNicolai @alexey-milovidov @vdimir — could you review? Two-part fix for the chronic AST fuzzer assertion in |
|
Workflow [PR], commit [28524b0] Summary: ✅
AI ReviewSummaryThis PR fixes the empty-chunk boundary for Missing context / blind spots
Final VerdictStatus: ✅ Approve |
|
This was fixed by #105146. Let's update the branch. |
CI ledger — covered SHA:
|
| Check | Test | Disposition |
|---|---|---|
Stateless tests (amd_tsan, parallel, 1/2) |
00175_obfuscator_schema_inference |
flaky chronic trunk — task 2026-06-02-ci-00175obfuscatorschemainference-ab |
Unit tests (asan_ubsan) |
(check-level) | infra/chronic UBSan UntrackedMemoryCounter — task 2026-06-03-ci-p1-chronic-ubsan-in-untrackedmemoryc |
Unit tests (asan_ubsan, function_prop_fuzzer) |
FunctionsStress.stress, AllTests |
infra/chronic, follows the asan_ubsan check-level fail above (same UntrackedMemoryCounter teardown). |
AST fuzzer (amd_debug) |
Logical error: Trying to get name of not a column: A (STID: 2310-3791) |
chronic trunk family bug — tracked in task 2026-05-30-ci-p0-ast-fuzzer-logical-error-trying-, our fix PR #106172 awaiting review. NOT PR-caused (this PR only touches LimitTransform.{cpp,h}). |
Bugfix validation (functional tests) |
04247_99495_limit_with_ties_virtual_row_empty_chunk |
this PR's OWN regression test — framework limitation: the LimitTransform assertion bug requires read_in_order_use_virtual_row_per_block randomization that isn't always exercised on master HEAD. Not a real regression. |
No PR-caused correctness failures. Awaiting human review.
Session: cron:our-pr-ci-monitor:20260604-213000
@groeneai you may set this setting explicit in the test. |
…sion test Per @vdimir on ClickHouse#105102 (comment): make the regression test deterministically reproduce the assertion on master HEAD so the Bugfix validation framework can confirm the fix. The query-level SETTINGS clause already pins `optimize_read_in_order`, `read_in_order_use_virtual_row`, and `read_in_order_use_virtual_row_per_block`. The remaining randomization that can mask the bug is at MergeTree level (e.g. `index_granularity_bytes`, `min_bytes_for_wide_part`) which can change part type / mark layout and cause the per-block virtual row chunk to never be emitted at the boundary the bug needs. Adding `no-random-merge-tree-settings` makes the data layout deterministic. Also trim the inline comments per the @azat directive that explanation context belongs in the commit message rather than in the code; the test name and the PR / commit message provide the reader with enough context. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
@ vdimir thanks — pushed The query-level Session: cron:clickhouse-ci-task-worker:20260605-194200 |
…n test The Bugfix validation framework needs the regression test to FAIL deterministically on master HEAD. The previous fix-up tagged the test with no-random-merge-tree-settings, but that did not pin the actual trigger and the assertion still slipped past randomization. Minimal trigger isolated locally: optimize_read_in_order=1, read_in_order_use_virtual_row=1, read_in_order_use_virtual_row_per_block=1, use_skip_indexes_on_data_read=0. With use_skip_indexes_on_data_read at the default of 1, the bloom filter index is consumed in a separate step and the empty virtual row chunk never reaches LimitTransform. With it at 0 the read goes through the data path that exposes the empty chunk and the assertion trips. Adds use_skip_indexes_on_data_read=0 to both query SETTINGS clauses and drops the broad no-random-merge-tree-settings tag, since the bug is independent of part type and other MergeTree randomization. Verified locally: piping the test SQL into a buggy clickhouse aborts on LimitTransform.cpp:60 with Logical error 'row < chunk.getNumRows()'. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (fix-up commit
|
| # | Question | Answer |
|---|---|---|
| a | Deterministic repro? | Yes. Piping the test SQL (with the new pinned use_skip_indexes_on_data_read = 0) into a debug clickhouse built from master HEAD without the LimitTransform fix aborts every time on LimitTransform.cpp:60 Logical error: 'row < chunk.getNumRows()'. Just the four pinned settings (optimize_read_in_order = 1, read_in_order_use_virtual_row = 1, read_in_order_use_virtual_row_per_block = 1, use_skip_indexes_on_data_read = 0) trigger it; no other randomization required. |
| b | Root cause explained? | Yes. With use_skip_indexes_on_data_read = 1 (default), the bloom filter is consumed in a separate index-only step and the data read pipeline never sees the empty virtual-row chunk that read_in_order_use_virtual_row_per_block = 1 emits. With use_skip_indexes_on_data_read = 0, the read goes through MergeTreeRangeReader on the data path; the RemoveVirtualRowTransform upstream in SortingStep only stripped ChunkInfo (didn't actually drop the zero-row chunk). After the previous data chunk pushed rows_read to exactly offset + limit, the empty chunk reached LimitTransform::preparePair, which called makeChunkWithPreviousRow(empty_chunk, getNumRows() - 1) — a UInt64 underflow that trips the assertion. |
| c | Fix matches root cause? | Yes. The PR fix has two parts: (1) LimitTransform.cpp adds && rows > 0 so makeChunkWithPreviousRow is only called when there is a row to remember; (2) SortingStep.cpp switches RemoveVirtualRowTransform's ISimpleTransform to skip_empty_chunks=true so the marker is consumed instead of forwarded. The test fix here only pins the runner randomization that exposes the broken pipeline shape, so Bugfix validation reproduces the bug deterministically against master HEAD. |
| d | Test intent preserved / new tests added? | Yes. The test still exercises the exact original bug: LIMIT 1 WITH TIES and LIMIT 0, 1 WITH TIES over a single-stream read_in_order_use_virtual_row_per_block = 1 pipeline, with mapContains PREWHERE on a bloom_filter skip index. Pinning use_skip_indexes_on_data_read = 0 does not weaken the assertion — it forces the failing pipeline shape that the AST fuzzer was hitting through randomization. The no-random-merge-tree-settings tag added in the previous fix-up is dropped: the bug is independent of compact-vs-wide parts and other MergeTree randomization, so the broad tag was not the right tool. |
| e | Both directions demonstrated? | Yes. Without the fix (debug clickhouse built from master HEAD): piping the test SQL aborts the server with Logical error: 'row < chunk.getNumRows()' at LimitTransform.cpp:60. With the fix (this PR): Bugfix validation reported the test passing in 0.21s on the prior commit (b7d6e3492a0c), and the LimitTransform path now safely skips the empty chunk. The fix-up only adds an extra SETTING to the regression test; the source-code fix and PR semantics are unchanged. |
| f | Fix is general, not a narrow patch? | Yes. The source-code fix already covers all read-in-order paths that can produce empty marker chunks: (1) LimitTransform guards makeChunkWithPreviousRow against zero-row chunks regardless of upstream — protects every WITH TIES consumer; (2) RemoveVirtualRowTransform enables skip_empty_chunks so all downstream transforms (MergingSortedTransform not in the path, LimitTransform, etc.) never see these markers. The test's pinned settings narrow the runner randomization just enough for Bugfix validation to deterministically reproduce; it is not a defensive symptom-only patch. |
Session id: cron:clickhouse-ci-task-worker:20260605-212000
|
@vdimir thanks — the previous fix-up's Minimal trigger isolated locally — the four pinned settings ( The |
|
@vdimir thanks. The four The remaining Two options:
Session: cron:clickhouse-ci-task-worker:20260605-225900 |
…rg::alter PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to declare last_version and compression_method outside an if/else that assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables flags the bare declarations and Build (arm_tidy) is built with -warnings-as-errors, so the build fails for every PR whose CI ran on master after this commit. CIDB shows 30+ unrelated PRs hitting this in the last 2 days (e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102, ClickHouse#106590). Initialize both variables to safe defaults at declaration. They are unconditionally overwritten in both if and else branches before use, so behavior is unchanged. The new defaults are only relevant if a future code path skips both assignments, in which case last_version=0 and compression_method=CompressionMethod::None are sane no-op values (the same defaults the old structured-binding form would produce through default-construction of the destructured aggregate). Co-Authored-By: Claude Opus 4.8 <[email protected]> (cherry picked from commit d72cac5)
…rg::alter PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to declare last_version and compression_method outside an if/else that assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables flags the bare declarations and Build (arm_tidy) is built with -warnings-as-errors, so the build fails for every PR whose CI ran on master after this commit. CIDB shows 30+ unrelated PRs hitting this in the last 2 days (e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102, ClickHouse#106590). Initialize both variables to safe defaults at declaration. They are unconditionally overwritten in both if and else branches before use, so behavior is unchanged. The new defaults are only relevant if a future code path skips both assignments, in which case last_version=0 and compression_method=CompressionMethod::None are sane no-op values (the same defaults the old structured-binding form would produce through default-construction of the destructured aggregate). Co-Authored-By: Claude Opus 4.8 <[email protected]> (cherry picked from commit d72cac5)
…rg::alter PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to declare last_version and compression_method outside an if/else that assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables flags the bare declarations and Build (arm_tidy) is built with -warnings-as-errors, so the build fails for every PR whose CI ran on master after this commit. CIDB shows 30+ unrelated PRs hitting this in the last 2 days (e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102, ClickHouse#106590). Initialize both variables to safe defaults at declaration. They are unconditionally overwritten in both if and else branches before use, so behavior is unchanged. The new defaults are only relevant if a future code path skips both assignments, in which case last_version=0 and compression_method=CompressionMethod::None are sane no-op values (the same defaults the old structured-binding form would produce through default-construction of the destructured aggregate). Co-Authored-By: Claude Opus 4.8 <[email protected]> (cherry picked from commit d72cac5)
…rg::alter PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to declare last_version and compression_method outside an if/else that assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables flags the bare declarations and Build (arm_tidy) is built with -warnings-as-errors, so the build fails for every PR whose CI ran on master after this commit. CIDB shows 30+ unrelated PRs hitting this in the last 2 days (e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102, ClickHouse#106590). Initialize both variables to safe defaults at declaration. They are unconditionally overwritten in both if and else branches before use, so behavior is unchanged. The new defaults are only relevant if a future code path skips both assignments, in which case last_version=0 and compression_method=CompressionMethod::None are sane no-op values (the same defaults the old structured-binding form would produce through default-construction of the destructured aggregate). Co-Authored-By: Claude Opus 4.8 <[email protected]> (cherry picked from commit d72cac5)
…rg::alter PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to declare last_version and compression_method outside an if/else that assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables flags the bare declarations and Build (arm_tidy) is built with -warnings-as-errors, so the build fails for every PR whose CI ran on master after this commit. CIDB shows 30+ unrelated PRs hitting this in the last 2 days (e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102, ClickHouse#106590). Initialize both variables to safe defaults at declaration. They are unconditionally overwritten in both if and else branches before use, so behavior is unchanged. The new defaults are only relevant if a future code path skips both assignments, in which case last_version=0 and compression_method=CompressionMethod::None are sane no-op values (the same defaults the old structured-binding form would produce through default-construction of the destructured aggregate). Co-Authored-By: Claude Opus 4.8 <[email protected]> (cherry picked from commit d72cac5)
…rg::alter PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to declare last_version and compression_method outside an if/else that assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables flags the bare declarations and Build (arm_tidy) is built with -warnings-as-errors, so the build fails for every PR whose CI ran on master after this commit. CIDB shows 30+ unrelated PRs hitting this in the last 2 days (e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102, ClickHouse#106590). Initialize both variables to safe defaults at declaration. They are unconditionally overwritten in both if and else branches before use, so behavior is unchanged. The new defaults are only relevant if a future code path skips both assignments, in which case last_version=0 and compression_method=CompressionMethod::None are sane no-op values (the same defaults the old structured-binding form would produce through default-construction of the destructured aggregate). Co-Authored-By: Claude Opus 4.8 <[email protected]> (cherry picked from commit d72cac5)
…rg::alter PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to declare last_version and compression_method outside an if/else that assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables flags the bare declarations and Build (arm_tidy) is built with -warnings-as-errors, so the build fails for every PR whose CI ran on master after this commit. CIDB shows 30+ unrelated PRs hitting this in the last 2 days (e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102, ClickHouse#106590). Initialize both variables to safe defaults at declaration. They are unconditionally overwritten in both if and else branches before use, so behavior is unchanged. The new defaults are only relevant if a future code path skips both assignments, in which case last_version=0 and compression_method=CompressionMethod::None are sane no-op values (the same defaults the old structured-binding form would produce through default-construction of the destructured aggregate). Co-Authored-By: Claude Opus 4.8 <[email protected]> (cherry picked from commit d72cac5)
…rg::alter PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to declare last_version and compression_method outside an if/else that assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables flags the bare declarations and Build (arm_tidy) is built with -warnings-as-errors, so the build fails for every PR whose CI ran on master after this commit. CIDB shows 30+ unrelated PRs hitting this in the last 2 days (e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102, ClickHouse#106590). Initialize both variables to safe defaults at declaration. They are unconditionally overwritten in both if and else branches before use, so behavior is unchanged. The new defaults are only relevant if a future code path skips both assignments, in which case last_version=0 and compression_method=CompressionMethod::None are sane no-op values (the same defaults the old structured-binding form would produce through default-construction of the destructured aggregate). Co-Authored-By: Claude Opus 4.8 <[email protected]> (cherry picked from commit d72cac5)
…rg::alter PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to declare last_version and compression_method outside an if/else that assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables flags the bare declarations and Build (arm_tidy) is built with -warnings-as-errors, so the build fails for every PR whose CI ran on master after this commit. CIDB shows 30+ unrelated PRs hitting this in the last 2 days (e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102, ClickHouse#106590). Initialize both variables to safe defaults at declaration. They are unconditionally overwritten in both if and else branches before use, so behavior is unchanged. The new defaults are only relevant if a future code path skips both assignments, in which case last_version=0 and compression_method=CompressionMethod::None are sane no-op values (the same defaults the old structured-binding form would produce through default-construction of the destructured aggregate). Co-Authored-By: Claude Opus 4.8 <[email protected]> (cherry picked from commit d72cac5)
…rg::alter PR #106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to declare last_version and compression_method outside an if/else that assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables flags the bare declarations and Build (arm_tidy) is built with -warnings-as-errors, so the build fails for every PR whose CI ran on master after this commit. CIDB shows 30+ unrelated PRs hitting this in the last 2 days (e.g. #89360, #103540, #106120, #106386, #106404, #106522, #105102, #106590). Initialize both variables to safe defaults at declaration. They are unconditionally overwritten in both if and else branches before use, so behavior is unchanged. The new defaults are only relevant if a future code path skips both assignments, in which case last_version=0 and compression_method=CompressionMethod::None are sane no-op values (the same defaults the old structured-binding form would produce through default-construction of the destructured aggregate). Co-Authored-By: Claude Opus 4.8 <[email protected]> (cherry picked from commit d72cac5)
…rg::alter PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to declare last_version and compression_method outside an if/else that assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables flags the bare declarations and Build (arm_tidy) is built with -warnings-as-errors, so the build fails for every PR whose CI ran on master after this commit. CIDB shows 30+ unrelated PRs hitting this in the last 2 days (e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102, ClickHouse#106590). Initialize both variables to safe defaults at declaration. They are unconditionally overwritten in both if and else branches before use, so behavior is unchanged. The new defaults are only relevant if a future code path skips both assignments, in which case last_version=0 and compression_method=CompressionMethod::None are sane no-op values (the same defaults the old structured-binding form would produce through default-construction of the destructured aggregate). Co-Authored-By: Claude Opus 4.8 <[email protected]> (cherry picked from commit d72cac5)
|
Hi @vdimir, gentle ping on the framework-limitation question. The chassert at LimitTransform.cpp:60 is a release no-op, so Bugfix-validation (which uses release master HEAD) cannot reproduce the assertion regardless of test-level pinning. Two options: (1) land this PR despite the gap, or (2) replace the chassert with an exception throw so the misbehavior is observable in release too. Happy to follow either path. Thanks. |
| chunk.clear(); | ||
| return; | ||
| } | ||
| chunk.getChunkInfos().extract<MergeTreeReadInfo>(); |
There was a problem hiding this comment.
Why extract<MergeTreeReadInfo> below doesn't do the same?
There was a problem hiding this comment.
Because the two branches handle different chunks.
isVirtualRow is true only for the index-boundary marker: a 0-row chunk whose payload is the non-empty pk_block in MergeTreeReadInfo (MergeTreeSelectProcessor::buildVirtualRowFromIndex). It carries no result rows, so we drop it entirely.
The extract line handles real data chunks. Those also carry a MergeTreeReadInfo, but only to convey origin_merge_tree_part_level (empty pk_block, so isVirtualRow is false), and they hold actual rows we must forward. We only strip the now-irrelevant ChunkInfo and keep the chunk. Clearing it there would discard query results.
One subtlety: extract alone cannot drop the marker. The virtual-row chunk has placeholder columns (0 rows), so after extracting the ChunkInfo it still reports hasColumns() and is not empty(), hence skip_empty_chunks would not suppress it. That is why the virtual-row branch needs the explicit chunk.clear(), which drops the columns too.
| public: | ||
| explicit RemoveVirtualRowTransform(SharedHeader header) | ||
| : ISimpleTransform(header, header, false) | ||
| : ISimpleTransform(header, header, /*skip_empty_chunks=*/ true) |
There was a problem hiding this comment.
The flag flip is what makes the clear() above effective. With skip_empty_chunks=false, ISimpleTransform::work() forces has_output=true for the cleared chunk and then rebuilds it into a 0-row chunk carrying the header columns (ISimpleTransform.cpp, the output_data.chunk = Chunk(header.cloneEmpty()...) branch). That rebuilt empty chunk is exactly what reaches LimitTransform and trips the WITH TIES assertion. With skip_empty_chunks=true, a chunk we cleared (now empty()) is suppressed and never forwarded. Real data chunks are non-empty, so the flag does not change their handling.
Strategic note, your call: the LimitTransform guard (rows > 0) alone already prevents the crash. This SortingStep change is the root-cause half: it makes RemoveVirtualRowTransform actually honor its documented contract ("remove virtual row before output"), which today only strips the MergeTreeReadInfo and leaks the empty husk downstream. If you prefer to keep the fix minimal and rely solely on the LimitTransform guard, I can drop this part. Which direction do you prefer?
…limit-with-ties-empty-chunk
|
CI summary on HEAD
No PR-caused failures. Ready for review. |
The AST fuzzer hit the same 'row < chunk.getNumRows()' assertion in LimitTransform::makeChunkWithPreviousRow via a second, independent path: a WITH FILL query (here STALENESS -1 on a DESC sort) emits a zero-row chunk that reaches LimitTransform at the WITH TIES boundary. There is no table and no read-in-order / virtual-row pipeline involved, so the SortingStep RemoveVirtualRowTransform change does not apply here; only the LimitTransform 'rows > 0' guard protects this case. Covering it in the same test guards both empty-chunk sources. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
The AST fuzzer hit this exact assertion again on 2026-06-15 (STID 2508-3b8e, PR #103322's SELECT DISTINCT a AS b, '[a-z]', 100 AS a ORDER BY 1 DESC NULLS FIRST WITH FILL STALENESS -1 LIMIT 1 WITH TIES;
The bug is still live on current master: a Debug build of This new case is also a cleaner regression test for the Pre-PR validation gate (test-only commit
|
| # | Question | Answer |
|---|---|---|
| a | Deterministic repro? | Yes. clickhouse local -q "SELECT DISTINCT a AS b, '[a-z]', 100 AS a ORDER BY 1 DESC NULLS FIRST WITH FILL STALENESS -1 LIMIT 1 WITH TIES" aborts every time on an unguarded build. |
| b | Root cause explained? | WITH FILL (here STALENESS -1 on a DESC sort) emits a zero-row chunk; at the WITH TIES boundary LimitTransform calls makeChunkWithPreviousRow(chunk, getNumRows() - 1), and getNumRows()==0 makes row underflow to UINT64_MAX, tripping row < chunk.getNumRows(). |
| c | Fix matches root cause? | N/A for this commit (test-only). The covering fix is the existing rows > 0 guard at LimitTransform.cpp. |
| d | Test intent preserved / new test added? | Test strengthened: adds a second, independent empty-chunk source (FillingTransform) to the existing file; the original virtual-row queries are unchanged. |
| e | Demonstrated in both directions? | Yes. Unguarded build of this branch (guard reverted) aborts with makeChunkWithPreviousRow (LimitTransform.cpp:60) <- preparePair (:249) <- prepare (:108), matching STID 2508-3b8e; guard restored returns 100 [a-z] 100. Master snapshot b5fa90e2908 also aborts. 20/20 runner-diff passes with the fix. |
| f | Fix is general, not a narrow patch? | Yes. The rows > 0 guard makes LimitTransform robust to empty chunks from any upstream; this commit demonstrates a second source beyond the virtual-row path. |
Session: cron:clickhouse-worker-slot-2:20260615-232700
Mirror the LimitTransform `rows > 0` empty-chunk guard into the sibling FractionalLimitTransform. Both its early-push path (prepare) and final-push path (pushData) called makeChunkWithPreviousRow(chunk, chunk_rows - 1) when WITH TIES reached the boundary (rows_processed == offset_rows + limit_rows) without checking chunk_rows > 0. A zero-row chunk (e.g. a trailing WITH FILL chunk) at that boundary makes chunk_rows - 1 underflow to UINT64_MAX, which fails the chassert(row < chunk.getNumRows()) in makeChunkWithPreviousRow. The stored ties_last_row is still the correct tie key at the boundary, so an empty chunk carries no row to remember and is simply skipped. The splitChunk path is already guarded by a non-zero cut_length, matching LimitTransform. Deterministic reproducer (aborts before the fix, returns the expected row after it): SELECT DISTINCT a AS b, '[a-z]', 100 AS a ORDER BY 1 DESC NULLS FIRST WITH FILL STALENESS -1 LIMIT 0.5 WITH TIES; Found by the clickhouse-gh review bot applying the symmetric-path rule to the LimitTransform fix in this PR. Adds a fractional LIMIT ... WITH TIES case to the regression test. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gateFor the FractionalLimitTransform fix-up (cbfa201):
Session id: cron:clickhouse-worker-slot-2:20260616-005900 |
|
CI finished on cbfa201. No PR-caused failures; the Bugfix validation check is green on this head.
The regression test passes across all Stateless variants. |
|
CI fully finished on HEAD
The new regression test |
…limit-with-ties-empty-chunk
After merging master, the number 04247 now collides with 04247_attach_table_storage_clauses_without_engine_error. Renumber the LimitTransform WITH TIES regression test to a free number.
|
Refreshed the branch onto current One thing the merge required: the regression test number Fresh CI is running on |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 14/14 (100.00%) | Lost baseline coverage: none · Uncovered code |
CI finish ledger — 28524b0CI fully finished (Finish Workflow + Mergeable Check: success) on the branch after it was refreshed onto current master. This PR fixes the chronic AST-fuzzer
No test-level FAIL/ERROR rows in CIDB for this commit; the only red GitHub check is the private Cloud sync. Session id: cron:our-pr-ci-monitor:20260630-173000 |
|
Our aarch64 AST-fuzzer-oracle harness (PR #99980) hit this same assertion on the Snapshot SELECT flag_b, flag_b, flag_a FROM local_dup_mixed ORDER BY dt DESC LIMIT 1 WITH TIESThe duplicate-projected-column ( For lineage: same assertion signature as closed #11372 (2020, different offset-overflow trigger). |
…rg::alter PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to declare last_version and compression_method outside an if/else that assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables flags the bare declarations and Build (arm_tidy) is built with -warnings-as-errors, so the build fails for every PR whose CI ran on master after this commit. CIDB shows 30+ unrelated PRs hitting this in the last 2 days (e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102, ClickHouse#106590). Initialize both variables to safe defaults at declaration. They are unconditionally overwritten in both if and else branches before use, so behavior is unchanged. The new defaults are only relevant if a future code path skips both assignments, in which case last_version=0 and compression_method=CompressionMethod::None are sane no-op values (the same defaults the old structured-binding form would produce through default-construction of the destructured aggregate). Co-Authored-By: Claude Opus 4.8 <[email protected]> (cherry picked from commit d72cac5)
…rg::alter PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to declare last_version and compression_method outside an if/else that assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables flags the bare declarations and Build (arm_tidy) is built with -warnings-as-errors, so the build fails for every PR whose CI ran on master after this commit. CIDB shows 30+ unrelated PRs hitting this in the last 2 days (e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102, ClickHouse#106590). Initialize both variables to safe defaults at declaration. They are unconditionally overwritten in both if and else branches before use, so behavior is unchanged. The new defaults are only relevant if a future code path skips both assignments, in which case last_version=0 and compression_method=CompressionMethod::None are sane no-op values (the same defaults the old structured-binding form would produce through default-construction of the destructured aggregate). Co-Authored-By: Claude Opus 4.8 <[email protected]> (cherry picked from commit d72cac5)
…rg::alter PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to declare last_version and compression_method outside an if/else that assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables flags the bare declarations and Build (arm_tidy) is built with -warnings-as-errors, so the build fails for every PR whose CI ran on master after this commit. CIDB shows 30+ unrelated PRs hitting this in the last 2 days (e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102, ClickHouse#106590). Initialize both variables to safe defaults at declaration. They are unconditionally overwritten in both if and else branches before use, so behavior is unchanged. The new defaults are only relevant if a future code path skips both assignments, in which case last_version=0 and compression_method=CompressionMethod::None are sane no-op values (the same defaults the old structured-binding form would produce through default-construction of the destructured aggregate). Co-Authored-By: Claude Opus 4.8 <[email protected]> (cherry picked from commit d72cac5)
…sion test Per @vdimir on ClickHouse#105102 (comment): make the regression test deterministically reproduce the assertion on master HEAD so the Bugfix validation framework can confirm the fix. The query-level SETTINGS clause already pins `optimize_read_in_order`, `read_in_order_use_virtual_row`, and `read_in_order_use_virtual_row_per_block`. The remaining randomization that can mask the bug is at MergeTree level (e.g. `index_granularity_bytes`, `min_bytes_for_wide_part`) which can change part type / mark layout and cause the per-block virtual row chunk to never be emitted at the boundary the bug needs. Adding `no-random-merge-tree-settings` makes the data layout deterministic. Also trim the inline comments per the @azat directive that explanation context belongs in the commit message rather than in the code; the test name and the PR / commit message provide the reader with enough context. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…-limit-with-ties-empty-chunk Fix LimitTransform WITH TIES assertion on empty virtual-row chunk
Description
Chronic AST fuzzer assertion
Assertion 'row < chunk.getNumRows()' failedinLimitTransform::makeChunkWithPreviousRow(src/Processors/LimitTransform.cpp:60), triggered byLIMIT ... WITH TIESqueries when the read-in-order pipeline emits a per-block virtual-row marker that reachesLimitTransformafterrows_readalready hit the limit boundary. The marker chunk has zero rows, sogetNumRows() - 1underflows toUINT64_MAXand trips the assertion (server abort in debug builds; surfaces as aLOGICAL_ERRORin release builds). The AST fuzzer has hit this on master across multiple unrelated PRs (#99495, #104268, #101158) over the past 60 days.Root cause
With
optimize_read_in_order = 1,read_in_order_use_virtual_row = 1andread_in_order_use_virtual_row_per_block = 1,VirtualRowTransformdeliberately produces zero-row chunks carryingMergeTreeReadInfo. They are intended as sort-key markers forMergingSortedTransform. In the single-stream case there is no merging, andRemoveVirtualRowTransformis inserted to clean them up — but itstransformonly stripped theChunkInfoand left the empty chunk on the pipeline. When such an empty chunk arrived atLimitTransformafter a previous data chunk had pushedrows_readto exactlyoffset + limit, thewith_ties && rows_read == offset + limitbranch calledmakeChunkWithPreviousRow(empty_chunk, 0 - 1)and the underflow triggered the assertion.Deterministic reproducer (pre-fix)
Fix
Two small, focused changes:
src/Processors/LimitTransform.cpp— defensive guard. Skip themakeChunkWithPreviousRowcall when the current chunk has zero rows. There is no row to remember and theprevious_row_chunksaved from the prior non-empty chunk is still the correct tie key at the boundary.src/Processors/QueryPlan/SortingStep.cpp— makeRemoveVirtualRowTransformactually consume virtual rows:chunk.clear()them and enableskip_empty_chunkson theISimpleTransformbase so they are not re-emitted. This matches the existing comment ("we need to remove virtual row before output") and protects other downstream transforms from receiving these pointless markers.The two fixes are complementary:
LimitTransformbecomes robust against any source of empty chunks, andRemoveVirtualRowTransformno longer leaks zero-row markers downstream.Regression test
tests/queries/0_stateless/04247_99495_limit_with_ties_virtual_row_empty_chunk.{sql,reference}aborts master in debug builds and passes after this change. Verified locally 10x; existing virtual-row andWITH TIEStests all still pass.Related
GradualResizeProcessorto limit effective parallelism for GROUP BY on small data volumes #99495FractionalLimitTransformmanifestation of the same empty-chunk boundary (fractionalLIMIT ... WITH TIES): Closes Logical error: 'row < chunk.getNumRows()' (STID: 2508-4656) #109948 (STID 2508-4656). Its guards are already included here.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a
LOGICAL_ERRORAssertion 'row < chunk.getNumRows()' failedinLimitTransform::makeChunkWithPreviousRowwhenLIMIT ... WITH TIESqueries run with the read-in-order pipeline (optimize_read_in_order = 1andread_in_order_use_virtual_row_per_block = 1). The exception was raised byLimitTransformwhen a per-block virtual-row marker (a zero-row chunk produced byVirtualRowTransform) reached it afterrows_readhad already hit the limit boundary.Documentation entry for user-facing changes
Version info
26.7.1.831(included in26.7and later)