Skip to content

sql: declared schemas for materialized views - #39600

Draft
antiguru wants to merge 1 commit into
mv-schema/explain-schemafrom
claude/mv-declared-schema-impl
Draft

antiguru wants to merge 1 commit into
mv-schema/explain-schemafrom
claude/mv-declared-schema-impl

Conversation

@antiguru

@antiguru antiguru commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Implements the design in #39596: CREATE MATERIALIZED VIEW mv (a int8 NOT NULL, b text) AS ..., behind enable_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 the create_sql is re-planned on boot. The query is cast to the declared types with assignment casts, as INSERT ... SELECT does, and declared NOT NULL columns become non-null assertions, so a violation is a query error rather than a persist encoder panic. PRIMARY KEY and UNIQUE are 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-deploy unit 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

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
antiguru force-pushed the claude/mv-declared-schema-impl branch from ba2710a to 4b7f9de Compare October 7, 2026 07:04
@antiguru
antiguru removed this pull request from stack #39604 October 7, 2026 07:04
@antiguru
antiguru changed the base branch from main to mv-schema/explain-schema October 7, 2026 07:04
@antiguru
antiguru added this pull request to stack #39622 October 7, 2026 07:04

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants