> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# SHOW MATERIALIZED VIEWS

> 展示所有或指定异步物化视图的信息。

## 功能

展示所有或指定异步物化视图信息。该语句从 3.0 版本开始更名为 SHOW MATERIALIZED VIEWS，之前版本为 SHOW MATERIALIZED VIEW。

> **注意**
>
> 该命令当前仅针对异步物化视图生效。针对同步物化视图您可以通过 [SHOW ALTER MATERIALIZED VIEW](/documents/cn/4.2/sql-reference/sql-statements/materialized_view/SHOW_ALTER_MATERIALIZED_VIEW.md) 命令查看当前数据库中同步物化视图的构建状态。
> 该操作不需要权限。

## 语法

```SQL theme={null}
SHOW MATERIALIZED VIEWS
[FROM db_name]
[
WHERE NAME { = "mv_name" | LIKE "mv_name_matcher"}
]
```

**Note**

自 v3.3 起，如果单个物化视图刷新任务包含多个分区或 task\_runs，`SHOW MATERIALIZED VIEWS` 语句将追踪所有 task\_runs 的状态。仅当所有 task\_runs 成功后，`last_refresh_state` 字段才会返回 `SUCCESS`。

## 参数

| **参数** | **必选** | **说明** |
| - | - | - |
| db\_name | 否 | 物化视图所属的数据库名称。如果不指定该参数，则默认使用当前数据库。 |
| mv\_name | 否 | 用于精确匹配的物化视图名称。 |
| mv\_name\_matcher | 否 | 用于模糊匹配的物化视图名称 matcher。 |

## 返回

返回最近一次 REFRESH 任务的状态。

| **返回** | **说明** |
| - | - |
| id | 物化视图 ID。 |
| database\_name | 物化视图所属的数据库名称。 |
| name | 物化视图名称。 |
| refresh\_type | 物化视图的更新方式，有效值：`SYNC`（同步物化视图）和 `ASYNC`（异步物化视图，无论以何种方式触发刷新）。 |
| is\_active | 物化视图状态是否为 active。有效值：`true` 和 `false`。 |
| inactive\_reason | 物化视图失效的原因。 |
| partition\_type | 物化视图的分区类型，包括 RANGE 和 UNPARTITIONED。 |
| task\_id | 物化视图的刷新任务 ID。 |
| task\_name | 物化视图的刷新任务名称。 |
| last\_refresh\_start\_time | 物化视图上一次刷新开始时间。 |
| last\_refresh\_finished\_time | 物化视图上一次刷新结束时间。 |
| last\_refresh\_duration | 物化视图上一次刷新耗时（单位秒）。 |
| last\_refresh\_state | 物化视图上一次刷新的状态，包括 PENDING、RUNNING、FAILED、SUCCESS、SKIPPED。如果未检测到基表分区上的数据发生变化，则会跳过对应物化视图分区的刷新操作。 |
| last\_refresh\_force\_refresh | 物化视图上一次刷新是否为强制（FORCE）刷新。 |
| last\_refresh\_start\_partition | 上一次刷新开始的物化视图分区。 |
| last\_refresh\_end\_partition | 上一次刷新结束的物化视图分区。 |
| last\_refresh\_base\_refresh\_partitions | 上一次刷新基表更新的分区。 |
| last\_refresh\_mv\_refresh\_partitions | 上一次刷新物化视图刷新的分区。 |
| last\_refresh\_error\_code | 物化视图上一次刷新失败的 ErrorCode（如果物化视图状态不为 active）。 |
| last\_refresh\_error\_message | 物化视图上一次刷新失败的 ErrorMessage（如果物化视图状态不为 active）。 |
| rows | 物化视图中数据行数。 |
| text | 创建物化视图的查询语句。 |
| extra\_message | 最近一次刷新任务的额外信息。 |
| query\_rewrite\_status | 物化视图的查询改写状态。 |
| creator | 最近一次刷新任务的创建者。 |
| last\_refresh\_process\_time | 最近一次刷新任务的处理开始时间。 |
| last\_refresh\_job\_id | 最近一次刷新任务的作业 ID。 |
| last\_refresh\_time | 物化视图已反映基表更新的最新时间。 |
| warehouse | 异步物化视图执行刷新任务所使用的 warehouse 名称。在存算一体模式下，或对于同步（rollup）物化视图，该值为空。 |
| refresh\_mode | 异步物化视图配置的刷新模式。支持 `PCT`（分区变更跟踪，仅刷新发生变更的分区）、`INCREMENTAL`（增量视图维护）和 `AUTO`（自动选择刷新模式）。对于同步物化视图为空。 |
| refresh\_trigger | 刷新的触发方式。有效值：`NONE`（同步物化视图）、`MANUAL`（仅通过 REFRESH MATERIALIZED VIEW 触发）、`SCHEDULED`（周期性触发，通过 EVERY 间隔）和 `ON_BASE_TABLE_CHANGE`（基表导入或变更时自动触发）。 |
| refresh\_policy | 可读的刷新策略。有效值：`NONE`、`MANUAL`、`ON_BASE_TABLE_CHANGE`，或形如 `START("yyyy-MM-dd HH:mm:ss") EVERY(INTERVAL n unit)` 的调度（仅当定义了起始时间时才包含 `START` 子句）。 |
| resource\_group | 物化视图刷新任务所使用的资源组（来自物化视图的 `resource_group` 属性）。未设置时默认为 `default_mv_wg`。 |
| query\_rewrite\_status\_reason | `query_rewrite_status` 的原因。有效值：`OK`、`MV_INACTIVE`、`QUERY_REWRITE_DISABLED`、`UNSUPPORTED_DEFINITION` 和 `UNKNOWN`。 |
| last\_freshness\_confirmed\_at | 最近一次成功刷新的开始时间，在整次刷新（其全部 task run）完成后才记录；确认基表无变化、无需刷新的刷新同样会确认新鲜度。物化视图反映该时刻的基表数据。区别于 `last_refresh_time`（基表数据版本时间），这是墙钟时间。首次成功刷新前、以及同步物化视图，为空。按分区范围的 REFRESH（部分刷新）不推进该值。 |
| base\_table\_refresh\_version\_times | 各基表的数据版本时间，以 JSON 对象给出：键为基表的 `catalog.database.table` 名称，值为观测到的最新数据版本时间。这是 `last_refresh_time`（所有基表的单一最大值）背后的按表明细：外部/数据湖基表上报分区源修改时间，OLAP（内部）基表上报可见版本提交时间。无任何基表有可记录时间时为 `{}`。 |

## 示例

以下示例基于当前业务情景：

```Plain theme={null}
-- Create Table: customer
CREATE TABLE customer ( C_CUSTKEY     INTEGER NOT NULL,
                        C_NAME        VARCHAR(25) NOT NULL,
                        C_ADDRESS     VARCHAR(40) NOT NULL,
                        C_NATIONKEY   INTEGER NOT NULL,
                        C_PHONE       CHAR(15) NOT NULL,
                        C_ACCTBAL     double   NOT NULL,
                        C_MKTSEGMENT  CHAR(10) NOT NULL,
                        C_COMMENT     VARCHAR(117) NOT NULL,
                        PAD char(1) NOT NULL)
    ENGINE=OLAP
DUPLICATE KEY(`c_custkey`)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`c_custkey`) BUCKETS 10
PROPERTIES (
"replication_num" = "3",
"storage_format" = "DEFAULT"
);

-- Create MV: customer_mv
CREATE MATERIALIZED VIEW customer_mv
DISTRIBUTED BY HASH(c_custkey) buckets 10
REFRESH MANUAL
PROPERTIES (
    "replication_num" = "3"
)
AS SELECT
              c_custkey, c_phone, c_acctbal, count(1) as c_count, sum(c_acctbal) as c_sum
   FROM
              customer
   GROUP BY c_custkey, c_phone, c_acctbal;

-- Refresh the MV
REFRESH MATERIALIZED VIEW customer_mv;
```

示例一：通过精确匹配查看特定物化视图

```Plain theme={null}
mysql> show materialized views  where name='customer_mv'\G
*************************** 1. row ***************************
                        id: 10142
                      name: customer_mv
             database_name: test
              refresh_type: ASYNC
                 is_active: true
   last_refresh_start_time: 2023-02-17 10:27:33
last_refresh_finished_time: 2023-02-17 10:27:33
     last_refresh_duration: 0
        last_refresh_state: SUCCESS
             inactive_code: 0
           inactive_reason:
                      text: CREATE MATERIALIZED VIEW `customer_mv`
COMMENT "MATERIALIZED_VIEW"
DISTRIBUTED BY HASH(`c_custkey`) BUCKETS 10
REFRESH MANUAL
PROPERTIES (
"replication_num" = "3",
"storage_medium" = "HDD"
)
AS SELECT `customer`.`c_custkey`, `customer`.`c_phone`, `customer`.`c_acctbal`, count(1) AS `c_count`, sum(`customer`.`c_acctbal`) AS `c_sum`
FROM `test`.`customer`
GROUP BY `customer`.`c_custkey`, `customer`.`c_phone`, `customer`.`c_acctbal`;
                      rows: 0
                 warehouse:
              refresh_mode: PCT
           refresh_trigger: MANUAL
            refresh_policy: MANUAL
            resource_group: default_mv_wg
1 row in set (0.11 sec)
```

示例二：通过模糊匹配查看物化视图

```Plain theme={null}
mysql> show materialized views  where name like 'customer_mv'\G
*************************** 1. row ***************************
                        id: 10142
                      name: customer_mv
             database_name: test
              refresh_type: ASYNC
                 is_active: true
   last_refresh_start_time: 2023-02-17 10:27:33
last_refresh_finished_time: 2023-02-17 10:27:33
     last_refresh_duration: 0
        last_refresh_state: SUCCESS
             inactive_code: 0
           inactive_reason:
                      text: CREATE MATERIALIZED VIEW `customer_mv`
COMMENT "MATERIALIZED_VIEW"
DISTRIBUTED BY HASH(`c_custkey`) BUCKETS 10
REFRESH MANUAL
PROPERTIES (
"replication_num" = "3",
"storage_medium" = "HDD"
)
AS SELECT `customer`.`c_custkey`, `customer`.`c_phone`, `customer`.`c_acctbal`, count(1) AS `c_count`, sum(`customer`.`c_acctbal`) AS `c_sum`
FROM `test`.`customer`
GROUP BY `customer`.`c_custkey`, `customer`.`c_phone`, `customer`.`c_acctbal`;
                      rows: 0
                 warehouse:
              refresh_mode: PCT
           refresh_trigger: MANUAL
            refresh_policy: MANUAL
            resource_group: default_mv_wg
1 row in set (0.12 sec)

```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.