From 8f13f40c92ec40b6b905c105da25895bd8728f4c Mon Sep 17 00:00:00 2001
From: sundyli <543950155@qq.com>
Date: Thu, 5 Nov 2026 03:45:02 +0000
Subject: [PATCH] docs: explain cross-database materialized view sources
---
.../00-ddl/05-view/materialized-view.md | 17 +++++++++++++++++
.../00-ddl/05-view/materialized-view.md | 17 +++++++++++++++++
2 files changed, 34 insertions(+)
diff --git a/docs/cn/sql-reference/10-sql-commands/00-ddl/05-view/materialized-view.md b/docs/cn/sql-reference/10-sql-commands/00-ddl/05-view/materialized-view.md
index 5104388e7a..15c72794b8 100644
--- a/docs/cn/sql-reference/10-sql-commands/00-ddl/05-view/materialized-view.md
+++ b/docs/cn/sql-reference/10-sql-commands/00-ddl/05-view/materialized-view.md
@@ -61,6 +61,23 @@ REFRESH MATERIALIZED VIEW paid_orders_by_customer;
`CREATE OR REPLACE` 会替换已有物化视图;当同名对象已存在时,`IF NOT EXISTS` 不执行任何操作。
+
使用其他数据库中的源表
+
+
+
+物化视图与源表可以位于同一 `default` catalog 中的不同数据库。请使用数据库名称限定源表。未限定的源表名称在当前会话数据库中解析,而不是在目标数据库中解析。
+
+例如,假设 `sales.orders` 具有上例中的列,且 `reporting` 数据库已存在:
+
+```sql
+CREATE MATERIALIZED VIEW reporting.paid_orders AS
+SELECT order_id, amount FROM sales.orders WHERE paid;
+
+REFRESH MATERIALIZED VIEW reporting.paid_orders;
+```
+
+删除源数据库会使物化视图失效。`system.materialized_views` 会显示 `invalid = 1` 和 `invalid_reason = 'source database was dropped'`。对于仅因该删除操作而失效的物化视图,使用 `UNDROP DATABASE` 恢复原源数据库即可恢复视图。新建同名数据库不会恢复源表的对象身份。删除物化视图所在的数据库不会阻止对源表的查询。
+
## 刷新物化视图
```sql
diff --git a/docs/en/sql-reference/10-sql-commands/00-ddl/05-view/materialized-view.md b/docs/en/sql-reference/10-sql-commands/00-ddl/05-view/materialized-view.md
index 3af721715d..9016395d49 100644
--- a/docs/en/sql-reference/10-sql-commands/00-ddl/05-view/materialized-view.md
+++ b/docs/en/sql-reference/10-sql-commands/00-ddl/05-view/materialized-view.md
@@ -61,6 +61,23 @@ REFRESH MATERIALIZED VIEW paid_orders_by_customer;
`CREATE OR REPLACE` replaces an existing materialized view. `IF NOT EXISTS` is a no-op if the name already exists.
+Use a source table in another database
+
+
+
+The materialized view and its source table can use different databases in the same `default` catalog. Qualify the source table with its database name. An unqualified source name resolves in the current session database, not the target database.
+
+For example, if `sales.orders` has the columns in the previous example and the `reporting` database exists:
+
+```sql
+CREATE MATERIALIZED VIEW reporting.paid_orders AS
+SELECT order_id, amount FROM sales.orders WHERE paid;
+
+REFRESH MATERIALIZED VIEW reporting.paid_orders;
+```
+
+Dropping the source database makes the view invalid. `system.materialized_views` reports `invalid = 1` and `invalid_reason = 'source database was dropped'`. Restore the original source database with `UNDROP DATABASE` to recover a view invalidated only by that drop. Creating a new database with the same name does not restore the source table's identity. Dropping the database that contains the materialized view does not prevent queries on the source table.
+
## Refresh a materialized view
```sql