MV_INFOS
Description
Table function, generating temporary tables for asynchronous materialized views, which can view information about asynchronous materialized views created in a certain database.
Syntax
MV_INFOS("database"="<database>")
Parameters
| Parameter | Description |
|---|---|
<database> | Required. String type. Name of the database whose asynchronous materialized view metadata you want to query. |
Return Value
This table function returns zero or more rows describing asynchronous materialized views. The function itself does not return NULL. Individual fields can be empty or NULL when the corresponding metadata is unavailable.
| Field | Type | Description |
|---|---|---|
| Id | BIGINT | Materialized view ID |
| Name | TEXT | Materialized view name |
| JobName | TEXT | Name of the refresh job corresponding to the materialized view. It can be used to query jobs("type"="mv") and tasks("type"="mv"). |
| State | TEXT | Metadata state of the materialized view. Possible values: INIT, NORMAL, and SCHEMA_CHANGE. |
| SchemaChangeDetail | TEXT | Reason why State becomes SCHEMA_CHANGE. Empty when the materialized view is not in schema change state. |
| RefreshState | TEXT | State of the latest refresh. Possible values: INIT, SUCCESS, and FAIL. |
| RefreshInfo | TEXT | Refresh strategy defined for the materialized view, including build mode, refresh method, and trigger mode. |
| QuerySql | TEXT | SQL query defined for the materialized view |
| EnvInfo | TEXT | Environment information when the materialized view was created |
| MvProperties | TEXT | Materialized view properties |
| MvPartitionInfo | TEXT | Partition information of the materialized view |
| SyncWithBaseTables | BOOLEAN | Whether the data of the materialized view is synchronized with its base tables. To check which partition is not synchronized, use SHOW PARTITIONS. |
RefreshInfo is displayed as BUILD <BuildMode> REFRESH <RefreshMethod> ON <RefreshTrigger> [schedule]. The meaning of each part is described in the enum section below.
MV info enum fields
The following enum fields are commonly used when checking materialized view definitions and health:
State: metadata state of the materialized view.INIT: the materialized view has been created but has not reached normal usable metadata state yet.NORMAL: the materialized view metadata is normal. This is the expected state in most cases.SCHEMA_CHANGE: a schema change on a base table or related object affected this materialized view. CheckSchemaChangeDetailfor the reason. The materialized view can usually be queried directly, but it may not be available for transparent rewrite until it is refreshed successfully.
RefreshState: result state of the latest refresh.INIT: no refresh result has been recorded yet.SUCCESS: the latest refresh finished successfully.FAIL: the latest refresh failed. UseJobNameto querytasks("type"="mv")and check the failed task'sErrorMsg.
RefreshInfo.BuildMode: when Doris builds the materialized view data.IMMEDIATE: build the materialized view immediately after creation.DEFERRED: do not build it at creation time. The materialized view needs a later refresh before it has fresh data.
RefreshInfo.RefreshMethod: how Doris chooses data to refresh.COMPLETE: always refresh the materialized view completely.AUTO: Doris decides whether to refresh all partitions or only changed partitions.
RefreshInfo.RefreshTrigger: what triggers refresh tasks.MANUAL: refresh is triggered manually.COMMIT: refresh is triggered by data changes on related base tables.SCHEDULE: refresh is triggered by a schedule. The schedule details appear afterON SCHEDULEinRefreshInfo.
MvPartitionInfo.partitionType: how the materialized view is partitioned.FOLLOW_BASE_TABLE: materialized view partitions follow a base table partition column.SELF_MANAGE: the materialized view manages its own partitions.
Doris 2.1.x supports FOLLOW_BASE_TABLE and SELF_MANAGE for MvPartitionInfo.partitionType. The EXPR partition type is supported since Doris 3.0.0.
SyncWithBaseTables: whether materialized view data is synchronized with base tables.1ortrue: synchronized.0orfalse: not fully synchronized. For partitioned materialized views, useSHOW PARTITIONS FROM <mv_name>to check partition-level synchronization.
Examples
View a materialized view under database test.
select *
from mv_infos("database"="test")
where Name = "mv1"\G
*************************** 1. row ***************************
Id: 19494
Name: mv1
JobName: inner_mtmv_19494
State: NORMAL
SchemaChangeDetail:
RefreshState: SUCCESS
RefreshInfo: BUILD DEFERRED REFRESH AUTO ON MANUAL
QuerySql: SELECT `internal`.`test`.`user`.`k2`, `internal`.`test`.`user`.`k3` FROM `internal`.`test`.`user`
EnvInfo: EnvInfo{ctlId='0', dbId='16813'}
MvProperties: {partition_sync_limit=100, partition_sync_time_unit=YEAR}
MvPartitionInfo: MTMVPartitionInfo{partitionType=FOLLOW_BASE_TABLE, relatedTable=user, relatedCol='k2', partitionCol='k2'}
SyncWithBaseTables: 1
In this result:
IdandNameidentify the materialized view.JobNameis the refresh job name for this materialized view. Use it to query the job or refresh tasks, for exampleselect * from jobs("type"="mv") where Name = "inner_mtmv_19494";.StateisNORMAL, which means the materialized view metadata is normal.INITmeans the materialized view has just been created or initialized.SCHEMA_CHANGEmeans a schema change on a base table affected this materialized view; in this state, checkSchemaChangeDetail.SchemaChangeDetailis empty becauseStateis notSCHEMA_CHANGE.RefreshStateisSUCCESS, which means the latest refresh succeeded.INITmeans no successful refresh state has been recorded yet.FAILmeans the latest refresh failed; querytasks("type"="mv")withJobNameto find the failed task and itsErrorMsg.RefreshInfoisBUILD DEFERRED REFRESH AUTO ON MANUAL.BUILD DEFERREDmeans the materialized view was not built immediately at creation time.REFRESH AUTOmeans Doris decides whether to refresh all partitions or only changed partitions.ON MANUALmeans refresh is triggered manually rather than by a schedule.QuerySqlis the query definition of the materialized view.EnvInforecords the environment information when the materialized view was created.MvPropertiesshows the properties of the materialized view. In this example, partition synchronization is limited bypartition_sync_limit=100andpartition_sync_time_unit=YEAR.MvPartitionInfoshows how the materialized view is partitioned. In Doris 2.1.x,FOLLOW_BASE_TABLEmeans the materialized view follows a base table partition column, andSELF_MANAGEmeans the materialized view manages its own partitions. TheEXPRpartition type is supported since Doris 3.0.0.SyncWithBaseTablesis1, which means the materialized view data is synchronized with its base tables.0means it is not fully synchronized. For partitioned materialized views, useSHOW PARTITIONS FROM <mv_name>to check partition-level synchronization.
To view the latest refresh task of this materialized view:
select TaskId, JobName, MvName, Status, ErrorMsg, CreateTime, FinishTime
from tasks("type"="mv")
where JobName = "inner_mtmv_19494"
order by CreateTime desc
limit 1;
+-----------------+------------------+--------+---------+----------+---------------------+---------------------+
| TaskId | JobName | MvName | Status | ErrorMsg | CreateTime | FinishTime |
+-----------------+------------------+--------+---------+----------+---------------------+---------------------+
| 437156301250803 | inner_mtmv_19494 | mv1 | SUCCESS | | 2025-01-07 22:13:48 | 2025-01-07 22:17:45 |
+-----------------+------------------+--------+---------+----------+---------------------+---------------------+