Repository navigation
Fix mv source engine checks - #123514
Fix mv source engine checks#123514
Conversation
|
Workflow [PR], commit [dbabf63] Summary: ✅
AI ReviewSummaryThis PR separates materialized-view source typing from engine-aware source-table checks by keeping the catalog storage in Findings
Final Verdict
LLVM Coverage ReportMeasured on commit dbabf63.
Changed lines: Changed C/C++ lines covered: 13/13 (100.00%) · Uncovered code |
| if (auto view_source = context->getViewSource(); | ||
| view_source && !context->isViewInnerQuery() | ||
| && view_source->getStorageID().getFullNameNotQuoted() == storage_id.getFullNameNotQuoted()) | ||
| metadata_snapshot = view_source->getInMemoryMetadataPtr(context, false); |
There was a problem hiding this comment.
tryResolveTableIdentifier now keeps the catalog storage here, but the IN (subquery) rewrite still swaps matching source-table references back to view_source during the resolve pass in src/Analyzer/Resolve/resolveFunction.cpp:2434. ShardNumColumnToFunctionPass runs after resolve, so a materialized-view self-reference like ... IN (SELECT _shard_num FROM dist_src) is still seen as StorageValues there and _shard_num will not be rewritten for a Distributed source. If the intent is that analyzer passes see the real table again, this path needs the same treatment as the one in this patch: keep the catalog storage until replaceStorageInQueryTree, or transplant only the metadata snapshot instead of calling updateStorage.
There was a problem hiding this comment.
The IN rewrite with updateStorage(view_source) predates #122345 and is untouched by both PRs, so _shard_num inside IN (SELECT … FROM dist_src) behaves exactly as before; it is not part of #123270.
Types are consistent there (the subquery resolves with the block metadata before the storage is replaced by the same StorageValues). Deferring that swap to replaceStorageInQueryTree is not a drop-in change, because the post-pass swap does not visit IN subqueries; it would turn IN into a read of the whole table.
If _shard_num in IN over a Distributed MV source matters, it should be a separate issue.
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, 11 s compile time in total, 7 of them have a recent master baseline. |
78f684e to
82eabe3
Compare
…ysis, take only the types from the inserted block
82eabe3 to
dbabf63
Compare
c9d4edb
Backport #123514 to 26.9: Fix mv source engine checks
Backport #123514 to 26.8: Fix mv source engine checks
Since ClickHouse#123514, `tryResolveTableIdentifier` resolves every reference to the source table of a materialized view, outside view inner queries, to the catalog storage with the view source metadata (columns only, no primary key), relying on `replaceStorageInQueryTree` to swap the view source in after the passes. That swap only walked the join trees, so a reference in a correlated subquery, as the right side of `IN` (`k IN src`), or in a non-leftmost table of an `IN` subquery was planned as a `MergeTree` read with that metadata, and `KeyCondition` dereferenced the missing primary key expression: an INSERT into the source table crashed the server. When the storage being swapped in is the context's view source, walk the whole query tree, including subqueries in expressions, still stopping at view inner queries and table function arguments. These references read the pushed block again, as with ClickHouse#122345 and the old analyzer. Other callers (Buffer, header computation) keep the join-tree walk. Closes ClickHouse#124647 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…w's source table Since ClickHouse#123514 `tryResolveTableIdentifier` resolves the source table of a materialized view (outside view inner queries) to the catalog storage with the view source's metadata, and relies on `replaceStorageInQueryTree` to swap the inserted block in after the passes. `buildFilterQueryTree`, which builds the query tree of every row policy, `additional_table_filters`, `parallel_replicas_custom_key` and `additional_result_filter`, never did the swap. A filter like `x IN src` (or an `IN` subquery reading `src` as a non-leftmost table) under an MV push therefore planned a read of the real `MergeTree` with key-less metadata, and `KeyCondition` dereferenced the missing primary key expression (SIGSEGV). With a source engine without index analysis (`Null`) the filter read the empty table instead of the block, and the view wrote no rows. Do the swap in `buildFilterQueryTree`, with the same guard as the analysis-time scalar subquery path: the inner query of an ordinary view reads the table, not the block (05345). Co-Authored-By: Claude Opus 5.5 <[email protected]>
… and `executable` under a materialized view Inside a materialized view query, `tryResolveTableIdentifier` (ClickHouse#123514) types every reference to the view source table by the view source metadata (`StorageValues`, no primary key) while keeping the catalog storage, and relies on `replaceStorageInQueryTree` to swap the view source in after the passes. That swap only happens for an interpreter given the view source as its storage. Three reads re-analyze an AST under a copy of the push context without one: a `Merge` child planned by a nested interpreter (a `Distributed` sibling raises the read above `FetchColumns`), the inner query of `loop`, and the input queries of `executable`. The catalog `MergeTree` was then planned with key-less metadata and `KeyCondition` dereferenced a null primary key expression (SIGSEGV, STID 1288-3bd5). The same holds for the `APPEND` refresh of a refreshable view into the source table. Pass the view source as the interpreter's storage at these three sites, as `interpretSubquery` and `ExecuteScalarSubqueriesVisitor` already do. The nested re-analysis reads the inserted block again, as before ClickHouse#123514 and as the old interpreter did. The context is unchanged, so row-policy subqueries of a `Merge` child keep reading the inserted block (05321), the local shard of a `Distributed` read keeps reading the table (05294) and ordinary view inner queries are unaffected. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… and `executable` under a materialized view Inside a materialized view query, `tryResolveTableIdentifier` (ClickHouse#123514) types every reference to the view source table by the view source metadata (`StorageValues`, no primary key) while keeping the catalog storage, and relies on `replaceStorageInQueryTree` to swap the view source in after the passes. That swap only happens for an interpreter given the view source as its storage. Three reads re-analyze an AST under a copy of the push context without one: a `Merge` child planned by a nested interpreter (a `Distributed` sibling raises the read above `FetchColumns`), the inner query of `loop`, and the input queries of `executable`. The catalog `MergeTree` was then planned with key-less metadata and `KeyCondition` dereferenced a null primary key expression (SIGSEGV, STID 1288-3bd5). Pass the view source as the interpreter's storage at these three sites, as `interpretSubquery` and `ExecuteScalarSubqueriesVisitor` already do. The nested re-analysis reads the inserted block again, as before ClickHouse#123514 and as the old interpreter did. The context is unchanged, so row-policy subqueries of a `Merge` child keep reading the inserted block (05321), the local shard of a `Distributed` read keeps reading the table (05294) and ordinary view inner queries are unaffected. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #123270
Caused by: #122345
#122345 resolved the source table of a materialized view directly to the
StorageValuesholding the pushed block, so that the view query is typed by the block. That node also served every engine check of the analysis:FINAL/SAMPLEwere validated againstStorageValues, which supports neither, and_shard_numover aDistributedsource was no longer rewritten.The two roles are now separate: the catalog table stays the storage of the
TableNode, and only the metadata (column types) is taken from the view source. The existing post-passreplaceStorageInQueryTreestill swaps the view source in for execution, as before #122345.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
INSERTfailing withILLEGAL_FINALorSAMPLING_NOT_SUPPORTEDwhen a materialized view appliesFINALorSAMPLEto its own source table inside a subquery. Regression in #122345.Workflow [PR]
Sync PR [sync-upstream/pr/123514]
Version info
26.10.1.1832-master(included in26.10and later)26.9.13.18,26.8.21.12