Project: StarRocks (App Definition and Development / Database)
File: SHOW_MATERIALIZED_VIEW.md

displayed_sidebar: "English" Shows all or one specific asynchronous materialized view. Since v3.0, the name of this statement is changed from SHOW MATERIALIZED VIEW to SHOW MATERIALIZED VIEWS. :::tip This operation does not require privileges. ::: ```SQL SHOW MATERIALIZED VIEWS [FROM db_name] [ WHERE NAME { = "mvname" | LIKE "mvname_matcher"} ] ``` Parameters in brackets [] is optional. | Parameter | Required | Description | | | | | | db_name | no | The name of the database to which the materialized view resides. If this parameter is not specified, the current database is used by default. | | mv_name | no | The name of the materialized view to show. | | mvnamematcher | no | The matcher used to filter materialized views. | | Return | Description | | -- | | | id | The ID of the materialized view. | | database_name | The name of the database in which the materialized view resides. | | name | The name of the materialized view. | | refresh_type | The refresh type of the materialized view, including ROLLUP, MANUAL, ASYNC, and INCREMENTAL. | | is_active | Whether the materialized view state is active. Valid Value: `true` and `false`. | | partition_type | The partition type of the materialized view, including RANGE and UNPARTITIONED. | | task_id | ID of the materialized view refresh task. | | task_name | Name of the materialized view refresh task. | | lastrefreshstart_time | The start time of the last refresh of the materialized view. | | lastrefreshfinished_time | The end time of the last refresh of the materialized view. | | lastrefreshduration | The time taken by the last refresh. Unit: seconds. | | lastrefreshstate | The status of the last refresh, including PENDING, RUNNING, FAILED, and SUCCESS. | | lastrefreshforce_refresh | Whether the last refresh is a FORCE refresh. | | lastrefreshstart_partition | The start partition of the last refresh in the materialized view. | | lastrefreshend_partition | The end partition of the last refresh in the materialized view. | | lastrefreshbaserefreshpartitions | The base table partitions that were refreshed in the last

| | lastrefreshmvrefreshpartitions | The materialized view partitions that were refreshed in the last refresh. | | lastrefresherror_code | The error code for the last failed refresh of the materialized view (if the materialized view state is not active). | | lastrefresherror_message | The reason why the last refresh failed (if the materialized view state is not active). | | rows | The number of data rows in the materialized view. | | text | The statement used to create the materialized view. | The following examples is based on this business scenario: ```Plain -- 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`) PROPERTIES ( "replication_num" = "3", "storage_format" = "DEFAULT" ); -- Create MV: customer_mv CREATE MATERIALIZED VIEW customer_mv DISTRIBUTED BY HASH(c_custkey) REFRESH MANUAL PROPERTIES ( "replication_num" = "3" ) AS SELECT ccustkey, cphone, cacctbal, count(1) as ccount, sum(cacctbal) as csum FROM customer GROUP BY ccustkey, cphone, c_acctbal; -- Refresh the MV REFRESH MATERIALIZED VIEW customer_mv; ``` Example 1: Show a specific materialized view. ```Plain mysql> SHOW MATERIALIZED VIEWS WHERE NAME='customer_mv'\G row * id: 10142 name: customer_mv database_name: test refresh_type: MANUAL is_active: true lastrefreshstart_time: 2023-02-17 10:27:33 lastrefreshfinished_time: 2023-02-17 10:27:33 lastrefreshduration: 0 lastrefreshstate: SUCCESS inactive_code: 0 inactive_reason: text: CREATE MATERIALIZED VIEW `customer_mv` COMMENT "MATERIALIZED_VIEW" DISTRIBUTED BY HASH(`c_custkey`) REFRESH MANUAL PROPERTIES ( "replication_num" = "3", "storage_medium" = "HDD" ) AS SELECT `customer`.`ccustkey`, `customer`.`cphone`, `customer`.`cacctbal`, count(1) AS `ccount`, sum(`customer`.`cacctbal`) AS `csum` FROM `test`.`customer` GROUP BY `customer`.`ccustkey`, `customer`.`cphone`, `customer`.`c_acctbal`; rows: 0 1 row in set (0.11 sec) ``` Example 2: Show materialized views by matching the name. ```Plain mysql> SHOW MATERIALIZED VIEWS WHERE NAME LIKE 'customer_mv'\G row * id: 10142 name: customer_mv database_name: test refresh_type: MANUAL is_active: true lastrefreshstart_time: 2023-02-17 10:27:33 lastrefreshfinished_time: 2023-02-17 10:27:33 lastrefreshduration: 0 lastrefreshstate: SUCCESS inactive_code: 0 inactive_reason: text: CREATE MATERIALIZED VIEW `customer_mv` COMMENT "MATERIALIZED_VIEW" DISTRIBUTED BY HASH(`c_custkey`) REFRESH MANUAL PROPERTIES ( "replication_num" = "3", "storage_medium" = "HDD" ) AS SELECT `customer`.`ccustkey`, `customer`.`cphone`, `customer`.`cacctbal`, count(1) AS `ccount`, sum(`customer`.`cacctbal`) AS `csum` FROM `test`.`customer` GROUP BY `customer`.`ccustkey`, `customer`.`cphone`, `customer`.`c_acctbal`; rows: 0 1 row in set (0.12 sec) ```