Skip to content

Commit

Permalink
sql: set GLOBAL on MATERIALIZED VIEW tables on first ADD REGION
Browse files Browse the repository at this point in the history
Release note (sql change): Materialized views which are in a database
before the first ADD REGION will become GLOBAL on ADD REGION, in line
with the behavior of CREATE MATERIALIZED VIEW on a multi-region
database.
  • Loading branch information
otan committed Mar 18, 2021
1 parent 101824a commit 7fbb939
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
6 changes: 5 additions & 1 deletion pkg/ccl/logictestccl/testdata/logic_test/multi_region
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,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"
Expand All @@ -1332,6 +1333,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;
Expand All @@ -1345,6 +1347,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
Expand Down Expand Up @@ -1373,6 +1376,7 @@ table_name locality
t NULL
s NULL
v NULL
mat_view NULL
s2 NULL
v2 NULL
mat_view2 NULL
16 changes: 12 additions & 4 deletions pkg/sql/alter_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,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 {
Expand Down

0 comments on commit 7fbb939

Please sign in to comment.