Repository navigation
Fix missing materialized-CTE gate in lightweight UPDATE/DELETE set subqueries - #119489
Conversation
… an `IN` subquery The six run-time set variants (empty table, non-key column, index analysis for `IN` disabled, two `IN` subqueries, a CTE depending on another CTE, lightweight `DELETE`) fail with `LOGICAL_ERROR` before the fix; the in-place variant and the `SELECT` analogue pass. Related: #119451 Co-Authored-By: Claude Fable 5.1 <[email protected]>
…ner` Move the helper out of the anonymous namespace of `Planner.cpp` into `CollectMaterializedCTE.cpp`, next to `collectMaterializedCTEs`, so that plans assembled outside the `Planner` can plant the materialized-CTE gate too. No behaviour change. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
…plan `MutationsInterpreter::buildSubqueryPlansForSetsAndAdd` planned the `IN` subqueries of a mutation with `forceMaterializeCTE` but never added the outer `DelayedMaterializingCTEsStep` that the `Planner` adds through `addBuildSubqueriesForMaterializedCTEsIfNeeded` for a `SELECT`. Since `DelayedCreatingSetsStep::makePlansForSets` strips the safety-net step from every set plan built at run time, the `MemorySource` readers of the CTE ran ungated and hit the fail-fast check in `ReadFromMemoryStorageStep` with `LOGICAL_ERROR`. Collect the CTEs referenced by each set subquery and plant the step after the sets step, as the `Planner` does. Closes: #119451 Fuzzer report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118853&sha=b20ba6c83530627b14d5f12aa0a1089d7275b2a4&name_0=PR&name_1=AST%20fuzzer%20(amd_debug%2C%20targeted) Co-Authored-By: Claude Fable 5.1 <[email protected]>
`Processors/QueryPlan/MaterializingCTEStep.h` was needed only by `addBuildSubqueriesForMaterializedCTEsIfNeeded`, which now lives in `CollectMaterializedCTE.cpp`. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Workflow [PR], commit [6585b66] Summary: ✅
AI ReviewSummaryThis PR fixes the missing outer Final Verdict✅ No findings. LLVM Coverage ReportMeasured on commit 6585b66.
Changed lines: Changed C/C++ lines covered: 51/53 (96.23%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes5 object files changed (+45.87 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units9 translation units recompiled, 36 s compile time in total, 9 of them have a recent master baseline. |
`05182_lightweight_update_materialized_cte_in_subquery` (from #119489) exercises the mutation plan for a materialized CTE inside a lightweight `UPDATE` / `DELETE` predicate. With the default `force_materialized_cte = 1` that statement is rejected before planning, so the test sets the guard off explicitly. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Resolve the cherry-pick of #121010 to 26.8. On master, #119489 moved `addBuildSubqueriesForMaterializedCTEsIfNeeded` from `src/Planner/Planner.cpp` into `src/Planner/CollectMaterializedCTE.cpp`. That PR is not on 26.8, so the hunk did not apply. On 26.8 the function is still in `Planner.cpp`, and its body is identical to the one #121010 patched. The resolution adds the same three lines there, before `Planner cte_planner(...)`, and leaves `CollectMaterializedCTE.cpp` as it is on 26.8. #119489 also adds the materialized-CTE gate for lightweight `UPDATE` and `DELETE` set subqueries, which the two `UPDATE` cases of `05230_materialized_cte_shared_by_two_ctes_in_set_subquery` depend on. Without it they still fail on 26.8, so those two cases are removed from the test here. The `SELECT` cases are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #119451
Related: #98884
Related: #105041
Related: #118853
Related: #118983
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 planraised by a lightweightUPDATE, or a lightweightDELETEinlightweight_update_forcemode, whose predicate contains anINsubquery that defines a materialized CTE, when the set is built at run time.Description
A lightweight
UPDATEplans itsINsubqueries inMutationsInterpreter::buildSubqueryPlansForSetsAndAdd, mirroring the Planner'saddBuildSubqueriesForSetsStepIfNeeded, but the mutation plan never received the outerDelayedMaterializingCTEsStepthataddBuildSubqueriesForMaterializedCTEsIfNeededadds for aSELECT.DelayedCreatingSetsStep::makePlansForSetsstrips the safety-net step from every set plan built at run time and relies on that outer step as the single writer site, so theMemorySourcereaders of the CTE ran ungated and hit the fail-fast check inReadFromMemoryStorageStep. The set built in place during primary-key analysis (populated table,INon a key column,use_index_for_in_with_subqueries = 1) keeps its safety net, which is why only the run-time set path failed.The helper is moved out of the anonymous namespace of
Planner.cppintoCollectMaterializedCTE.cppand called for the CTEs referenced by the set subqueries of each mutation stage. No optimizer or pipeline changes.For mutations without materialized CTEs the change is a no-op:
collectMaterializedCTEsreturns nothing andaddBuildSubqueriesForMaterializedCTEsIfNeededreturns before touching the plan, so no step is added.Found by the AST fuzzer: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118853&sha=b20ba6c83530627b14d5f12aa0a1089d7275b2a4&name_0=PR&name_1=AST%20fuzzer%20(amd_debug%2C%20targeted)
Note on #118853: with
force_materialized_cte = 1(its default) a materialized CTE in a lightweightUPDATEis rejected before planning, which also covers this shape. Whichever of the two merges second must addSET force_materialized_cte = 0to the new test; the setting does not exist onmasteryet, so this PR cannot set it.ALTER TABLE ... UPDATEcannot reach this path until #118983 is fixed.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/119489]