diff --git a/pkg/ccl/logictestccl/testdata/logic_test/multi_region b/pkg/ccl/logictestccl/testdata/logic_test/multi_region index 5bf86ecd8a87..ca73aaea8b0b 100644 --- a/pkg/ccl/logictestccl/testdata/logic_test/multi_region +++ b/pkg/ccl/logictestccl/testdata/logic_test/multi_region @@ -1259,7 +1259,8 @@ statement ok CREATE TABLE t (id INT PRIMARY KEY, a INT, b INT); INSERT INTO t VALUES (1, 2, 3), (4, 5, 6); CREATE SEQUENCE s; -CREATE VIEW v AS SELECT id, a, b FROM t +CREATE VIEW v AS SELECT id, a, b FROM t; +CREATE MATERIALIZED VIEW mat_view AS SELECT id, a, b FROM t statement ok ALTER DATABASE db_with_views_and_sequences SET PRIMARY REGION "ap-southeast-2" @@ -1271,6 +1272,7 @@ table_name locality t REGIONAL BY TABLE IN PRIMARY REGION s REGIONAL BY TABLE IN PRIMARY REGION v REGIONAL BY TABLE IN PRIMARY REGION +mat_view GLOBAL statement ok CREATE SEQUENCE s2; @@ -1284,6 +1286,7 @@ table_name locality t REGIONAL BY TABLE IN PRIMARY REGION s REGIONAL BY TABLE IN PRIMARY REGION v REGIONAL BY TABLE IN PRIMARY REGION +mat_view GLOBAL s2 REGIONAL BY TABLE IN PRIMARY REGION v2 REGIONAL BY TABLE IN PRIMARY REGION mat_view2 GLOBAL @@ -1312,6 +1315,7 @@ table_name locality t NULL s NULL v NULL +mat_view NULL s2 NULL v2 NULL mat_view2 NULL diff --git a/pkg/sql/alter_database.go b/pkg/sql/alter_database.go index 026bbf829773..e37372713d35 100644 --- a/pkg/sql/alter_database.go +++ b/pkg/sql/alter_database.go @@ -592,10 +592,18 @@ func addDefaultLocalityConfigToAllTables( return err } - if err := p.alterTableDescLocalityToRegionalByTable( - ctx, tree.PrimaryRegionNotSpecifiedName, mutDesc, regionEnumID, - ); err != nil { - return err + if mutDesc.MaterializedView() { + if err := p.alterTableDescLocalityToGlobal( + ctx, mutDesc, regionEnumID, + ); err != nil { + return err + } + } else { + if err := p.alterTableDescLocalityToRegionalByTable( + ctx, tree.PrimaryRegionNotSpecifiedName, mutDesc, regionEnumID, + ); err != nil { + return err + } } if err := p.writeSchemaChangeToBatch(ctx, mutDesc, b); err != nil {