This topic describes how to use materialized views in SQL syntax, such as SELECT
, INSERT INTO SELECT
, and WITH
, to improve query performance.
Required permissions
You must have the SELECT permission on materialized views. You do not need to have the SELECT permission on the base tables referenced by materialized views.
You can execute the GRANT
statement to grant the SELECT permission on materialized views to users.
GRANT SELECT ON <mv_name> TO '<user>'@'%';
Method
The statement used to query the data of materialized views is the same as the statement used to query the data of standard tables or views. You can use materialized views in all SQL syntax. Sample statement:
SELECT * FROM adbview
WHERE device = 'PC'
AND city = 'Beijing';
When you perform queries by using materialized views, base tables referenced by the materialized views may be updated, but the updates are not reflected in the materialized views. In this case, the query results may be inaccurate. For this reason, we recommend that you manually refresh materialized views after their base tables are updated and then perform queries. For more information about how to manually refresh materialized views, see Configure full refresh for materialized views.