Repository navigation
Conversation
… steps When `correlated_subqueries_use_in_memory_buffer` is off, a decorrelated subquery body is duplicated by cloning it, so `optimizeTreeSecondPass` first takes the `IN` sets out of the fragments and then re-attaches them in a single `DelayedCreatingSetsStep`. That step was attached above the plan root. With a top-level `MATERIALIZED` CTE the root at that moment is the `DelayedMaterializingCTEsStep` chain the planner pushed, so the set builder landed above the CTE gate. Both `CreatingSetsStep::updatePipeline` and `MaterializingCTEsStep::updatePipeline` end in `addPipelineBefore`, whose `DelayedPortsProcessor` marks the main pipe's output ports delayed and leaves the "before" branch as the non-delayed side, so a node's child 0 runs after its siblings. With the set gate on top, the set plans became the "before" branch and ran before the CTE writer, while `makePlansForSets` had already stripped the set plan's own `DelayedMaterializingCTEsStep` on the premise that the outer step dominates every reader. The set source then read an unmaterialized `StorageMemory` and `ReadFromMemoryStorageStep` reported the missing gate as a `LOGICAL_ERROR`. Attach the builder below every `DelayedMaterializingCTEsStep` on the plan's single-child spine instead. That is the position `addBuildSubqueriesForSetsStepIfNeeded` already uses for the plan's own set builder, immediately below the CTE chain added on the next line. With no materialized CTE on the spine the resulting plan is unchanged. The same failure is reachable a second way, because the optimizer-side flag is also cleared by `correlated_subqueries_default_join_kind = 'left'`; the new test arms cover both settings, each read against the same query with neither setting applied. One arm is structural and asserts via `EXPLAIN PLAN` that the CTE gate stays at the plan root with the set gate under it, so the ordering is pinned rather than inferred from values. `make_distributed_plan = 1` clears the same flag and so enters the same hoist, but every shape of this query measured under it is rejected before execution by the exchange guard in `convertToDistributed`, identically with and without this change, so it gets no arm. Reported by zlareb1 on ClickHouse#115868.
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 gate runs, 1 finding then 0
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20260831-100002 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20260831-094600 |
|
Workflow [PR], commit [1c546da] Summary: ❌
AI ReviewSummaryThe PR places the extracted Final Verdict✅ Approve. |
|
cc @novikd @vdimir, could you review this? When a decorrelated subquery body is duplicated, |
Build profile diff (arm_release)Commit See the job log for details. |
CI finish ledger -
|
| Check / test | Reason | Owner / fixing PR |
|---|---|---|
Integration tests (amd_asan_ubsan, db disk, old analyzer, 2/6) / Container memory budget exceeded (/docker) |
/docker cgroup leaf OOM kills the concurrent shutdown gdb attaches; job ERROR, no test failed |
#117202 (external, merged 2026-08-31), absent from this tree |
Integration tests (amd_asan_ubsan, db disk, old analyzer, 5/6) / Container memory budget exceeded (/docker) |
same leaf OOM as above | #117202 (external, merged 2026-08-31), absent from this tree |
Integration tests (amd_asan_ubsan, db disk, old analyzer, 6/6) / Container memory budget exceeded (/docker) |
same leaf OOM as above | #117202 (external, merged 2026-08-31), absent from this tree; a fix task owns the 6/6 residual noted below |
The three Container memory budget exceeded (/docker) rows are one signature, not three. The
/docker cgroup leaf that bounds the nested test containers is capped at 40.78 GiB, and
docker compose stop signals every node of a cluster at once, so each node that outlives the
60 s deadline attaches gdb at the same moment. On an ASan build each attach holds about 3.4 GiB
of anonymous memory, so a nine-node cluster asks for roughly the whole leaf and the kernel kills
the debuggers. #117202 serializes that attach. It is merged, but it is outside the tree this
run built: the fix symbol GDB_ATTACH_LOCK is absent at fc2c5eb1f337 and present at the merge
commit 7fc3004ed25a. So the run predates the fix. These rows clear when the branch next picks
master up. I am not merging master here purely to re-run CI, to keep the review load down.
Measured caveat: on true-master trees that DO contain #117202, the 2/6 and 5/6 shards are
clean (0 of 13 post-fix trees) but 6/6 still fires (13 of 13). So a 6/6 row may return after
the master merge. A fix task owns that residual and its fixing-PR link will be posted here when
one opens.
Two things in the check list are artifacts of this head having been built twice, and neither is a
defect. Two PR workflow runs were triggered nine seconds apart, 33382952934 and
33382964461. Stateless tests (arm_binary, parallel) is red only in the second, where the job
ended after 47 s without starting a test; in the first it is success with 13428 passing test
rows and no failing row at this commit. Finish Workflow is likewise red only in the second,
reporting that run's integration rows. The three integration rows above failed in both runs,
which is why they are the only ones owed an owner.
None of these rows is reachable from this diff, which attaches the correlated-subquery set
builder below the materialized CTE steps.
Mergeable Check and PR are praktika aggregators. Config Workflow, Style check and
CH Inc sync are all success on this head.
Session id: cron:our-pr-ci-monitor:20260831-203000
…ated-set-builder-below-materialized-cte
`make_distributed_plan = 1` also clears `correlated_subqueries_use_in_memory_buffer`, so it reaches the same `IN`-set hoist. Before the master merge such a query was refused with `SUPPORT_IS_DISABLED` on both binaries, so it had no arm. Master now falls back to local execution when a plan cannot be distributed (`distributed_plan_fallback_to_local_execution`, on by default), and the query runs. Measured on the master debug snapshot `e5b8853baca3`: the new arm aborts the server with `Reading from materialized CTE 'mat' before its materialization completed - DelayedPortsProcessor gate is missing in the query plan`. With this branch it returns `1 0 / 2 1 / 3 0`, and 60/60 randomized runs of the whole file pass. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 81dd802Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
All 172 check runs completed (128 pass, 41 not selected, 3 red: the row above and its two rollups), Session id: cron:our-pr-ci-monitor:20260927-173207 |
|
Fixing PR for the |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A correlated subquery whose
INsubquery reads an experimentalMATERIALIZEDCTE now runs when its decorrelated body is duplicated (correlated_subqueries_use_in_memory_buffer = 0orcorrelated_subqueries_default_join_kind = 'left'), instead of failing with aDelayedPortsProcessor gate is missinglogical error.Description
Reported by @ zlareb1 on #115868 (comment). Related: #116343. Filed as
Improvementbecauseenable_materialized_cteis experimental.What breaks. With
enable_materialized_cte = 1, a valid query is rejected withCode: 49 ... DelayedPortsProcessor gate is missing in the query plan:Root cause. When a decorrelated body is duplicated,
optimizeTreeSecondPasstakes theINsets out of the fragments and re-attaches oneDelayedCreatingSetsStepabove the plan root. With a top-levelMATERIALIZEDCTE, that root is theDelayedMaterializingCTEsStepchain, so the set builder lands above the CTE gate. Both steps schedule throughaddPipelineBefore, so the set plans run before the CTE writer, whilemakePlansForSetshas already stripped the set plan's own gate on the premise that the outer gate dominates it. Its source then reads an unmaterializedStorageMemory.The change. Attach the builder below every
DelayedMaterializingCTEsStepon the plan's single-child spine, which is wherePlanner.cppalready puts the plan's own set builder. With no materialized CTE on the spine the behaviour is unchanged.Validation. Both settings above reproduce the logical error before the fix and pass after it; the
buffer = 1control is unchanged. Eight arms were added to05029_correlated_subquery_materialized_in_set, one a structuralEXPLAIN PLANarm pinning the CTE gate at the root. They abort a pre-fix debug server and pass 60/60 randomized runs after it.make_distributed_plan = 1clears the same flag, and a plan it cannot distribute now runs locally (distributed_plan_fallback_to_local_execution), so it reaches the same hoist and has its own arm.Workflow [PR]
Sync PR [sync-upstream/pr/117311]