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

displayed_sidebar: "English" This SQL statement can: Alter the name of an asynchronous materialized view. Alter the refresh strategy of an asynchronous materialized view. Alter the status of an asynchronous materialized view to active or inactive. Perform an atomic swap between two asynchronous materialized views. Alter the properties of an asynchronous materialized view. You can use this SQL statement to alter the following properties: `partitionttlnumber` `partitionrefreshnumber` `resource_group` `autorefreshpartitions_limit` `excludedtriggertables` `mvrewritestaleness_second` `unique_constraints` `foreignkeyconstraints` `colocate_with` All session variable-related properties. For information on session variables, see . :::tip This operation requires the ALTER privilege on the target materialized view. You can follow the instructions in to grant this privilege. ALTER MATERIALIZED VIEW does not support directly modifying the query statement used to build the materialized view. You can build a new materialized view and swap it with the original one using ALTER MATERIALIZED VIEW SWAP WITH. ::: ```SQL ALTER MATERIALIZED VIEW [dbname.]<mvname> { RENAME [dbname.]<newmv_name> | REFRESH <newrefreshscheme_desc> | ACTIVE | INACTIVE | SWAP WITH [dbname.]<mv2name> | SET ( "<key>" = "<value>"[,...]) } ``` Parameters in brackets [] is optional. | Parameter | Required | Description | | -- | | | | mv_name | yes | The name of the materialized view to alter. | | newrefreshscheme_desc | no | New refresh strategy, see for details. | | newmvname | no | New name for the materialized view. | | ACTIVE | no |Set the status of the materialized view to active. StarRocks automatically sets a materialized view to inactive if any of its base tables is changed, for example, dropped and re-created, to prevent the situation that original metadata mismatches the changed base table. Inactive materialized views cannot be used for query acceleration or query rewrite. You can use this SQL to activate the materialized view after changing the base tables. | | INACTIVE | no | Set the status of the materialized view to inactive. An inactive asynchronous materialized view cannot be refreshed. But you can still query it as a table. | | SWAP WITH | no | Perform an atomic exchange with another asynchronous materialized view after necessary consistency checks. | | key | no | The name of the property to alter, see for details.<br />NOTE<br />If you want to alter a session variable-related property of the materialized view, you must add a `session.` prefix to the property, for example, `session.querytimeout`. You do not need to specify the prefix for non-session properties, for example, `mvrewritestalenesssecond`. | | value | no | The value of the property to alter. | Example 1: Alter the name of the materialized view. ```SQL ALTER MATERIALIZED VIEW lomv1 RENAME lomv1newname; ``` Example 2: Alter the refresh interval of the materialized view. ```SQL ALTER MATERIALIZED VIEW lo_mv2 REFRESH ASYNC EVERY(INTERVAL 1 DAY); ``` Example 3: Alter the materialized view's properties. ```SQL -- Change mv1's query_timeout to 40000 seconds. ALTER MATERIALIZED VIEW mv1 SET ("session.query_timeout" = "40000"); -- Change mv1's mvrewritestaleness_second to 600 seconds. ALTER MATERIALIZED VIEW mv1 SET ("mvrewritestaleness_second" = "600"); ``` Example 4: Alter the materialized view's status to active. ```SQL ALTER MATERIALIZED VIEW order_mv ACTIVE; ``` Example 5: Perform an atomic exchange between materialized views `ordermv` and `ordermv1`. ```SQL ALTER MATERIALIZED VIEW ordermv SWAP WITH ordermv1; ```