Skip to content

Convert mz_columns and mz_index_columns to builtin mvs - #39427

Draft
SangJunBak wants to merge 8 commits into
jun/durable-columnfrom
jun/sql-494-convert-mz_columns-and-mz_index_columns-to-catalog-views
Draft

SangJunBak wants to merge 8 commits into
jun/durable-columnfrom
jun/sql-494-convert-mz_columns-and-mz_index_columns-to-catalog-views

Conversation

@SangJunBak

@SangJunBak SangJunBak commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Closes SQL-494

Description

What does this PR actually do? Focus on the approach and any non-obvious
decisions. The diff shows the code --- use this space to explain what the
diff can't tell a reviewer.

Verification

How do you know this change is correct? Describe new or existing automated
tests, or manual steps you took.

@linear-code

linear-code Bot commented Sep 30, 2026

Copy link
Copy Markdown

SQL-494

@SangJunBak
SangJunBak force-pushed the jun/sql-494-convert-mz_columns-and-mz_index_columns-to-catalog-views branch from a659af0 to 27c8872 Compare October 6, 2026 19:49
@SangJunBak
SangJunBak changed the base branch from main to jun/sql-702/mv-refresh-strat October 6, 2026 19:56
@SangJunBak
SangJunBak added this pull request to stack #38849 October 6, 2026 19:56
@SangJunBak SangJunBak changed the title sql: extract plan_refresh_time from plan_create_materialized_view Refactor mz_columns and mz_index_columns Oct 7, 2026
@SangJunBak
SangJunBak force-pushed the jun/sql-494-convert-mz_columns-and-mz_index_columns-to-catalog-views branch from 27c8872 to 7857df2 Compare October 9, 2026 15:29
@SangJunBak
SangJunBak force-pushed the jun/sql-494-convert-mz_columns-and-mz_index_columns-to-catalog-views branch from 7857df2 to 3a32217 Compare October 9, 2026 15:34
@SangJunBak
SangJunBak force-pushed the jun/sql-494-convert-mz_columns-and-mz_index_columns-to-catalog-views branch from 3a32217 to 27a429d Compare October 13, 2026 17:38
@SangJunBak
SangJunBak force-pushed the jun/sql-494-convert-mz_columns-and-mz_index_columns-to-catalog-views branch from 27a429d to 3c03c63 Compare October 14, 2026 08:57
Base automatically changed from jun/sql-702/mv-refresh-strat to main October 14, 2026 10:25
@SangJunBak SangJunBak added the ci-nightly PR CI control: also trigger Nightly label Oct 14, 2026
@SangJunBak
SangJunBak force-pushed the jun/sql-494-convert-mz_columns-and-mz_index_columns-to-catalog-views branch 3 times, most recently from d50422a to 2194479 Compare October 14, 2026 13:08
SangJunBak and others added 8 commits October 14, 2026 10:34
mz_type_name only knew the PostgreSQL types, since Type::from_oid cannot
reconstruct a list, map or record from an OID alone. Type gains
name_of_oid, which also names Materialize's own types and the list, map and
record pseudo-types, and a test checks it covers every type a column can
present as.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…e_sql

parse_catalog_create_sql reports a table's DEFAULT clauses by column name,
with NULL for a column without one, and an index's key expressions in
index order, so that catalog views can read both without a planner.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Builtin relations have no item in mz_catalog_raw, so a generated
mz_builtin_columns view inlines every builtin relation's declared columns,
its own and mz_builtin_views' included. The keys of builtin indexes and of
the introspection source indexes are resolved against the declared descs
of the relations they index by a generated mz_builtin_index_columns view,
the way mz_builtin_indexes and mz_builtin_log_indexes serve mz_indexes.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…ized views

mz_columns reads the ItemColumn rows each relation records in
mz_catalog_raw: the recorded OID and type modifier present the type through
mz_type_name, and a column of a CREATE TYPE list, map or record takes the
name and OID of that type's item instead. A table's column defaults are the
DEFAULT clauses of its create_sql, read through parse_catalog_create_sql.
Builtin relations' columns come from mz_builtin_columns, joined to the
builtin object mappings.

mz_index_columns reads the IndexColumn rows each index records, with the
key expressions as written in create_sql. Builtin and introspection source
index keys come from mz_builtin_index_columns, joined to the builtin index
mappings and to the per-cluster introspection source index records.

Both packers go away, and each relation gets a replacement migration step.

Closes: SQL-494

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…materialized views

Plans, builtin object listings and OIDs change with the two relations
becoming materialized views and with the generated mz_builtin_columns and
mz_builtin_index_columns views.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The sqllogictests pin the schema, the builtin, introspection and user rows
for every relation kind and key shape, and retraction. Their expectations
were captured from the builtin tables before the conversion and hold for
the views, except that a table's defaults read as written.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The ItemColumns platform check creates tables, views, materialized views
and indexes with column and expression keys in every phase, adds columns
with ALTER TABLE, and comments on columns. It then checks what mz_columns
and mz_index_columns report and that the reported positions join with the
comments. In the upgrade scenarios the objects created before the upgrade
get their recorded rows from the bootstrap refresh.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…x-selects

The mz_type_name body change makes the scalar function registry source
snapshot stale. mz_columns.slt and mz_index_columns.slt assert on allocated
item ids and type OIDs and list every user object, which --auto-index-selects
perturbs by creating wrapper views and indexes.
@SangJunBak
SangJunBak force-pushed the jun/sql-494-convert-mz_columns-and-mz_index_columns-to-catalog-views branch from 2194479 to ea159b9 Compare October 14, 2026 14:40
@SangJunBak
SangJunBak removed this pull request from stack #38849 October 14, 2026 14:41
@SangJunBak
SangJunBak changed the base branch from main to jun/durable-column October 14, 2026 14:41
@SangJunBak
SangJunBak added this pull request to stack #39819 October 14, 2026 14:41
@SangJunBak SangJunBak changed the title Refactor mz_columns and mz_index_columns Convert mz_columns and mz_index_columns to builtin mvs Oct 14, 2026

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

ci-nightly PR CI control: also trigger Nightly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant