Repository navigation
Add regression test for empty-pipe reverse-order read (STID 2635-3a9e) - #105132
alexey-milovidov merged 9 commits into
Conversation
…ith InReverseOrder `ReadFromMergeTree::readInOrder` constructs one `Pipe` per part in `parts_with_ranges`, unites them with `Pipe::unitePipes`, then for `ReadType::InReverseOrder` unconditionally inserts a `ReverseTransform` via `Pipe::addSimpleTransform`. `parts_with_ranges` can legitimately be empty: - A layer produced by `splitIntersectingPartsRangesIntoLayers` may end up empty when called from the `readByLayers` path that the `query_plan_read_in_order_through_join` optimization uses on the preserved side of a `LEFT JOIN`. - The non-intersecting branch of `splitPartsWithRangesByPrimaryKey` returns no parts when every range intersects with another. In that case `Pipe::unitePipes` returns an empty `Pipe` (no output ports) and `Pipe::addSimpleTransform` throws `LOGICAL_ERROR: 'Cannot add simple transform to empty Pipe.'`. This crashed the server on master via the server-side AST fuzzer (`serverfuzz`) on 2026-05-15 in both `Stress test (experimental, serverfuzz, amd_tsan)` and `Stress test (experimental, serverfuzz, arm_debug)` (STID `2635-3a9e`, source test `04230_top_k_through_join_join_swap_gate.sql`). Fix: guard the `ReverseTransform` insertion with `pipe.numOutputPorts() > 0`. Reversing an empty pipe is a no-op; callers already handle empty pipes from `read` (see `ReadFromMergeTree::readByLayers` substituting a `NullSource`). Adds regression test `04251_stid_2635_empty_pipe_reverse_order.sql` covering the four shapes that reach the previously buggy branch: single-table `ORDER BY ... DESC` with forced intersecting-layer split, empty-table `ORDER BY ... DESC`, the original `read-in-order-through-join` `LEFT JOIN` shape from `04230_top_k_through_join_join_swap_gate`, and plan-time pipeline construction via `EXPLAIN PIPELINE` (the path that `viewExplain(...)` takes). CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=3ef3c3b01c0be29077da7292df6b24f890212c70&name_0=MasterCI&name_1=Stress%20test%20%28experimental%2C%20serverfuzz%2C%20amd_tsan%29
|
cc @KochetovNicolai @vdimir @alexey-milovidov — could you review this? |
Pre-PR validation gate (TASK.md Phase 4)Session: a) Deterministic repro? Partial — exact SQL-level reproduction of the b) Root cause explained? Yes. c) Fix matches root cause? Yes. The fix targets the exact mechanism from (b): guard the d) Test intent preserved? / New tests added? Yes. No existing tests are modified or weakened. Added e) Demonstrated in both directions? Partial — see (a). With the fix applied, the regression test passes 20× under full CI randomization ( f) Fix is general, not a narrow patch? Yes. The fix is at the actual error site (
|
|
Workflow [PR], commit [497827d] Summary: ✅ AI ReviewSummaryThis PR is now test-only: it adds Final VerdictStatus: ✅ Approve |
|
This was fixed by #105146. Let's update the branch. |
|
@alexey-milovidov thanks for merging The new CI run on
Just before the crash the same log shows the symptom chain that usually precedes these crashes on this variant: CIDB shows this is a chronic problem with this specific check, not specific to this PR. Last 7 days, same check,
Different crash stacks each time — ASan #105146 was for Could you retrigger this single check, or would you prefer I push a trivial no-op commit to kick CI? |
…order
Update the branch with current master to trigger fresh CI. The two
previously-red checks are unrelated to this change:
- 02180_group_by_lowcardinality 'result differs' was a flaky
non-deterministic LIMIT under ParallelReplicas + s3, fixed on master
by 4bced7e (after this branch's merge-base), now picked up here.
- 'Server died' is the chronic master-wide flake tracked in ClickHouse#102044,
crashing in MergeTask/MergeTreeSequentialSource, never in
ReadFromMergeTree::readInOrder.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…-order fix The previous test exercised single-table read-in-order and a LEFT JOIN with read-in-order-through-join, but the empty parts_with_ranges that hits read(..., InReverseOrder) is only produced by join sharding (query_plan_join_shard_by_pk_ranges, default false), so the test passed on an unfixed binary. Replace the cases with a join-sharding + reverse-key + disjoint-PK-band query that produces an empty per-source layer and reaches the regressed read path. Verified with gdb that without the numOutputPorts() guard this aborts at ReadFromMergeTree::readInOrder via Pipe::addSimpleTransform on an empty pipe, and with the guard it returns the correct result. Kept the empty-table reverse-order case for breadth. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ndomization
The shard-join reverse-key case reaches read({}, InReverseOrder) only when
read_in_order is enabled, which requires optimize_read_in_order &&
query_plan_read_in_order (QueryPlanOptimizationSettings.cpp:188). The stateless
runner randomizes optimize_read_in_order, so a run with it off skipped the
guarded path and the test passed even on an unguarded binary. Pin both inline so
the regression aborts when the numOutputPorts() > 0 guard is removed regardless
of runner randomization.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Correct, thank you. Pinned Verified guard-sensitivity on a debug build, both directions:
|
|
CI finished on c88554d. The only non-skipped failure is pre-existing and not caused by this change:
The new regression test passes (the guard-sensitivity fix from the latest commits is in). Ready for review. |
CI finish ledger — bbffb73CI fully finished (Finish Workflow: success). This PR guards a
Session id: cron:our-pr-ci-monitor:20260630-163000 |
Ledger line resolved:
|
…635-empty-pipe-reverse-order # Conflicts: # src/Processors/QueryPlan/ReadFromMergeTree.cpp
|
Scope reduced to test-only, pushed as a89abc1 (merged current master). Master independently fixed the same empty-pipe Validated locally (debug) both directions: with master's guard present the test passes and matches the reference; with the guard removed the same query SIGABRTs at Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-12:20260702-170800 |
The empty_reverse (empty-table) case never reached the guarded
read({}, ReadType::InReverseOrder) path: an empty MergeTree read is
replaced by a ReadNothing/NullSource step upstream (verified via EXPLAIN
and by running it against an unguarded binary, where it did not abort in
either count() or FORMAT Null form). Remove it; it could pass on an
unguarded binary and was misleading.
The shard_join_reverse case is the genuinely guard-sensitive reproducer:
it reaches readByLayers -> read({}, InReverseOrder) with an empty layer.
Verified both directions on a debug build: with master's guard
(if (pipe.empty()) return pipe;, e45eb19) it returns 50; with the
guard reverted it aborts with the exact empty-pipe LOGICAL_ERROR at
ReadFromMergeTree::readInOrder. The inline query-level SETTINGS override
runner-injected optimize_read_in_order=0, so the reverse path is forced
regardless of randomization.
Also refresh the header comment to reference master's actual early-return
guard instead of the earlier numOutputPorts() > 0 form.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Updated the regression test per the two review comments (c25ffab). PR remains test-only. Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-4:20260702-183100 |
The guard-sensitive shard-join reverse-order query previously used FORMAT Null
(proving only that it no longer aborts) with correctness checked by a separate
count() over a stripped-down join that takes a different read path. A regression
that silently loses or duplicates rows through read({}, ReadType::InReverseOrder)
would still pass.
Assert the ordered output of the exact guarded query directly (the 50 shared
keys, descending). The top-level ORDER BY k DESC keeps the read on the
reverse-order path (an aggregate wrapper would let RemoveRedundantSorting drop
the sort), and comparing the rows themselves catches wrong-result regressions,
not just aborts.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-10:20260702-195400 |
LLVM Coverage Report
Changed lines: No C/C++ source files changed — skipping uncovered code analysis. Newly covered by added/modified tests: 322 line(s), 12 function(s) across 57 file(s) · Details Top files
|
CI finish ledger — 497827dCI is complete on this head. This is a test-only PR (adds a regression test for the empty-pipe reverse-order read, STID 2635-3a9e). No failed tests; all aggregators green (Finish Workflow, Mergeable Check pass); only the private
Session id: cron:our-pr-ci-monitor:20260703-000000 |
…2635-empty-pipe-reverse-order Add regression test for empty-pipe reverse-order read (STID 2635-3a9e)
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Now test-only. The code fix this PR originally carried (guarding the
ReverseTransforminsertion inReadFromMergeTree::readInOrderagainst an emptyPipe) has been superseded on master by an independent, equivalent fix:if (pipe.empty()) return pipe;at the same site, added in commit e45eb19 (Nikita Taranov, merged 2026-05-07). For pipes built byreadInOrder,Pipe::empty()(processors empty) andnumOutputPorts() == 0are equivalent, so master's early return already prevents theLOGICAL_ERROR: 'Cannot add simple transform to empty Pipe.'(STID 2635-3a9e). This PR is therefore reduced to just the regression test, which master does not otherwise cover.ReadFromMergeTree::readInOrderunites onePipeper part inparts_with_rangesand, forReadType::InReverseOrder, inserts aReverseTransform.parts_with_rangescan legitimately be empty (a per-source empty layer produced by join sharding, gated byquery_plan_join_shard_by_pk_ranges; or the non-intersecting branch ofsplitPartsWithRangesByPrimaryKey), yielding an emptyPipethat the reverse-order path must pass through rather than abort.tests/queries/0_stateless/04251_stid_2635_empty_pipe_reverse_order.sqlreaches this path via afull_sorting_mergeJOIN over reverse-primary-key tables withquery_plan_join_shard_by_pk_ranges = 1, plus an empty-table reverse read. The read-in-order gates (optimize_read_in_order,query_plan_read_in_order) are pinned so the test stays guard-sensitive under CI randomization.Validated locally (debug) in both directions:
ReadFromMergeTree::readInOrder->Pipe::addSimpleTransform, confirming the test catches the regression.No related open GitHub issue (originally surfaced by the server-side AST fuzzer, STID 2635-3a9e).
Version info
26.7.1.468(included in26.7and later)