Skip to content

Commit

Permalink
backupccl: support materialized view mutation in restore
Browse files Browse the repository at this point in the history
Release note (bug fix): Fixed a bug that could prevent RESTORE from
working if the backup had a refresh materialized view mutation in it.
  • Loading branch information
rafiss committed Apr 27, 2023
1 parent 2066afb commit e4b74b8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/ccl/backupccl/restore_schema_change_creation.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ func jobDescriptionFromMutationID(
}
}
jobDescBuilder.WriteString(")")
case *descpb.DescriptorMutation_MaterializedViewRefresh:
jobDescBuilder.WriteString("refreshing materialized view with primary key ")
jobDescBuilder.WriteString(t.MaterializedViewRefresh.NewPrimaryIndex.Name)
default:
return "", 0, errors.Newf("unsupported mutation %+v, while restoring table %+v", m, tableDesc)
}
Expand Down
42 changes: 42 additions & 0 deletions pkg/ccl/backupccl/testdata/backup-restore/materialized_view
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# We allow implicit access to non-admin users so that we can test
# with nodelocal.
new-cluster name=s1 allow-implicit-access
----

exec-sql
CREATE DATABASE testdb;
USE testdb;
CREATE TABLE testdb.t (a int primary key, b int);
CREATE MATERIALIZED VIEW testdb.mv AS SELECT a, b FROM testdb.t;
INSERT INTO testdb.t (a, b) VALUES (1, 2);
----

exec-sql
REFRESH MATERIALIZED VIEW mv;
----

exec-sql
INSERT INTO testdb.t (a, b) VALUES (2, 3);
----

exec-sql
REFRESH MATERIALIZED VIEW mv;
----

exec-sql
BACKUP INTO 'nodelocal://1/test/'
----


new-cluster name=s2 share-io-dir=s1 allow-implicit-access
----

exec-sql
RESTORE DATABASE testdb FROM LATEST IN 'nodelocal://1/test/' WITH new_db_name = 'newdb';
----

query-sql
SELECT * FROM newdb.mv;
----
1 2
2 3

0 comments on commit e4b74b8

Please sign in to comment.