All Products
Search
Document Center

MaxCompute:SELECT MATERIALIZED VIEW

Last Updated:Oct 30, 2023

Queries the status of a materialized view. This operation allows you to view changes to the source table and determines whether the materialized view is valid.

Background information

A materialized view can be in one of the following states:

  • Valid

    When you execute a query statement, MaxCompute queries data from the materialized view instead of querying data from the source table.

  • Invalid

    When you execute a query statement, MaxCompute cannot directly query data from the materialized view. In this case, MaxCompute queries data from the source table. As a result, the query speed is not accelerated.

Query the status of a materialized view

You can use a function to check whether data in a materialized view is valid.

  • Syntax

    Boolean materialized_view_is_valid(<mv_name>,<partition>);
  • Examples

    Check whether data in the materialized view mf_mv_refresh4 is consistent with the latest data in the source table. If the data is consistent, true is returned. Otherwise, false is returned.

    • select materialized_view_is_valid("mf_mv_refresh4");
    • -- Specify the value of the partition.
      select materialized_view_is_valid("mf_mv_refresh_pts","20220810");
      
      -- Specify the value of a level-2 partition.
      select materialized_view_is_valid("mf_mv_refresh_pts_part","20220810","beijing");

Related statements

  • CREATE MATERIALIZED VIEW: creates a materialized view that supports clustering or partitioning based on the data for materialized view scenarios.

  • ALTER MATERIALIZED VIEW: updates a materialized view, changes the lifecycle of a materialized view, enables or disables the lifecycle feature for a materialized view, or drops partitions from a materialized view.

  • DESC TABLE/VIEW: views the information about a materialized view in a MaxCompute project.

  • DROP MATERIALIZED VIEW: drops an existing materialized view.