Repository navigation
Fix a crash and lost rows on INSERT when a row policy of a table read by a materialized view uses IN <source table> - #125893
Conversation
…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]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding) plus my own cold review of the diff (no code findings).
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20261014-214100 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261014-201400 |
|
Workflow [PR], commit [057ccb9] Summary: ✅
AI ReviewSummaryThis PR restores inserted-block substitution in materialized-view filter subqueries, preventing a server crash with Final VerdictStatus: ✅ Approve |
|
cc @novikd @al13n321, could you review this and add |
6ce833a
Backport #125893 to 26.10: Fix a crash and lost rows on INSERT when a row policy of a table read by a materialized view uses `IN <source table>`
Cherry-pick of #125893 onto 26.3: only the include block of Planner/Utils.cpp conflicted; add the InterpreterSelectQueryAnalyzer.h include. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry-pick of #125893 onto 26.7: only the include block of Planner/Utils.cpp conflicted; add the InterpreterSelectQueryAnalyzer.h include. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry-pick of #125893 onto 26.8: only the include block of Planner/Utils.cpp conflicted; add the InterpreterSelectQueryAnalyzer.h include. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry-pick of #125893 onto 26.9: only the include block of Planner/Utils.cpp conflicted; add the InterpreterSelectQueryAnalyzer.h include. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…row policy of a table read by a materialized view uses `IN <source table>`
…row policy of a table read by a materialized view uses `IN <source table>`
…row policy of a table read by a materialized view uses `IN <source table>`
…row policy of a table read by a materialized view uses `IN <source table>`
Backport #125893 to 26.9: Fix a crash and lost rows on INSERT when a row policy of a table read by a materialized view uses `IN <source table>`
Backport #125893 to 26.8: Fix a crash and lost rows on INSERT when a row policy of a table read by a materialized view uses `IN <source table>`
Backport #125893 to 26.3: Fix a crash and lost rows on INSERT when a row policy of a table read by a materialized view uses `IN <source table>`
…ilters `buildFilterQueryTree` swapped the inserted block into the tree of a row policy or of `additional_table_filters` (ClickHouse#125893) whenever the context had a view source, so inside a materialized view the input query of `executable` or a `loop` read the table while the policy of the table it read used the inserted block (`x NOT IN (SELECT x FROM src)` kept rows the stored table excludes). It now uses `getViewSourceForSubqueries`, like the IN and scalar subquery paths: the view query, and its replan for a `Merge` child or a `Buffer`, still read the block. Two arms in 05389 read a table with such a policy directly through `executable` and `loop`, and the `merge_in` arm becomes `merge_not_in`, so a `Merge` branch that silently returns nothing cannot pass it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Backport #125893 to 26.7: Fix a crash and lost rows on INSERT when a row policy of a table read by a materialized view uses `IN <source table>`
Related: #123514
Related: #124740
Related: #125610
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a server crash (or missing rows in the view, with a
Nullsource table) onINSERTinto the source table of a materialized view when a row policy oradditional_table_filtersof a table read by the view references the source table, e.g.USING x IN src.Description
On 26.9.16.11, when a row policy or
additional_table_filtersof a table read by a materialized view usesIN <source table>, anINSERTinto the source crashes the server (MergeTreesource) or the view writes no rows (Nullsource). 26.9.9.28 and 26.3.42.3 return the expected rows. No related open issue found.Since #123514 the resolver gives a reference to the view's source table the catalog storage with the view source's metadata (no primary key), and relies on
replaceStorageInQueryTreeto swap the inserted block in after the passes.buildFilterQueryTree, which builds the trees of row policies,additional_table_filters,parallel_replicas_custom_keyandadditional_result_filter, never did the swap, so theINset was built by reading the realMergeTreewith key-less metadata.The fix does the swap in
buildFilterQueryTree, with the guard the scalar-subquery path uses: the inner query of an ordinary view reads the table (05345). The filter reads the inserted block again, as before #123514 and asIN (SELECT x FROM src)does today.The new test crashes the unfixed server, passes 50/50 with randomized settings and 20/20 with
--replicated-databaseand with parallel replicas; 26.9.9.28 and 26.3.42.3 produce its reference unchanged.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/125893]
Version info
26.11.1.195-master(included in26.11and later)26.10.2.20,26.9.23.5,26.8.32.7,26.7.36.11,26.3.57.7