diff --git a/edb/pgsql/metaschema.py b/edb/pgsql/metaschema.py index a20f20f824d..683e1d3809d 100644 --- a/edb/pgsql/metaschema.py +++ b/edb/pgsql/metaschema.py @@ -6294,6 +6294,10 @@ def _generate_sql_information_schema( backend_version: params.BackendVersion ) -> List[dbops.Command]: + # Helper to create wrappers around materialized views. For + # performance, we use MATERIALIZED VIEW for some of our SQL + # emulation tables. Unfortunately we can't use those directly, + # since we need tableoid to match the real pg_catalog table. def make_wrapper_view(name: str) -> trampoline.VersionedView: return trampoline.VersionedView( name=("edgedbsql", name), diff --git a/edb/server/bootstrap.py b/edb/server/bootstrap.py index 525e887f329..0c6f11e16ce 100644 --- a/edb/server/bootstrap.py +++ b/edb/server/bootstrap.py @@ -750,10 +750,19 @@ def _generate_drop_views( for cv in reversed(list(group)): dv: Any if isinstance(cv, dbops.CreateView): - dv = dbops.DropView( + # We try deleting both a MATERIALIZED and not materialized + # version, since that allows us to switch between them + # more easily. + dv = dbops.CommandGroup() + dv.add_command(dbops.DropView( cv.view.name, conditions=[dbops.ViewExists(cv.view.name)], - ) + )) + dv.add_command(dbops.DropView( + cv.view.name, + conditions=[dbops.ViewExists(cv.view.name, materialized=True)], + materialized=True, + )) elif isinstance(cv, dbops.CreateFunction): dv = dbops.DropFunction( cv.function.name,