Repository navigation
Conversation
`QueryPipelineBuilder::addPipelineBefore` routes the totals and extremes streams through the
`DelayedPortsProcessor` that gates a materialized CTE read, so those streams are gate output
ports.
`QueryPipeline::complete` discarded them by attaching a `NullSink`. A `NullSink` has no
outputs, so `ExecutingGraph::initializeExecution` seeds it and it runs before anything else;
its `prepare` closes its input without ever pulling. That finishes a gate output, the gate
finishes the pair and closes the paired input, and the gated sub-pipeline is released. The
CTE read then runs before `MaterializingCTETransform` has built it and the fail-fast check in
`ReadFromMemoryStorageStep` throws:
Reading from materialized CTE 'a' before its materialization completed -
DelayedPortsProcessor gate is missing in the query plan
Discard the two streams with a `DroppingTransform` on the main output instead. The transform
forwards the data stream 1:1 and drains totals/extremes, so it keeps data outputs and is not
seeded. This is the mechanism 641fc75 already established for the builder's own drop
sites; extending it here removes the last producer of an output-less discard node in this file,
so `drop` and the `NullSink.h` include are no longer needed.
Reached from `EXPLAIN ANALYZE` over a materialized CTE read behind an IN-subquery with either
`extremes = 1` or `WITH TOTALS`. `INSERT ... SELECT` and an aggregating subquery reach the same
error through `QueryPipelineBuilder::dropTotalsAndExtremes`, which is a separate site and is
not changed here.
`complete(Chain)` shares the helper. It is reachable from SQL through a lightweight
`UPDATE`/`DELETE`, but every caller that reaches it drops totals and extremes earlier in
`InterpreterInsertQuery`, so it is always entered with both ports already null and the new test
does not cover it.
Internal second-model review (click to expand)An independent cold review plus a second-model pass reviewed this change against the resulting
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20260806-104800 |
|
cc @KochetovNicolai @davenger, could you review this? |
|
cc @novikd |
|
Workflow [PR], commit [605a434] Summary: ⏳
AI ReviewSummaryThis PR replaces the output-less aux-port discard in Final Verdict✅ No actionable findings in the current diff. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units7 translation units recompiled, 11 s compile time in total, 7 of them have a recent master baseline. |
|
@PedroTadim This is again a duplicate with a wrong solution. There is a current attempt to fix #111194. |
|
Fine to close this one, and I will fold the change into #111194 while addressing your review comment there. One measured point for that work, because it changes what "check all the usages" has to include. There are two independent childless-
Measured on a debug build of #111194's head
The last two rows are the control: they are #111194's own scope, so that column is genuinely carrying #111194. The first four are 3/3 deterministic, and a plain Repro for the first row: SET enable_analyzer = 1;
SET enable_materialized_cte = 1;
EXPLAIN ANALYZE processors = 1
WITH a AS MATERIALIZED (SELECT number AS id FROM numbers(10))
SELECT id FROM a WHERE id IN (SELECT id FROM a)
SETTINGS extremes = 1; |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed the
LOGICAL_ERRORReading from materialized CTE '...' before its materialization completed - DelayedPortsProcessor gate is missing in the query planwhenEXPLAIN ANALYZEruns a query that reads a materialized CTE behind anINsubquery together withextremes = 1orGROUP BY ... WITH TOTALS.Description
QueryPipelineBuilder::addPipelineBeforeroutes the totals and extremes streams through theDelayedPortsProcessorthat gates a materialized CTE read, so they are gate output ports.QueryPipeline::completediscarded them by attaching aNullSink. ANullSinkhas no outputs, soExecutingGraph::initializeExecutionseeds it and it runs first, and itspreparecloses its input without ever pulling. That finishes a gate output; the gate finishes the pair and closes the paired input; the gated sub-pipeline is released. The CTE read then runs beforeMaterializingCTETransformhas built it and the fail-fast check inReadFromMemoryStorageStepthrows, aborting the server in a build with assertions.The two streams are now discarded with a
DroppingTransformon the main output instead. It forwards the data stream 1:1 and drains totals/extremes, so it keeps data outputs and is not seeded. This is the mechanism641fc75ea3f0d37already established for the builder's own drop sites; extending it here leaves the file with no producer of an output-less discard node, sodropand theNullSink.hinclude are deleted. The helper returns immediately when neither port exists.Reached from ordinary SQL, with only
enable_materialized_ctegated. This does not close #110176 by itself, although it does fix that issue's reproducer:INSERT ... SELECTand an aggregating subquery reach the same error throughdropTotalsAndExtremes, a separate site that #111194 addresses.Validation: the four
EXPLAIN ANALYZEshapes abort on unpatched master and pass with the change. Four mutants each redden the new test: reverting the helper call, discarding the aux ports withNullSinkwhile keeping the transform, and corrupting a control or a witness reference line. Reintroducing adropcall no longer compiles. The test passes 100/100 runs (50 randomized, 50 not), and across 262 stateless cases usingextremes,WITH TOTALS,EXPLAIN ANALYZEor materialized CTEs no case fails only with the change and no failure reason changes.