Materialized views store precomputed query results, making reads faster than querying base tables directly. Use them in SQL queries the same way you use standard tables or views.
Prerequisites
Only the SELECT permission on the materialized view is required. You do not need the SELECT permission on the base tables the materialized view references.
To grant the SELECT permission on a materialized view to a user, run:
GRANT SELECT ON <mv_name> TO '<user>'@'%';Replace <mv_name> with the name of the materialized view and <user> with the target username.
Query a materialized view
The syntax for querying a materialized view is identical to querying a standard table or view. Materialized views work with all SQL syntax, including SELECT, INSERT INTO SELECT, and WITH.
Example:
SELECT *
FROM adbview
WHERE device = 'PC'
AND city = 'Beijing';Data freshness
Materialized views store a snapshot of data at the time of the last refresh. If the base tables are updated after the last refresh, the materialized view does not reflect those changes, and query results may be outdated.
If you need the latest data, refresh the materialized view after each base table update before running queries. See Refresh a materialized view.