Skip to content

Fix LimitTransform WITH TIES assertion on empty virtual-row chunk - #105102

Merged
alexey-milovidov merged 10 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-99495-limit-with-ties-empty-chunk
Jul 12, 2026
Merged

alexey-milovidov merged 10 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-99495-limit-with-ties-empty-chunk

Conversation

@groeneai

@groeneai groeneai commented May 16, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Chronic AST fuzzer assertion Assertion 'row < chunk.getNumRows()' failed in LimitTransform::makeChunkWithPreviousRow (src/Processors/LimitTransform.cpp:60), triggered by LIMIT ... WITH TIES queries when the read-in-order pipeline emits a per-block virtual-row marker that reaches LimitTransform after rows_read already hit the limit boundary. The marker chunk has zero rows, so getNumRows() - 1 underflows to UINT64_MAX and trips the assertion (server abort in debug builds; surfaces as a LOGICAL_ERROR in 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 = 1 and read_in_order_use_virtual_row_per_block = 1, VirtualRowTransform deliberately produces zero-row chunks carrying MergeTreeReadInfo. They are intended as sort-key markers for MergingSortedTransform. In the single-stream case there is no merging, and RemoveVirtualRowTransform is inserted to clean them up — but its transform only stripped the ChunkInfo and left the empty chunk on the pipeline. When such an empty chunk arrived at LimitTransform after a previous data chunk had pushed rows_read to exactly offset + limit, the with_ties && rows_read == offset + limit branch called makeChunkWithPreviousRow(empty_chunk, 0 - 1) and the underflow triggered the assertion.

Deterministic reproducer (pre-fix)

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;

Fix

Two small, focused changes:

  1. src/Processors/LimitTransform.cpp — defensive guard. 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 at the boundary.

  2. src/Processors/QueryPlan/SortingStep.cpp — make RemoveVirtualRowTransform actually consume virtual rows: chunk.clear() them and enable skip_empty_chunks on the ISimpleTransform base 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: LimitTransform becomes robust against any source of empty chunks, and RemoveVirtualRowTransform no 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 and WITH TIES tests all still pass.

Related

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fix a LOGICAL_ERROR Assertion 'row < chunk.getNumRows()' failed in LimitTransform::makeChunkWithPreviousRow when LIMIT ... WITH TIES queries run with the read-in-order pipeline (optimize_read_in_order = 1 and read_in_order_use_virtual_row_per_block = 1). The exception was raised by LimitTransform when a per-block virtual-row marker (a zero-row chunk produced by VirtualRowTransform) reached it after rows_read had already hit the limit boundary.

Documentation entry for user-facing changes

  • Documentation is unchanged: this fix does not change observable behavior except removing the exception.

Version info

  • Merged into: 26.7.1.831 (included in 26.7 and later)

`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)
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate (TASK.md §Phase 4 Step 9):

a) Deterministic repro? Yes. Three single-row inserts (separate parts) into a MergeTree with bloom_filter skip index on mapKeys(m) and index_granularity = 1, plus the three settings optimize_read_in_order = 1, read_in_order_use_virtual_row = 1, read_in_order_use_virtual_row_per_block = 1. The query SELECT id FROM t PREWHERE mapContains(m, toFixedString('1', 1)) ORDER BY id ASC LIMIT 1 WITH TIES aborts the server every time on master (the first execution may complete before the abort lands in the client; the second hits before the result is returned).

b) Root cause explained? Yes. VirtualRowTransform produces a zero-row chunk carrying MergeTreeReadInfo as a sort-key marker for MergingSortedTransform. In the single-stream case there is no merging, and RemoveVirtualRowTransform is inserted to clean these up — but its transform only stripped the ChunkInfo and forwarded the empty chunk. When such a chunk reached LimitTransform after the previous data chunk had pushed rows_read to offset + limit, the with_ties && rows_read == offset + limit branch called makeChunkWithPreviousRow(empty_chunk, 0 - 1). The UInt64 underflow trips assert(row < chunk.getNumRows()) (src/Processors/LimitTransform.cpp:60).

c) Fix matches root cause? Yes, at two levels. LimitTransform now skips the makeChunkWithPreviousRow call when the current chunk has zero rows (the previously stored previous_row_chunk is still the correct tie key at the boundary). RemoveVirtualRowTransform now actually consumes the virtual-row chunk (chunk.clear() + skip_empty_chunks = true on the ISimpleTransform base), matching the existing comment "we need to remove virtual row before output". The two are complementary: LimitTransform is robust against any source of empty chunks, and RemoveVirtualRowTransform no longer leaks markers.

d) Test intent preserved? / New tests added? New regression test 04247_99495_limit_with_ties_virtual_row_empty_chunk.{sql,reference} reproduces the assertion on master (debug build aborts) and passes after this change. Two queries (LIMIT 1 WITH TIES, and LIMIT 0,1 WITH TIES at the offset boundary).

e) Demonstrated in both directions? Yes. Pre-fix binary: server abort, stack trace matches CIDB (LimitTransform.cpp:60 → LimitTransform.cpp:246). Post-fix binary: both queries return 1, 10/10 stable runs. The other call site at LimitTransform.cpp:343 was reviewed and is safe — the surrounding && length guard ensures current_row_num >= 1 before the underflow-prone subtraction.

f) Fix is general, not a narrow patch? Yes. The same anti-pattern (assuming a chunk has rows after rows_read jumps) does not exist elsewhere in LimitTransform. The sibling splitChunk path at line 343 is already protected by && length. The RemoveVirtualRowTransform change covers all downstream transforms in the single-stream read-in-order pipeline, not just LimitTransform. Existing virtual-row tests (04201_read_in_order_limit_with_filter, 04076_virtual_row_preliminary_merge, 04057_virtual_row_many_parts, 04049_virtual_row_overlap, 04029_read_in_order_expression_virtual_row, 04045_reverse_order_virtual_row, 03581_read_in_order_use_virtual_row_WHERE) all still pass locally, and existing WITH TIES tests (00996_limit_with_ties, 01525_select_with_offset_fetch_clause, 03704_fractional_limit_with_ties, 03725_empty_tuple_some_limit_with_ties_distinct, 03753_fractional_limit_with_ties_small_blocks) all still pass locally.

Session: cron:clickhouse-ci-task-worker:20260516-020000

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @KochetovNicolai @alexey-milovidov @vdimir — could you review? Two-part fix for the chronic AST fuzzer assertion in LimitTransform::makeChunkWithPreviousRow (per @alexey-milovidov's note on #99495): LimitTransform now guards against empty incoming chunks, and RemoveVirtualRowTransform actually drops the zero-row virtual-row markers it was meant to consume (the existing implementation only stripped the ChunkInfo).

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label May 16, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [28524b0]

Summary: ✅


AI Review

Summary

This PR fixes the empty-chunk boundary for LIMIT ... WITH TIES by guarding LimitTransform and the sibling FractionalLimitTransform before saving the last row, and by making RemoveVirtualRowTransform actually consume single-stream virtual-row markers. I found no unresolved correctness findings in the current code: the earlier bot finding about FractionalLimitTransform has been addressed, and the regression test now covers both the read-in-order virtual-row source and the independent WITH FILL empty-chunk source.

Missing context / blind spots
  • ⚠️ I could not run the new stateless test locally because this checkout has no local clickhouse binary or build directory. A local run of 04419_99495_limit_with_ties_virtual_row_empty_chunk or completed CI on 28524b0a461e633887bf2c97b61d8bd360e35bcc would close this gap.
  • ⚠️ Fresh CI for the current head was still in progress during review. The latest Praktika report had no failures at the time checked and Style check had passed, but final CI completion was not yet available.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label May 16, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

This was fixed by #105146. Let's update the branch.

@vdimir vdimir self-assigned this May 18, 2026
@groeneai

groeneai commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator Author

CI ledger — covered SHA: 17f0d2975d7211a9625a8b48112231d6be2798ad

CI fully finished (Mergeable Check completed; 0 pending checks).

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

@vdimir

vdimir commented Jun 5, 2026

Copy link
Copy Markdown
Member

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.

@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]>
@groeneai

groeneai commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator Author

@ vdimir thanks — pushed b7d6e3492a0c.

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 on both queries. The remaining knob that can mask the bug on master HEAD is MergeTree randomization (index_granularity_bytes, min_bytes_for_wide_part, etc.) which can change part type / mark layout so the per-block virtual row marker never reaches LimitTransform at the boundary. Added no-random-merge-tree-settings to keep the data layout deterministic. Awaiting Bugfix validation re-run.

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]>
@groeneai

groeneai commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate (fix-up commit a847a6faa322)

# 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

@groeneai

groeneai commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator Author

@vdimir thanks — the previous fix-up's no-random-merge-tree-settings umbrella was the wrong tool for this. Pushed a847a6faa322 which pins the actual trigger: use_skip_indexes_on_data_read = 0 in both query SETTINGS clauses, and drops the broad MergeTree randomization tag.

Minimal trigger isolated locally — 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) deterministically abort clickhouse built from master HEAD on LimitTransform.cpp:60 Logical error: 'row < chunk.getNumRows()'. Verified by piping the test SQL into the buggy binary.

The Bugfix validation framework should now reproduce the assertion deterministically.

@groeneai

groeneai commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator Author

@vdimir thanks. The four read_in_order related settings are pinned in the test SQL since a847a6faa322. Local Debug build of master HEAD (9c9b2b9a0da7) without our LimitTransform.cpp change deterministically aborts on LimitTransform.cpp:60 Logical error: 'row < chunk.getNumRows()' on every run when piping the test SQL into clickhouse-client (verified just now).

The remaining Bugfix validation (functional tests) failure is a framework limitation, not a settings issue. The check downloads master/aarch64/clickhouse (release build), and chassert is compiled out in release (see base/base/defines.h:42-49). With the assertion stripped, the empty-chunk path silently calls insertFrom(col, UINT64_MAX) and the test produces the same output rows as the fixed branch, so the runner reports Failed to reproduce the bug. This affects any chassert-only fix in Bugfix validation; with GLOBAL_TAGS=no-random-settings set by the bugfix runner, no amount of in-test setting pinning can change that.

Two options:

  1. Land this PR despite the Bugfix-validation gap (the regression test is correct under Debug/sanitizer builds, where the AST fuzzer originally hit it; chassert assertions surface in Stress test and AST fuzzer pipelines that DO fire).
  2. Replace chassert at LimitTransform.cpp:60 with an exception throw so the misbehavior is observable in release as well. That's a separate behavioral change with broader implications. Happy to do it in a follow-up PR if you prefer that as the long-term direction.

Session: cron:clickhouse-ci-task-worker:20260605-225900

alexey-milovidov pushed a commit to evillique/ClickHouse that referenced this pull request Jun 6, 2026
…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)
alexey-milovidov pushed a commit to jh0x/ClickHouse that referenced this pull request Jun 6, 2026
…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)
alexey-milovidov pushed a commit to adityachopra29/ClickHouse that referenced this pull request Jun 6, 2026
…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)
alexey-milovidov pushed a commit to abonander/ClickHouse that referenced this pull request Jun 6, 2026
…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)
alexey-milovidov pushed a commit to melvynator/ClickHouse that referenced this pull request Jun 6, 2026
…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)
alexey-milovidov pushed a commit to Onyx2406/ClickHouse that referenced this pull request Jun 6, 2026
…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)
alexey-milovidov pushed a commit to Onyx2406/ClickHouse that referenced this pull request Jun 6, 2026
…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)
alexey-milovidov pushed a commit to RinChanNOWWW/ClickHouse that referenced this pull request Jun 6, 2026
…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)
alexey-milovidov pushed a commit to yurifedoseev/ClickHouse that referenced this pull request Jun 6, 2026
…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)
alexey-milovidov pushed a commit that referenced this pull request Jun 6, 2026
…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)
alexey-milovidov pushed a commit to gregakinman/ClickHouse that referenced this pull request Jun 6, 2026
…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)
@groeneai

groeneai commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator Author

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>();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why extract<MergeTreeReadInfo> below doesn't do the same?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we change behavior here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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?

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI summary on HEAD 44bbea1 (CI fully finished). Disposition of each failure:

  • Build (arm_tidy) — now green on this HEAD. The earlier red was a trunk-stale clang-tidy init-variables warning in Iceberg/Mutations.cpp (introduced by catalogs with schema evolutions + concurrent checks #106102, unrelated to this PR); the master merge into this branch picked up the upstream fix (Fix arm_tidy build #106609), clearing it.
  • Bugfix validation (functional tests) / 04247_99495_limit_with_ties_virtual_row_empty_chunk — expected framework limitation. The original LimitTransform guard is a debug-only chassert, which is a no-op in the release binary the bugfix-validation job builds from master HEAD, so the regression test cannot deterministically FAIL there. The bug is real and reproduces deterministically on a debug build (validated both directions, above). Same pattern as discussed on this PR's design thread.
  • Stateless tests (arm_asan_ubsan, azure, parallel/sequential) — Server died + Segmentation fault (STID 0883-5001) — unrelated infrastructure: the 2026-06-10/11 arm_asan_ubsan, azure ASan-allocator OOM outage that hit ~100 unrelated PRs and master in the same window.
  • Stress test (arm_ubsan) — Hung check failed, possible deadlock found — chronic stress-runner family, not specific to this change.

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]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

The AST fuzzer hit this exact assertion again on 2026-06-15 (STID 2508-3b8e, PR #103322's AST fuzzer (amd_debug, targeted)), via a second, independent code path. Pushed eed48fb9d82 adding it to the regression test.

SELECT DISTINCT a AS b, '[a-z]', 100 AS a ORDER BY 1 DESC NULLS FIRST WITH FILL STALENESS -1 LIMIT 1 WITH TIES;

EXPLAIN PIPELINE shows there is no read-in-order / virtual-row pipeline here:

(Limit) Limit
  (Filling) FillingTransform
    (Distinct) DistinctSortedTransform
      ...
        (ReadFromSystemOne)

WITH FILL emits a zero-row chunk that reaches LimitTransform at the WITH TIES boundary, so makeChunkWithPreviousRow(chunk, getNumRows() - 1) underflows. Only the LimitTransform rows > 0 guard (fix #1) protects this case; the SortingStep/RemoveVirtualRowTransform change (fix #2) does not apply since there is no merging stage. Same assertion, different empty-chunk source, which is good evidence that the rows > 0 guard is the correct general fix.

The bug is still live on current master: a Debug build of b5fa90e2908 (master as of today, 110 commits behind origin/master, neither fix present) SIGABRTs on the query above; the same binary with this branch's LimitTransform.cpp change returns 100 [a-z] 100 cleanly.

This new case is also a cleaner regression test for the Bugfix validation concern you raised: it needs no read_in_order_use_virtual_row_per_block randomization at all, just a plain table-less query, so it does not depend on the fragile virtual-row path.

Pre-PR validation gate (test-only commit eed48fb9d82)

# 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

Comment thread src/Processors/LimitTransform.cpp Resolved
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]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

For the FractionalLimitTransform fix-up (cbfa201):

# 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 0.5 WITH TIES" aborts every time on the pre-fix binary (exit 134).
b Root cause explained? Yes. WITH FILL emits a trailing zero-row chunk. It reaches FractionalLimitTransform::pushData at the WITH TIES boundary (rows_processed == offset_rows + limit_rows), where makeChunkWithPreviousRow(chunk, chunk_rows - 1) is called with chunk_rows == 0, so row underflows to UINT64_MAX and chassert(row < chunk.getNumRows()) fails. gdb confirmed frame FractionalLimitTransform.cpp:80 with row=18446744073709551615.
c Fix matches root cause? Yes. Adds && chunk_rows > 0 to the two unguarded WITH TIES boundary sites, exactly mirroring the merged LimitTransform guard (&& rows > 0). The stored ties_last_row is still the correct tie key at the boundary, so an empty chunk is simply skipped.
d Test intent preserved / new tests added? Yes. Added a fractional LIMIT ... WITH TIES case to 04247_99495_limit_with_ties_virtual_row_empty_chunk. The existing virtual-row and WITH FILL cases are unchanged and still pass.
e Both directions demonstrated? Yes. Pre-fix binary (Build ID 64077ec2): exit 134, gdb stack at FractionalLimitTransform.cpp:80. Post-fix binary (Build ID 7ecb11b6): exit 0, expected output, and the test passes 30/30 with randomization.
f Fix is general, not a narrow patch? Yes. Checked all three makeChunkWithPreviousRow(_, X - 1) sites in FractionalLimitTransform: early-push (prepare) and final-push (pushData) were both unguarded and are both fixed; splitChunk is already guarded by a non-zero cut_length, matching LimitTransform::splitChunk. This completes the sibling-path coverage requested in the review.

Session id: cron:clickhouse-worker-slot-2:20260616-005900

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finished on cbfa201. No PR-caused failures; the Bugfix validation check is green on this head.

  • Stress test (arm_debug) "Hung check failed, possible deadlock found": chronic stress hung-check flake, not from this PR. 30d CIDB shows 270 master hits plus ~20 unrelated PRs with the same signature; this PR itself hit it on 2026-06-10 (arm_ubsan) before the FractionalLimitTransform commit. It is 1/5 on arm_debug and 0/4 on all 10 other Stress variants, with the generic all-threads stack_trace dump. The empty-chunk guard only skips work at the WITH TIES boundary, so it cannot introduce a wait cycle.
  • Performance Comparison (arm_release, 2/6): perf-comparison noise, not PR-caused.
  • Bugfix validation in-job server-log scan rows (Lost forever / Lost s3 keys / S3_ERROR / OOM in dmesg): pre-existing infra noise present across the PR queue; the Bugfix validation check itself passed here.
  • CH Inc sync: internal clickhouse-private mirror, not a public gate.

The regression test passes across all Stateless variants.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI fully finished on HEAD cbfa2015eda8 (Finish Workflow SUCCESS, Config Workflow SUCCESS, 0 pending). Triage of every failure:

  • Stress test (arm_debug) — Hung check failed, possible deadlock found: chronic trunk infra flake, NOT caused by this PR. The captured stack is the generic system.stack_trace diagnostic dump (PipelineExecutor worker threads, no LimitTransform frame). 30-day distribution: 25 distinct PRs plus master, one hit each.
  • Performance Comparison (arm_release, master_head, 2/6) — 0 individual test-regression rows; job-level perf-comparison noise, not PR-caused.
  • Bugfix validation (functional tests) — OOM in dmesg / S3_ERROR No such key / Lost forever for SharedMergeTree / Lost s3 keys / Exception in test runner: standard bugfix-validation infra meta-rows, identical across the PR queue, not PR-caused.

The new regression test 04247_99495_limit_with_ties_virtual_row_empty_chunk passes everywhere, including the flaky checks (amd_asan_ubsan / amd_debug / amd_msan / amd_tsan = 50/50 each). No real test failures on this HEAD.

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.
@alexey-milovidov

Copy link
Copy Markdown
Member

Refreshed the branch onto current master (it had fallen ~6800 commits / ~19 days behind). The merge was clean — all three guards (LimitTransform, FractionalLimitTransform) and the RemoveVirtualRowTransform change apply unchanged on top of current master, and every symbol they rely on (isVirtualRow, the ISimpleTransform ctor, Chunk::clear) is still present.

One thing the merge required: the regression test number 04247 now collides with the newly-added 04247_attach_table_storage_clauses_without_engine_error, so I renumbered it to 04419_99495_limit_with_ties_virtual_row_empty_chunk. The test content is unchanged.

Fresh CI is running on 28524b0a461.

@clickhouse-gh

clickhouse-gh Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.40% 85.40% +0.00%
Functions 92.60% 92.60% +0.00%
Branches 77.60% 77.60% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 14/14 (100.00%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 28524b0

CI fully finished (Finish Workflow + Mergeable Check: success) on the branch after it was refreshed onto current master. This PR fixes the chronic AST-fuzzer LimitTransform::makeChunkWithPreviousRow assertion (LIMIT WITH TIES over an empty virtual-row chunk). Every failure has an owner; none is PR-caused.

Check / test Reason Owner
CH Inc sync - CH Inc sync (private, not actionable by us)

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

@qoega

qoega commented Jul 7, 2026

Copy link
Copy Markdown
Member

Our aarch64 AST-fuzzer-oracle harness (PR #99980) hit this same assertion on the merged7 cycle with a different query shape — same trigger settings, so #105102's fix should cover it. Cross-referencing here for the chronic-signature list.

Snapshot runs/merged7/crashes/inst-09-20260704-120003, ClickHouse 26.7.1 debug, aarch64. Session settings included optimize_read_in_order=1, read_in_order_use_virtual_row=1, read_in_order_use_virtual_row_per_block=1 — exact prerequisites per your root-cause. The last (internal) query before the assertion:

SELECT flag_b, flag_b, flag_a FROM local_dup_mixed ORDER BY dt DESC LIMIT 1 WITH TIES

The duplicate-projected-column (flag_b, flag_b) plus LIMIT 1 WITH TIES on a ORDER BY dt DESC read-in-order pipeline is a slightly different arrival than your minimal repro (PREWHERE mapContains ... ORDER BY id ASC LIMIT 1 WITH TIES) but the empty-chunk-from-virtual-row → makeChunkWithPreviousRow(empty, 0-1) underflow path is the same. Might be worth adding a variant to the regression test if convenient — no urgency, just adds coverage.

For lineage: same assertion signature as closed #11372 (2020, different offset-overflow trigger).

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok.

@alexey-milovidov alexey-milovidov self-assigned this Jul 12, 2026
@alexey-milovidov
alexey-milovidov merged commit df5a725 into ClickHouse:master Jul 12, 2026
173 of 174 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 12, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…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)
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…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)
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…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)
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…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]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…-limit-with-ties-empty-chunk

Fix LimitTransform WITH TIES assertion on empty virtual-row chunk
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 pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logical error: 'row < chunk.getNumRows()' (STID: 2508-4656)

5 participants