Skip to main content
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.
Tip
  • This operation requires the ALTER privilege on the target materialized view. You can follow the instructions in GRANT 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

Parameters

Example

Example 1: Alter the name of the materialized view.
Example 2: Alter the refresh interval of the materialized view.
Example 3: Alter the timeout duration for the materialized view refresh tasks to 1 hour (default).
Example 4: Alter the materialized view’s status to active.
Example 5: Perform an atomic exchange between materialized views order_mv and order_mv1.
Example 6: Enable profile for the materialized view refresh process. This feature is enabled by default.
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.
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.
Example 9: Alter the query rewrite staleness time for the materialized view to 600 seconds.
Example 10: Alter the materialized view’s bloom filter indexes.
Example 11: Change the sort key of a range-distributed materialized view to (k2, k1) online (from v4.2 onwards).
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. The restrictions on changing file_bundling are the same as for tables. See the file_bundling property in CREATE TABLE.