All Products
Search
Document Center

AnalyticDB:Manage materialized views

Last Updated:Mar 28, 2026

After creating materialized views, you can query their definitions, inspect metadata and refresh history, modify properties, and delete views you no longer need.

Query the definition of a materialized view

Run SHOW CREATE MATERIALIZED VIEW to retrieve the DDL statement used to create a materialized view.

Prerequisites

Before you begin, ensure that you have:

  • The SELECT permission on the materialized view

To grant it, a privileged account or a standard account with the GRANT permission can run the following statement or use the Account Management page in the console:

GRANT SELECT ON <database>.<mv_name> TO <username>;

Syntax

SHOW CREATE MATERIALIZED VIEW <mv_name>

Example

-- Retrieve the DDL for compl_mv1
SHOW CREATE MATERIALIZED VIEW demo.compl_mv1;

查询每次刷新读取和写入的数据量(仅全量刷新的物化视图)

SELECT * FROM 
information_schema.kepler_meta_async_jobs as async_tak 
JOIN 
information_schema.mv_auto_refresh_jobs as mv_jobs 
ON mv_jobs.process_id = async_tak.exec_job_id 
WHERE
mv_jobs.mv_name = '<mv_name>';

Query materialized view metadata

The information_schema.mv_info table stores metadata for all materialized views in the cluster. To retrieve the definition of a single view, use SHOW CREATE MATERIALIZED VIEW instead.

Fields

FieldDescription
MV_SCHEMADatabase where the materialized view resides
MV_NAMEName of the materialized view
MV_DEFINITIONDDL statement used to create the view
MV_QUERYOriginal SQL query of the view
FIRST_REFRESH_TIMEFirst refresh time, for views configured with automatic refresh
NEXT_REFRESH_TIME_FUNCFunction that calculates the next refresh time, for views configured with automatic refresh
OWNERAccount that created the view
QUERY_SCHEMADatabase in which the creation statement was executed
REFRESH_CONDITIONRefresh trigger mechanism: DEMAND (scheduled automatic or manual) or OVERWRITE (triggered when base tables are overwritten)
REFRESH_STATERefresh policy: COMPLETE (full refresh) or FAST (incremental refresh)
UPDATE_TIMETime when the view's metadata was last updated

Examples

-- Count all materialized views in the cluster
SELECT count(*) FROM information_schema.mv_info;

-- Query metadata for all materialized views
SELECT * FROM information_schema.mv_info;

List materialized views

SHOW MATERIALIZED VIEWS returns all materialized views in the current database on which you have the SELECT permission. Filter by name using a SQL LIKE pattern.

To query views in a specific database, use information_schema.mv_info with a WHERE clause.

Prerequisites

Before you begin, ensure that you have:

  • The SELECT permission on the materialized views you want to list

To grant it, a privileged account or a standard account with the GRANT permission can run the following statement or use the Accounts page in the console:

GRANT SELECT ON <database>.* TO <username>;

Syntax

-- List all materialized views in the current database
SHOW MATERIALIZED VIEWS [LIKE 'pattern']

-- List all materialized views in a specific database
SELECT * FROM information_schema.mv_info WHERE mv_schema = '<schema_name>';

Examples

-- List all materialized views in the current database
SHOW MATERIALIZED VIEWS;

-- List materialized views whose names start with "compl"
SHOW MATERIALIZED VIEWS LIKE 'compl%';

-- List all materialized views in the demo database
SELECT * FROM information_schema.mv_info WHERE mv_schema = 'demo';
For LIKE pattern syntax, see String functions.

Query refresh records

Automatic refresh records

The information_schema.mv_auto_refresh_jobs table records automatic refresh jobs for materialized views configured with the START WITH or NEXT parameter.

SELECT * FROM information_schema.mv_auto_refresh_jobs
WHERE mv_schema = '<schema_name>' AND mv_name = '<mv_name>';

Usage notes

  • The table stores up to 1,024 records per cluster.

  • The first refresh after view creation is not included.

Fields

FieldDescription
MV_SCHEMADatabase where the materialized view resides
MV_NAMEName of the materialized view
PROCESS_IDProcess ID of the refresh task
SCHEDULED_START_TIMEScheduled start time of the refresh job
START_TIMEActual start time
END_TIMEActual end time
STATEJob status (see below)

STATE values:

ValueDescription
PENDINGWaiting to be triggered
RUNNINGIn progress. If multiple views refresh concurrently, some jobs may wait for available computing resources.
FINISHEDCompleted successfully
FAILEDFailed. The job retries up to 10 times; if all retries fail, the job is canceled.
TIMEOUTTimed out. Timed-out jobs can be retriggered.

Examples

-- Query all automatic refresh records for compl_mv1 in the demo database
SELECT * FROM information_schema.mv_auto_refresh_jobs
WHERE mv_schema = 'demo' AND mv_name = 'compl_mv1';

-- Query only pending jobs for compl_mv1 in the demo database
SELECT * FROM information_schema.mv_auto_refresh_jobs
WHERE mv_schema = 'demo' AND mv_name = 'compl_mv1' AND state = 'PENDING';

Manual refresh records

Use one of the following tools to look up manual refresh activity:

  • SQL Audit (past 30 days): On the SQL Audit tab, enter REFRESH MATERIALIZED VIEW <mv_name> in the Keyword field. The results show the time, duration, IP address, and username for each manual refresh.

    SQL Audit must be enabled before use. Operations that occurred before you enabled it are not recorded.

    image

  • SQL diagnostics and optimization (past 14 days): On the SQL Diagnostics and Optimization tab, enter the view name (for example, compl_mv1). The results include all related SQL activity—creation, manual refresh, automatic refresh, and modification—with start time, username, duration, and query ID.

    image

Modify a materialized view

ALTER MATERIALIZED VIEW lets you change a standard materialized view to an elastic materialized view, update its resource group, toggle query rewrite, or rename it.

The following properties cannot be changed: the view definition, refresh policy, and refresh trigger mechanism.

Prerequisites

Before you begin, ensure that you have:

  • The ALTER permission on the materialized view

To grant it, a privileged account or a standard account with the GRANT permission can run the following statement or use the Account Management page in the console:

GRANT ALTER ON <database>.<mv_name> TO <username>;

Syntax

ALTER MATERIALIZED VIEW <mv_name>
  [MV_PROPERTIES = '<MV_PROPERTIES>']
  [ENABLE | DISABLE QUERY REWRITE]
  [RENAME <new_mv_name>]

Parameters:

ParameterDescription
MV_PROPERTIESA JSON object containing view properties. Supported keys: mv_resource_group (the resource group for the view) and mv_refresh_hints (hint parameters; see Config and hint configuration parameters).
ENABLE | DISABLE QUERY REWRITEEnables or disables query rewrite for the view.
RENAME <new_mv_name>Renames the materialized view.
Important

MV_PROPERTIES in the ALTER statement replaces (does not merge with) the MV_PROPERTIES set at creation time. For example, if you created the view with both mv_resource_group and mv_refresh_hints, then alter it with only mv_resource_group, the mv_refresh_hints value is cleared.

Examples

-- Enable query rewrite
ALTER MATERIALIZED VIEW compl_mv1 ENABLE QUERY REWRITE;

-- Change the resource group for an elastic materialized view
ALTER MATERIALIZED VIEW job_mv
  MV_PROPERTIES = '{
    "mv_resource_group": "my_job_rg_2",
    "mv_refresh_hints": {"query_priority": "NORMAL"}
  }';

-- Convert a standard materialized view to an elastic materialized view
ALTER MATERIALIZED VIEW compl_mv1
  MV_PROPERTIES = '{
    "mv_resource_group": "my_job_rg_2"
  }';

-- Rename a materialized view
ALTER MATERIALIZED VIEW mv1 RENAME mv2;

Delete a materialized view

DROP MATERIALIZED VIEW permanently deletes the materialized view and its data.

Running DROP TABLE on a materialized view returns an error: demo.myview11 is materialized view, use DROP MATERIALIZED VIEW.

Prerequisites

Before you begin, ensure that you have:

  • The DROP permission on the materialized view

To grant it, a privileged account or a standard account with the GRANT permission can run the following statement or use the Accounts page in the console:

GRANT DROP ON <database>.<mv_name> TO <username>;

Syntax

DROP MATERIALIZED VIEW <mv_name>

Example

-- Delete compl_mv1
DROP MATERIALIZED VIEW compl_mv1;