Repository navigation
Fix crash when a materialized view reads its source table through merge with a Distributed table - #129493
Closed
antonio2368 wants to merge 2 commits into
Closed
Fix crash when a materialized view reads its source table through merge with a Distributed table#129493antonio2368 wants to merge 2 commits into
merge with a Distributed table#129493antonio2368 wants to merge 2 commits into
Conversation
…rge` with a `Distributed` table A materialized view (or the `RETURNING` query of an `INSERT`) is analyzed with the inserted block as the view source. `IdentifierResolver::tryResolveTableIdentifier` gave every reference to the source table the metadata of the block, which has no primary key. This is correct only for the references that `replaceStorageInQueryTree` later replaces with the block. A nested analysis also has the view source in its context but does not replace the reference: `ReadFromMerge::createPlanForTable` analyzes the child query again when `merge` also covers a `Distributed` table. That child read the real parts with key-less metadata, and the server crashed in `KeyCondition`. Now the analysis gets the storage that its caller replaces afterwards, and only then does the resolver apply the metadata of the view source. The row policy filter analysis, which replaces the view source after its own analysis, passes it too. Related: #122603 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
|
Workflow [PR], commit [8f85be3] Summary: ⏳
|
antonio2368
added a commit
that referenced
this pull request
Nov 5, 2026
…-snapshot-without-data The fix (#129493) gives the view source metadata only to the references that the caller swaps for the block. This PR takes the snapshot without data only for those references, so nested analyses (such as the children of `merge` with a `Distributed` sibling) keep reading the real parts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The previous commit gave the metadata of the inserted block only to the analyses that got `replaced_storage`. But some nested analyses do not get it and still swap the block in: an `IN` subquery in the child query of `merge`, and the row policy of an inlined view (`analyzer_inline_views`). Such a subquery got the types of the altered source table, but read the block with the old types. The `IN` case gave a `LOGICAL_ERROR` exception in `arrayExists`, and the policy case removed rows. Now every reference to the view source outside view inner queries gets the metadata of the block again, as before the previous commit. The only exception is the root query of the child query of `merge`, because its table reads the real parts: `ReadFromMerge::createPlanForTable` marks it with `SelectQueryOptions::root_query_reads_real_tables`. The mark is a member of `QueryAnalyzer`, not of the context, so nested analyzers do not get it. This removes `replaced_storage`. Related: #129493 (comment) Related: #122603 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
antonio2368
added a commit
that referenced
this pull request
Nov 6, 2026
…ough `merge` with a `Distributed` table" This reverts commit 9696a8c, which came from #129493. Its rule gave the metadata of the inserted block only to analyses that swap it in, but nested analyses that swap in subqueries got the catalog types: #122603 (comment) The crash is fixed in master by #129338. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A materialized view (or the
RETURNINGquery of anINSERT) that reads its source table throughmergecrashed the server whenmergealso covered aDistributedtable. In that case themergechild that reads the real source table got the metadata of the inserted block, which has no primary key.Now the table of the
mergechild query uses the metadata of the real table, because it reads the real parts. All other references to the source table keep the metadata of the inserted block, also in nested analyses that read the block: anINsubquery inside themergechild, or the row policy of an inlined view. This also covers a source table that is altered during the insert.Related: #122603
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a server crash when a materialized view or
INSERT ... RETURNINGreads its source table throughmergetogether with aDistributedtable.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/129493]