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

# ALTER MATERIALIZED VIEW

> Alters the name, refresh strategy, status, or properties of an asynchronous materialized view, or atomically swaps two views.

ALTER MATERIALIZED VIEW 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.
* Change the sort key of a range-distributed asynchronous materialized view online, without recreating it (from v4.2 onwards).
* Alter the properties of an asynchronous materialized view.

  You can use this SQL statement to alter the following properties:

  * `bloom_filter_columns`
  * `partition_ttl_number`
  * `partition_refresh_number`
  * `partition_refresh_strategy`
  * `resource_group`
  * `auto_refresh_partitions_limit`
  * `excluded_trigger_tables`
  * `mv_rewrite_staleness_second`
  * `unique_constraints`
  * `foreign_key_constraints`
  * `colocate_with`
  * `excluded_refresh_tables`
  * `file_bundling` (shared-data clusters only, from v4.2.1 onwards)
  * All session variable-related properties. For information on session variables, see [System variables](/documents/4.2/sql-reference/System_variable.md).

**Tip**

* This operation requires the ALTER privilege on the target materialized view. You can follow the instructions in [GRANT](/documents/4.2/sql-reference/sql-statements/account-management/GRANT.md) 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.

## Syntax

```SQL theme={null}
ALTER MATERIALIZED VIEW [db_name.]<mv_name> 
    { RENAME [db_name.]<new_mv_name> 
    | REFRESH <new_refresh_scheme_desc> 
    | ACTIVE | INACTIVE 
    | SWAP WITH [db_name.]<mv2_name>
    | ORDER BY (<column_name> [, <column_name> ...])
    | SET ( "<key>" = "<value>"[,...]) }
```

## Parameters

| **Parameter** | **Required** | **Description** |
| - | - | - |
| mv\_name | yes | The name of the materialized view to alter. |
| new\_refresh\_scheme\_desc | no | New refresh strategy, see [SQL Reference - CREATE MATERIALIZED VIEW - Parameters](/documents/4.2/sql-reference/sql-statements/materialized_view/CREATE_MATERIALIZED_VIEW.md#parameters) for details. |
| new\_mv\_name | no | New name for the materialized view. |
| ACTIVE | no | Set the status of the materialized view to active. The database 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. |
| ORDER BY | no | Change the sort key of the materialized view to the listed columns online, without recreating the materialized view. Supported only for range-distributed asynchronous materialized views in shared-data clusters (from v4.2 onwards). On a materialized view with `colocate_with`, the new sort key must start with the colocated columns, in the same order and with the same types. If `colocate_with` specifies only the colocation group and the new sort key is longer than the colocated columns, the property is rewritten to the explicit form `<colocation_group>:<colocated_column>[,<colocated_column>]`, which `SHOW CREATE MATERIALIZED VIEW` returns from then on. The listed columns must be output columns of the materialized view. For Duplicate Key materialized views the sort key can be any subset of the columns; for Aggregate and Unique Key materialized views the sort key must consist of exactly the key columns. The materialized view's refresh is paused for the duration of the rewrite and resumed automatically when it completes; the materialized view remains queryable throughout and the new sort order takes effect atomically. |
| key | no | The name of the property to alter, see [SQL Reference - CREATE MATERIALIZED VIEW - Parameters](/documents/4.2/sql-reference/sql-statements/materialized_view/CREATE_MATERIALIZED_VIEW.md#parameters) for details. **NOTE** 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.insert_timeout`. You do not need to specify the prefix for non-session properties, for example, `mv_rewrite_staleness_second`. |
| value | no | The value of the property to alter. |

## Example

Example 1: Alter the name of the materialized view.

```SQL theme={null}
ALTER MATERIALIZED VIEW lo_mv1 RENAME lo_mv1_new_name;
```

Example 2: Alter the refresh interval of the materialized view.

```SQL theme={null}
ALTER MATERIALIZED VIEW lo_mv2 REFRESH SCHEDULE EVERY(INTERVAL 1 DAY);
```

Example 3: Alter the timeout duration for the materialized view refresh tasks to 1 hour (default).

```SQL theme={null}
ALTER MATERIALIZED VIEW mv1 SET ("session.insert_timeout" = "3600");
```

Example 4: Alter the materialized view's status to active.

```SQL theme={null}
ALTER MATERIALIZED VIEW order_mv ACTIVE;
```

Example 5: Perform an atomic exchange between materialized views `order_mv` and `order_mv1`.

```SQL theme={null}
ALTER MATERIALIZED VIEW order_mv SWAP WITH order_mv1;
```

Example 6: Enable profile for the materialized view refresh process. This feature is enabled by default.

```SQL theme={null}
ALTER MATERIALIZED VIEW mv1 SET ("session.enable_profile" = "true");
```

Example 7: Enable intermediate result spilling for the materialized view refresh process, and set the mode of spilling to `force`. Intermediate result spilling is enabled by default since v3.1.

```SQL theme={null}
-- Enable spilling during materialized view refresh.
ALTER MATERIALIZED VIEW mv1 SET ("session.enable_spill" = "true");
-- Set spill_mode to force (the default value is auto).
ALTER MATERIALIZED VIEW mv1 SET ("session.spill_mode" = "force");
```

Example 8: Alter the optimizer timeout duration for materialized view to 30 seconds (default since v3.3) if its query statement contains external tables or multiple joins.

```SQL theme={null}
ALTER MATERIALIZED VIEW mv1 SET ("session.new_planner_optimize_timeout" = "30000");
```

Example 9: Alter the query rewrite staleness time for the materialized view to 600 seconds.

```SQL theme={null}
ALTER MATERIALIZED VIEW mv1 SET ("mv_rewrite_staleness_second" = "600");
```

Example 10: Alter the materialized view's bloom filter indexes.

```SQL theme={null}
ALTER MATERIALIZED VIEW mv1 SET ("bloom_filter_columns" = "col1, col2");
```

Example 11: Change the sort key of a range-distributed materialized view to `(k2, k1)` online (from v4.2 onwards).

```SQL theme={null}
ALTER MATERIALIZED VIEW order_mv ORDER BY (k2, k1);
```

Example 12: Enable File Bundling for a materialized view in a shared-data cluster (from v4.2.1 onwards). `file_bundling` must be the only property in the statement. The change runs as an asynchronous job, and you can check its progress with [SHOW ALTER TABLE COLUMN](/documents/4.2/sql-reference/sql-statements/table_bucket_part_index/SHOW_ALTER.md). The restrictions on changing `file_bundling` are the same as for tables. See the `file_bundling` property in [CREATE TABLE](/documents/4.2/sql-reference/sql-statements/table_bucket_part_index/CREATE_TABLE.md).

```SQL theme={null}
ALTER MATERIALIZED VIEW order_mv SET ("file_bundling" = "true");
```


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