Repository navigation
Do not start reading in multi-output transforms before an output asks for data - #125043
Conversation
…ake data A lightweight UPDATE/DELETE whose predicate is a constant `ignore(...)` tears its pipeline down before it runs: `FilterTransform` closes on its first `prepare`, and the stacked `DelayedCreatingSets` and `MaterializingCTEs` gates finish all their pairs, which closes the writer of a MATERIALIZED CTE unrun and closes the never-started `IN`-set plan from its end. The close reaches a multi-output processor one output at a time. `NegativeLimitTransform`, `NegativeOffsetTransform`, `FractionalLimitTransform`, `FractionalOffsetTransform`, `CopyTransform` and `ScatterByPartitionTransform` answered the first finished output by calling `setNeeded()` on their inputs although none of their outputs had ever been needed, so a `MemorySource` reading the CTE ran before the close caught up and threw "Reading from materialized CTE ... before its materialization completed" (STID 2467-34d3, AST fuzzer, a mutation of 05210_lightweight_update_materialized_cte_in_ignore). These six now follow the rule every single-output transform follows (`ISimpleTransform::prepare`): request input only while an unfinished output can take a chunk, otherwise withdraw the demand and return `PortFull`. The predicate lives in `IProcessor::isAnyOutputPushable`. ClickHouse#119715 applied the same rule to `DelayedPortsProcessor`. While some output can take data the code path is unchanged. The new test has one teardown statement per processor; each aborts on master, and reverting any single guard brings back only its statement. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the over-general second sentence of the isAnyOutputPushable doc comment. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings), plus my own review of the same head (4 nits, none blocking).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261010-074200 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261010-045900 |
|
Workflow [PR], commit [956a755] Summary: ✅
AI ReviewSummaryThis PR makes the first input request in Final Verdict✅ No blocking or major issues found. I did not post any new inline review comments. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units667 translation units recompiled, 4540 s compile time in total, 667 of them have a recent master baseline. |
|
They are independent. Both involve a
Neither covers the other: this PR's test aborts in |
The previous guard made the six multi-output transforms request input only while an unfinished output could take a chunk (`canPush`), which also removed their existing prefetch while every output holds data. That is a behaviour change outside the teardown this PR fixes, and CI measured it on the INSERT fan-out to materialized views, where `CopyTransform` feeds every view: `03652_threads_count_insert` got 5 instead of 7 peak threads, and `test_materialized_views_cascaded_multiple` saw its views run in another order (`42,0` instead of `42,2` with `max_threads = 1`). The master unit test `ScatterByPartition.DoesNotPullAnotherChunkWhileOneIsPending`, which encodes that prefetch, failed as well. The teardown only needs the start to be gated: a processor that no output ever asked for must not wake its sources. So each of the six now requests its inputs for the first time only once an unfinished output `isNeeded()`, the rule ClickHouse#119715 applied to `DelayedPortsProcessor` (`are_inputs_initialized`), and behaves exactly as on master afterwards. In normal execution the first `prepare()` of such a processor is caused by a consumer calling `setNeeded()` on one of its outputs, so nothing changes there; in the teardown the outputs only finish, so the inputs are never requested and the CTE readers in the never-started `IN`-set plan do not run. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #119715
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Negative and fractional
LIMIT/OFFSET,GROUPING SETSand window functions withPARTITION BYnow wait until a downstream step asks for data before reading their input, so a lightweightUPDATEorDELETEwhoseignore(...)predicate holds anINsubquery over aMATERIALIZEDCTE no longer fails with a logical error.Description
Found by the AST fuzzer (STID 2467-34d3) on 2 unrelated PRs: report 1, report 2.
Repro on master (
t: MergeTree with block number/offset columns, rows 0, 1, 2 in one part):Cause: the constant
ignore(...)filter tears the mutation pipeline down before it runs, which closesc's writer unrun and the never-startedIN-set plan from its end. A multi-output processor in that plan sees its outputs finish one at a time; six of them answered the first one by requesting input, although no output was ever needed, so a reader ofcran.Change: each of the six requests its inputs for the first time only once an unfinished output asks for data (
IProcessor::isAnyOutputNeeded), the rule #119715 applied toDelayedPortsProcessor; after that it behaves as before. In normal execution that first request is caused by a consumer asking for data, so only a processor nobody asked is affected. Open #114550 adds a stricter per-call guard toScatterByPartitionTransformthat subsumes this one.Validation: new test
05355_lightweight_update_materialized_cte_set_teardown, one statement per processor; each aborts on master and passes with the change. 50 randomized runs pass. The processors' unit tests and 819 related stateless tests (materialized-view fan-out incl.03652_threads_count_insert, distributed broadcast/shuffle, windows, grouping sets, negative/fractional limits) give the same results with and without the change.Workflow [PR]
Sync PR [sync-upstream/pr/125043]
Version info
26.11.1.43-master(included in26.11and later)