Repository navigation
Conversation
antiguru
added this pull request to stack #39604
October 6, 2026 20:24
Allow `CREATE MATERIALIZED VIEW` to declare its schema with column definitions, behind the `enable_materialized_view_column_definitions` feature flag. A declared schema is the materialized view's `RelationDesc`, independent of what the optimizer infers, both on creation and when the `create_sql` is re-planned. The query is cast to the declared types with assignment casts, and declared `NOT NULL` columns are checked at runtime as non-null assertions. `PRIMARY KEY` and `UNIQUE` are not supported yet. A replacement for a materialized view with a declared schema has to declare one too, and `mz-deploy` unit tests apply the declared types with casts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
antiguru
force-pushed
the
claude/mv-declared-schema-impl
branch
from
October 7, 2026 07:04
ba2710a to
4b7f9de
Compare
antiguru
removed this pull request from stack #39604
October 7, 2026 07:04
antiguru
added this pull request to stack #39622
October 7, 2026 07:04
This branch has not been deployed
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.
Implements the design in #39596:
CREATE MATERIALIZED VIEW mv (a int8 NOT NULL, b text) AS ..., behindenable_materialized_view_column_definitions(off in production, on in CI).A declared schema is the materialized view's
RelationDesc, independent of what the optimizer infers, both on creation and when thecreate_sqlis re-planned on boot. The query is cast to the declared types with assignment casts, asINSERT ... SELECTdoes, and declaredNOT NULLcolumns become non-null assertions, so a violation is a query error rather than a persist encoder panic.PRIMARY KEYandUNIQUEare rejected here and added in #39621.A replacement for a materialized view with a declared schema must declare one too, so applying it cannot turn the schema back into an inferred one.
mz-deployunit tests run a declared materialized view with casts to its declared types.Release notes
None, the feature is behind a flag.
🤖 Generated with Claude Code