Skip to content

Cherry pick #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> - #126682

Merged
PedroTadim merged 2 commits into
backport/26.3/125893from
cherrypick/26.3/125893
Oct 19, 2026
Merged

PedroTadim merged 2 commits into
backport/26.3/125893from
cherrypick/26.3/125893

Conversation

@robot-clickhouse

Copy link
Copy Markdown
Member

Original pull-request #125893

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

groeneai and others added 2 commits October 14, 2026 21:31
…w's source table

Since #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]>
…lters

Fix a crash and lost rows on INSERT when a row policy of a table read by a materialized view uses `IN <source table>`
@robot-clickhouse robot-clickhouse added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Oct 19, 2026
@PedroTadim
PedroTadim merged commit f7b7419 into backport/26.3/125893 Oct 19, 2026
173 of 174 checks passed
@PedroTadim
PedroTadim deleted the cherrypick/26.3/125893 branch October 19, 2026 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants