Skip to content

Reject correlated MATERIALIZED CTE reused in a JOIN at analysis time - #108883

Merged
alexey-milovidov merged 6 commits into
ClickHouse:masterfrom
groeneai:fix-placeholder-materialized-cte
Sep 12, 2026
Merged

alexey-milovidov merged 6 commits into
ClickHouse:masterfrom
groeneai:fix-placeholder-materialized-cte

Conversation

@groeneai

@groeneai groeneai commented Jun 30, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix a logical error when a correlated MATERIALIZED CTE is referenced more than once inside a JOIN. Such a CTE is now rejected at analysis time with UNSUPPORTED_METHOD, consistently with the single-reference and IN-subquery paths.

Description

Related: #105501
Closes: #118851

A MATERIALIZED CTE is materialized once and cannot depend on outer-scope columns, so its body cannot be a correlated subquery. The analyzer already rejects this on the IN-subquery path and on the first (storage-initializing) reference in the join tree.

When such a CTE is referenced more than once it is not inlined, so each reference is a separate TableNode resolved independently, and the storage-initializing one can resolve non-correlated while a later one resolves correlated. The subsequent-reference branch in resolveQueryJoinTreeNode only verified column structure (verifyMaterializedCTESubqueryMatchesStorage), not correlation, so the correlated clone slipped through and kept its PLACEHOLDER nodes (correlated-column markers), which the materialized-CTE build path never decorrelates.

Two routes then hit a logical error, and rejecting the clone closes both. #105501 reaches ExpressionActions::execute (Trying to execute PLACEHOLDER action). #118851 fails earlier when the CTE body aggregates: query-plan optimization hashes the sub-plan's ActionsDAG for an aggregation cache key (setAggregationHashTableCacheKeys -> calculateHashFromStep -> ActionsDAG::serialize), which has no case for PLACEHOLDER and throws Unknown node type 5.

Not debug-only: on 26.8.2.7 (LTS) and 26.9.1.1013 the #118851 query returns Code: 49 ... PLACEHOLDER action node must be removed before query plan optimization, with one non-default setting, enable_materialized_cte = 1.

Reproducer (STID 1611-343c):

SET enable_analyzer = 1, enable_materialized_cte = 1, allow_experimental_correlated_subqueries = 1;
CREATE TABLE users (uid Int16) ENGINE = Memory;
WITH a AS (SELECT uid FROM users), b AS MATERIALIZED (SELECT database, uid FROM a)
SELECT count() FROM b AS l SEMI LEFT JOIN b AS r ON l.uid = r.uid;

The fix runs the correlation check on the subsequent-reference branch too, so every reference is rejected uniformly; the shared check is extracted into a helper. A non-correlated materialized CTE reused in a JOIN keeps working.

Found by Stress test (arm_debug):
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=107826&sha=3f6a79763dc52cd4004e8c1c177b67e1a428e7fd&name_0=PR&name_1=Stress%20test%20%28arm_debug%29

Version info

  • Merged into: 26.9.1.1296 (included in 26.9 and later)

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. WITH a AS (SELECT uid FROM users), b AS MATERIALIZED (SELECT database, uid FROM a) SELECT count() FROM b AS l SEMI LEFT JOIN b AS r ON l.uid = r.uid; with enable_materialized_cte=1, allow_experimental_correlated_subqueries=1 aborts every time (SIGABRT, exit 134). Local gdb backtrace is identical to the CI Stress test (arm_debug) fatal.log: ExpressionActions.cpp:797 PLACEHOLDER -> ExpressionTransform::transform -> PipelineExecutor.
b Root cause explained? A reused MATERIALIZED CTE is not inlined; each reference is a separate TableNode resolved independently. The storage-initializing reference resolved database as currentDatabase() (non-correlated); the second reference resolved database as a correlated outer-scope column (EXPLAIN QUERY TREE shows is_correlated: 1). resolveQueryJoinTreeNode's subsequent-reference branch only ran verifyMaterializedCTESubqueryMatchesStorage (column count/type), not a correlation check, so the correlated clone was materialized; its PLACEHOLDER node is never decorrelated on the materialized-CTE build path and reaches ExpressionActions::execute.
c Fix matches root cause? Yes. Adds the existing isCorrelated() rejection (already present on the IN-subquery and first-reference paths) to the subsequent-reference branch, so a correlated materialized CTE is rejected at analysis time on every path. Not a symptom guard.
d Test intent preserved / new tests added? Yes. Extended 04322_105501_correlated_materialized_cte_in_subquery.sql with the JOIN reused-reference cases (SEMI LEFT / INNER / CROSS), each { serverError UNSUPPORTED_METHOD }, plus a valid non-correlated reused-in-JOIN case that must still work. Existing IN-subquery cases unchanged.
e Both directions demonstrated? Yes. Without the fix the reproducer aborts (SIGABRT); with the fix it returns UNSUPPORTED_METHOD and the server stays up. The valid non-correlated case returns the correct result both before and after.
f Fix is general across code paths? Yes. There are two MATERIALIZED CTE resolution paths with a correlation check: the identifier path (resolveExpressionNode) and the join-tree path (resolveQueryJoinTreeNode). The identifier path already re-checks on every clone (gated on subquery-resolved). Only the join-tree path's subsequent-reference branch was missing the check; that is the one fixed. The shared check is extracted into a helper used by all sites.
g Fix generalizes across inputs? Yes. Verified graceful rejection for SEMI LEFT / INNER / CROSS JOIN, for 3+ references (third reference also covered), and for the IN form reused twice. The non-materialized default (enable_materialized_cte=0) path is unchanged: correlated CTE in JOIN still rejects via the existing isCorrelatedQueryOrUnionNode on the inlined QueryNode with NOT_IMPLEMENTED. Non-correlated materialized CTEs reused in a JOIN keep working.
h Backward compatible? Yes. The change only converts a debug/sanitizer server abort (and undefined behavior in release) into a clean analysis-time UNSUPPORTED_METHOD for a query shape that never produced a correct result. No setting default, on-disk/wire format, or existing-data validation changes.
i Invariants and contracts preserved? Yes. The invariant is: a MATERIALIZED CTE body must be non-correlated (it materializes once, independent of call site). The fix enforces it uniformly across all references. The error path uses the same UNSUPPORTED_METHOD exception and message as the existing checks; no PLACEHOLDER-bearing ActionsDAG can reach pipeline execution via this path.

Session id: cron:clickhouse-worker-slot-3:20260630-020800

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @novikd @vdimir could you review this? It closes the last route to the Trying to execute PLACEHOLDER action abort (STID 1611-343c) that #105518 left open: a correlated MATERIALIZED CTE reused in a JOIN. Subsequent references in resolveQueryJoinTreeNode were resolved but not re-checked for correlation, so a clone that resolved correlated reached pipeline execution with a live PLACEHOLDER. The fix adds the existing correlation rejection to that branch.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jun 30, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [fb7e0c5]

Summary: ✅


AI Review

Summary

This PR closes a real analyzer gap for MATERIALIZED CTEs reused in a JOIN: the first reference already rejected correlated bodies, but a later reference could resolve the cloned subquery against outer scope and carry a live PLACEHOLDER into planning or execution. The extracted helper now enforces the non-correlation invariant on every materialized-CTE resolution path that matters here, and the updated stateless test covers both the broken reused-in-JOIN cases and the still-valid non-correlated reuse case. I did not find any remaining contract violations or missing review comments on the current head.

Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Measured on commit fb7e0c5.

Metric Baseline Current Δ
Lines 88.90% 88.90% +0.00%
Functions 91.70% 91.70% +0.00%
Branches 81.30% 81.30% +0.00%

Changed lines: Changed C/C++ lines covered: 21/21 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 30, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 62abf5f

Every failure below has an owner: a fixing PR (ours or external). Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stress test (amd_tsan) / Hung check failed, possible deadlock found deadlock (chronic trunk; 109 distinct PRs + 76 master hits in 24h, not caused by this PR) #101680 / #105905 (ours, open)
Stress test (arm_tsan) / Hung check failed, possible deadlock found deadlock (chronic trunk; same family) #101680 / #105905 (ours, open)
PR (rollup) aggregates the stress sub-checks above #101680 / #105905 (ours, open)
CH Inc sync - CH Inc sync (private, not actionable)

Session id: cron:our-pr-ci-monitor:20260630-073000

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 62abf5f

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stress test (amd_tsan) / Hung check failed, possible deadlock found deadlock (chronic: 370 hits / 125 PRs / 76 master in 24h) #101680 / #105905 (ours, open)
Stress test (arm_tsan) / Hung check failed, possible deadlock found deadlock (chronic) #101680 / #105905 (ours, open)
CH Inc sync private sync CH Inc sync (private, not actionable)

The analyzer change (reject correlated MATERIALIZED CTE reused in a JOIN) cannot cause a TSan shutdown deadlock; both stress failures are the chronic hung-check family across unrelated PRs and master.

Session id: cron:our-pr-ci-monitor:20260630-083000

A MATERIALIZED CTE is materialized once and cannot depend on outer-scope
columns, so its body cannot be a correlated subquery. The analyzer already
rejects this on the IN-subquery path and on the first (storage-initializing)
reference in the join tree, but a MATERIALIZED CTE referenced more than once
is not inlined: each reference is a separate TableNode whose body subquery is
resolved independently. The storage-initializing reference can resolve
non-correlated while a later reference resolves correlated (for example
`database` binding to the outer scope). The subsequent-reference branch in
resolveQueryJoinTreeNode only verified column structure, not correlation, so
the correlated clone slipped through. Its PLACEHOLDER nodes (correlated-column
markers) are never decorrelated on the materialized-CTE build path and reach
ExpressionActions::execute, aborting the server in debug builds with 'Trying
to execute PLACEHOLDER action'.

Add the correlation check to the subsequent-reference branch so every
reference is rejected uniformly, matching the IN-subquery and first-reference
paths. The shared check is extracted into a helper.

Related: ClickHouse#105501
@groeneai
groeneai force-pushed the fix-placeholder-materialized-cte branch from 62abf5f to 3229484 Compare July 15, 2026 11:49
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 3229484

CI fully finished (Finish Workflow pass). The only red job is the fleet-wide host-OOM window; not PR-caused.

Check / test Reason Owner / fixing PR
Stateless tests (amd_asan_ubsan, distributed plan, parallel) / unrelated tests host-OOM (Code 241 (total) memory limit exceeded, RSS ~41.84 GiB host cap) #110503 (ours, open)
Mergeable Check aggregate of the above #110503 (ours, open)

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 9b91125

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel) / 01666_merge_tree_max_query_limit flaky, trunk — under parallel replicas one statement becomes several reads of the same table on this server, each with a different query id, so the long-running holder query competes against itself for the single max_concurrent_queries slot and is rejected instead of holding it #112385 (ours, open)

The earlier partial fix #111528 (pin max_threads = 1 on the holder query) is present on this
head and does not cover the parallel-replicas route, so #112385 disables parallel replicas for
this test outright.

Session id: cron:our-pr-ci-monitor:20260729-103000

Comment thread src/Analyzer/Resolve/QueryAnalyzer.cpp Outdated
Comment on lines +145 to +152
/// A MATERIALIZED CTE is materialized once into a temporary table, so its body cannot
/// depend on outer-scope columns: a correlated body would need a different materialization
/// per call site. A correlated body also leaves PLACEHOLDER nodes (correlated-column
/// markers) in its ActionsDAG that the materialized-CTE build path never decorrelates,
/// so they reach `ExpressionActions::execute` and throw `Trying to execute PLACEHOLDER
/// action`. Reject it at analysis time instead. The check must run for every reference,
/// because two clones of the same body can resolve differently (one non-correlated, one
/// correlated) and only the correlated clone must be rejected.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make comment shorter

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in b2da7ee - cut to two lines, the rest moved into the commit message.

@novikd novikd self-assigned this Jul 30, 2026
Per review feedback, keep only the invariant that is not obvious at the call
site and move the root-cause narrative here.

A MATERIALIZED CTE is materialized once into a temporary table, so its body
cannot depend on outer-scope columns: a correlated body would need a different
materialization per call site. A correlated body also leaves PLACEHOLDER nodes
(correlated-column markers) in its `ActionsDAG` that the materialized-CTE build
path never decorrelates, so they reach `ExpressionActions::execute` and throw
`Trying to execute PLACEHOLDER action`. The check therefore runs at analysis
time, and it must run for every reference: when a MATERIALIZED CTE is
referenced more than once it is not inlined, so each reference resolves its own
clone of the body and the clones can resolve differently (one non-correlated,
one correlated). Only the correlated clone must be rejected.

No functional change.

Co-Authored-By: Claude Fable 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.50% 86.50% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.60% 78.60% +0.00%

Changed lines: Changed C/C++ lines covered: 20/20 (100.00%) · Uncovered code

Full report · Diff report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - b2da7ee

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Integration tests (arm_binary, distributed plan, 2/4) / test_storage_s3_queue/test_system_stop.py::test_stopped_table_releases_hash_ring_slot server abort in ObjectStorageQueueSource::FileIterator::next (out-of-bounds element access when compacting file_metadatas after a partial batch); the Code: 210 connection resets in the traceback are downstream of that abort #108977 (mine, open)
Integration tests (arm_binary, distributed plan, 2/4) / test_storage_s3_queue/test_system_stop.py::test_refresh_survives_unready_dependencies same abort, same job: the setup DROP TABLE IF EXISTS hits the reset left by the first test. Both tests fail in the same check run, one abort, not two defects #108977 (mine, open)

All 174 check-runs on this commit are completed and this is the only failing check. Not caused by
this PR: the diff rejects a correlated MATERIALIZED CTE reused in a JOIN at analysis time and does
not touch the object-storage queue code. Over the last 30 days each of these two tests failed on 44
distinct pull requests plus 2 master commits, and #108977 is not an ancestor of this head, so
recurrence here is expected until it lands.

Session id: cron:our-pr-ci-monitor:20260730-233000

@clickhouse-gh

clickhouse-gh Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Dear @novikd, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@clickhouse-gh clickhouse-gh Bot added the comp-query-analyzer Semantic analysis + logical/physical planning + rewrites (Analyzer and Planner modules). label Sep 4, 2026
@novikd novikd self-assigned this Sep 8, 2026
@novikd

novikd commented Sep 8, 2026

Copy link
Copy Markdown
Member

@groeneai merge fresh master into the branch

groeneai and others added 2 commits September 8, 2026 15:35
`ExpressionActions::execute` throws `Exception(ErrorCodes::LOGICAL_ERROR,
"Trying to execute PLACEHOLDER action")`, and `Exception::Exception` only calls
`abortOnFailedAssertion` for a `LOGICAL_ERROR` in a debug or sanitizer build, so
the test comment that said a surviving `PLACEHOLDER` "aborts the server" claimed
more than the release build does. The in-tree rulebook also asks for literal SQL
keywords, class and function names and log-message excerpts in inline code
blocks, and for logical errors to be called exceptions rather than crashes;
`MATERIALIZED`, `TableNode`, `PLACEHOLDER`, `ExpressionActions::execute` and the
message text were bare.

Comments only, no functional change.

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai

groeneai commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author

Merged master (af30b32e) into the branch; new head 36fb80ef. The push also carries one comment-only commit: the reused-CTE comments now call the surviving PLACEHOLDER a LOGICAL_ERROR exception (only debug and sanitizer builds abort) and put the literal names in inline code, no functional change.

@clickhouse-gh

clickhouse-gh Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing fb7e0c59e with master fe1a91eac (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 129e4b59b; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 18 s compile time in total, 7 of them have a recent master baseline.

Job report

@groeneai

groeneai commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 36fb80e

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Integration tests (amd_asan_ubsan, db disk, old analyzer, 1/6) / Timeout job-level session-timeout overrun: the single failing row is the synthetic Timeout one with ERROR: session-timeout occurred during test execution, reported alongside 1218 passing tests and zero individual test failures #118384 (mine, open)
Mergeable Check, PR aggregators with no failure of their own, both rolling up the shard above #118384 (mine, open)

Not caused by this PR: the shard overran its wall-clock budget with every test it ran passing, and
the diff here changes one analyzer path plus one stateless test, nothing on the integration-test
timing surface. #118384 raises that job family's parallel session bound from 7200 to 9000 seconds.

Session id: cron:our-pr-ci-monitor:20260909-000033

…#118851)

A correlated MATERIALIZED CTE that survives on a subsequent reference keeps
its PLACEHOLDER nodes, and those have two reachable tripwires, not one.

The cases already in this file reach ExpressionActions::execute and throw
"Trying to execute PLACEHOLDER action": their CTE bodies do not aggregate, so
the plan never enters the aggregation hash-table cache-key pass. Issue ClickHouse#118851
reports the other one: with an aggregating CTE body, query-plan optimization
serializes the sub-plan's ActionsDAG to hash it
(setAggregationHashTableCacheKeys -> calculateHashFromStep ->
ActionsDAG::serialize), and serialize has no case for ActionType::PLACEHOLDER,
so it throws "Unknown node type 5" before execution is reached.

Measured on a pristine master debug build, the new case aborts with
"Logical error: 'Unknown node type 5'" through exactly the stack the issue
reports (ActionsDAG.cpp:4614 <- calculateHashTableCacheKeys.cpp:116/354/408 <-
optimizeTree.cpp:321), and on this branch it is rejected at analysis time with
"Materialized CTE 'rs' cannot be correlated. (UNSUPPORTED_METHOD)".

Two shape decisions are measured rather than stylistic. The existing Memory
table users_04322 reaches the pass, so no new table is needed: a MergeTree
variant produces an identical abort and stack. Dropping the aggregation, or
turning off either collect_hash_table_stats_during_aggregation or
collect_hash_table_stats_during_joins, moves the query back onto the execution
tripwire the file already covers, which is why the body aggregates and the two
settings are pinned at query level where randomization cannot override them.

The route is not debug-only: on official 26.8.2.7 (LTS) and 26.9.1.1013 the
issue's query returns Code: 49 "PLACEHOLDER action node must be removed before
query plan optimization", needing one non-default setting,
enable_materialized_cte = 1.
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 12, 2026
Merged via the queue into ClickHouse:master with commit e8d1267 Sep 12, 2026
175 checks passed
@alexey-milovidov

Copy link
Copy Markdown
Member

Recurred on master today, in a new and more reliable way: the AST fuzzer inside Stress test (amd_debug) mutated a stateless test that landed in master yesterday, so this shape now has a standing generator in CI.

Report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=a6fe14f068a998079aea4a1b3e7409004726e042&name_0=MasterCI&name_1=Stress%20test%20%28amd_debug%29 (Logical error: Trying to execute PLACEHOLDER action, STID 1611-37da, master at a6fe14f068a)

The fatal (clickhouse-server.err.log) is the familiar ExpressionActions.cpp:797 -> ExpressionTransform::transform route. The query, from query_log for query id afffeb58-08ba-48dd-bfd5-e4bc72e33537:

SELECT count() FROM t_lwu_materialized_cte
WHERE v IN (WITH c AS MATERIALIZED (SELECT database, number AS x FROM numbers(3)) SELECT a.x FROM c AS a, c AS b)

log_comment is 05182_lightweight_update_materialized_cte_in_subquery.sql, added to master in 781d270 (PR #119489, merged today). That test already reuses a materialized CTE in a comma join (FROM c AS a, c AS b); the fuzzer only added database to the CTE body, which is exactly the ingredient this PR is about. So every Stress test / AST fuzzer run over that test can now produce this abort until this PR merges.

Reduced to one statement, no table needed, only enable_materialized_cte:

SET enable_analyzer = 1, enable_materialized_cte = 1;
WITH c AS MATERIALIZED (SELECT database, number AS x FROM numbers(3)) SELECT count() FROM c AS a, c AS b;
-- Code: 49. DB::Exception: Trying to execute PLACEHOLDER action:
-- while executing 'PLACEHOLDER __table1.database -> __table1.database String : 1'. (LOGICAL_ERROR)

EXPLAIN QUERY TREE on master shows precisely the divergence this PR fixes — the first clone binds database to currentDatabase(), the second binds it to the first clone's projection column and becomes correlated:

TABLE id: 4, alias: __table1, ... temporary_table_name: _materialized_cte_c_...
  MATERIALIZED CTE SUBQUERY
    QUERY id: 5, ... cte_name: c
      PROJECTION
        FUNCTION id: 7, function_name: currentDatabase, ...
TABLE id: 12, alias: __table4, ... temporary_table_name: _materialized_cte_c_...
  MATERIALIZED CTE SUBQUERY
    QUERY id: 13, ... cte_name: c, is_correlated: 1
      CORRELATED COLUMNS
        COLUMN id: 15, column_name: database, result_type: String, source_id: 4

Verified against this PR's own Build (arm_release) artifact for fb7e0c59e9:

  • the reduced statement and the full fuzzed query from CI both now fail cleanly with Code: 1 ... Materialized CTE 'c' cannot be correlated ... (UNSUPPORTED_METHOD);
  • the non-correlated reuse shapes of 05182 still work (SELECT count() ... IN (WITH c AS MATERIALIZED ... FROM c AS a, c AS b) returns 3, and the in-place UPDATE ... WHERE id IN (...) variant gives the reference rows). The rest of 05182 cannot run on this branch yet because its base predates Fix missing materialized-CTE gate in lightweight UPDATE/DELETE set subqueries #119489, which is what plants the mutation-plan gate — unrelated to this change.

The PR is green (156 pass / 19 skipped) and approved since 2026-07-30. Worth merging.

@clickgapai

Copy link
Copy Markdown
Contributor

@groeneai @novikd @alexey-milovidov — ClickGap found the following in this PR:

Close anything that's wrong or already addressed.

groeneai added a commit to groeneai/ClickHouse that referenced this pull request Sep 13, 2026
…ransformer-alias-on-asterisk

One conflicted file, src/Analyzer/Resolve/QueryAnalyzer.cpp, resolved as a union of
two independent additions at the same two insertion points.

Anonymous namespace: master's checkMaterializedCTESubqueryIsNotCorrelated (ClickHouse#108883)
and this branch's isUntupleExpansion / getTupleElementName helpers. Kept both,
master's first.

resolveMatcher LAMBDA branch: master's node_to_projection_name.emplace seed
(ClickHouse#118825) and this branch's BAD_ARGUMENTS guard for a prefixed APPLY whose lambda
body is a bare matcher. Kept both, the guard first so the rejected query does not
register a projection name on its way out. The seed publishes the pre-transformer
name of the matched column, which is what a later bare matcher must still see; the
prefixed name is published on this chain's private clone further down, so the two
writes do not compete.

Verified the branch delta to that file is unchanged by the resolution: the 174
changed lines of git diff <merge-base>..HEAD are set-identical to git diff
origin/master..<resolved>.

Co-Authored-By: Claude Opus 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-query-analyzer Semantic analysis + logical/physical planning + rewrites (Analyzer and Planner modules). groeneai-origin-review-human PR origin: human review feedback on a groeneai PR pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logical error Unknown node type 5: ActionsDAG::serialize does not handle PLACEHOLDER nodes when hashing aggregation steps

5 participants