Repository navigation
Analyze projection queries without parallel replicas, so an IN subquery is not replaced with a temporary table - #129836
Conversation
`ProjectionDescription::fillProjectionDescriptionByQuery` analyzes the projection query with `InterpreterSelectQuery(...).modify()`, which rewrites `query_ast` in place, and `calculateByQuery` executes that AST for every `INSERT`. When the context enables parallel replicas, `ExpressionAnalyzer` treats the source as remote and `GlobalSubqueriesVisitor` replaces an `IN` or `GLOBAL IN` subquery with the name of a temporary table `_data_<hash>`. That table exists only while the analysing query runs, so every later `INSERT` fails with `UNKNOWN_IDENTIFIER`. `CREATE TABLE` and server startup analyze the projection with the global context, so a default profile with parallel replicas breaks it (this is the ParallelReplicas CI job, where `05515_global_subquery_projection_where` fails on every run); `ALTER TABLE ... ADD PROJECTION` uses the query context, so session settings break it in every configuration. With `parallel_replicas_allow_in_with_subquery = 0` in the default profile the same branch calls `getQueryContext()` on a global context copy and `CREATE TABLE` fails with `THERE_IS_NO_QUERY`. A projection is always calculated locally from the block being written, so disable parallel replicas for its analysis, as `MutationsInterpreter` does for its synthetic queries. The test now also adds projections with `ALTER TABLE` under session parallel replicas, which fails without the fix in every configuration; the comments that described the replacement as expected behaviour are corrected. Related: ClickHouse#129425 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the parallel replicas comment in fillProjectionDescriptionByQuery to one line. 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 cold review (1 nit).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-48:20261106-215100 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261106-210600 |
|
cc @KochetovNicolai @devcrafter, could you review this and add the |
|
Workflow [PR], commit [ed4362a] Summary: ❌
AI ReviewSummaryPR #129836, reviewed at Missing context / blind spots
Final VerdictStatus: ✅ Approve. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 17 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger - ed4362aEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
No job was dropped, and Session id: cron:our-pr-ci-monitor:20261107-023005 |
|
Fixing PR for |
|
Superseded by #129863 (merged), which makes the same change in |
Related: #129425
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
INSERTfailing withUNKNOWN_IDENTIFIERinto a table with a projection whose query has anINorGLOBAL INsubquery, when the projection was analyzed with parallel replicas enabled: in the server's default profile (atCREATE TABLEor at server startup), or in the session ofALTER TABLE ... ADD PROJECTION.Description
On 26.10.2.103,
ALTER TABLE t ADD PROJECTION p (SELECT a, b WHERE b IN (SELECT b FROM src) ORDER BY b)run withenable_parallel_replicas = 1succeeds, and then everyINSERT INTO tfails withCode: 47 ... Unknown expression or table expression identifier _data_<hash>. A server whose default profile enables parallel replicas does the same atCREATE TABLEand at startup, which is why05515_global_subquery_projection_where(#129425) fails on every master run of the ParallelReplicas job: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=4088c421fd27f2ea45bdbf87b2df9233debcfcdd&name_0=MasterCI&name_1=Stateless%20tests%20%28arm_binary%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29ProjectionDescription::fillProjectionDescriptionByQueryanalyzes the projection query withInterpreterSelectQuery(...).modify(), which rewrites the storedquery_astin place. With parallel replicas enabled,GlobalSubqueriesVisitorhandles the source as remote and replaces the subquery with the name of a temporary table, which does not exist when anINSERTlater calculates the projection. The fix disables parallel replicas for that analysis, asMutationsInterpreterdoes for its synthetic queries: a projection is always calculated locally. It also stopsCREATE TABLEwith such a projection from failing withTHERE_IS_NO_QUERYwhen the default profile hasparallel_replicas_allow_in_with_subquery = 0.Validation: the test now also adds two projections with
ALTER TABLEunder parallel replicas; it fails on master in every configuration and passes with the fix (50/50 randomized runs, 10/10 with the ParallelReplicas profile). With the fix, inserting with parallel replicas enabled, restarting into that profile, and reading an aggregate projection with parallel replicas on and off all work, and theprojectiontests show no other difference.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/129836]