Bailey Kocin
04/01/2026, 2:22 PMRocky
04/01/2026, 2:23 PMsql
REFRESH MATERIALIZED VIEW your_mv_name;
You can also set up an automatic refresh strategy (e.g., REFRESH ASYNC EVERY (INTERVAL 1 MINUTE)) so the window of "staleness" is minimized.
2. The "Loose" Consistency Workaround
If you don't mind querying slightly stale data in exchange for the performance of the MV, you can change the consistency requirements. You can do this by altering the MV properties:
* Set Consistency to LOOSE: This tells StarRocks to use the MV for query rewrite even if the base table has changed since the last refresh.
sql
ALTER MATERIALIZED VIEW your_mv_name SET ("query_rewrite_consistency" = "loose");
Note: The default is checked.
* Set a Staleness Threshold: If you want to allow the MV to be used only if it's "not too old," you can use the staleness property (introduced in v3.0+). For example, to allow rewrite if the MV was refreshed within the last 5 minutes:
sql
ALTER MATERIALIZED VIEW your_mv_name SET ("mv_rewrite_staleness_second" = "300");
3. How to verify the rewrite
To see exactly why the optimizer is (or isn't) choosing your MV, you can run an EXPLAIN on your query:
sql
EXPLAIN REWRITE SELECT ... FROM your_table;
Look for the Materialized View Rewrite Success or Failure section in the output. If it fails, it will often provide a reason, such as "materialized view is outdated."
Summary of properties
Property | Description
query_rewrite_consistency | Set to loose to allow rewrite even if data is inconsistent.
mv_rewrite_staleness_second | Defines a "grace period" (in seconds) where the MV is still eligible for rewrite after a base table update.
If you're on a version later than v3.2, you can also experiment with the session variable SET materialized_view_rewrite_mode = 'force'; to encourage the optimizer to prioritize the MV, though the consistency properties mentioned above are usually the most effective way to handle update-driven staleness.
References
• using_starrocks/async_mv/use_cases/query_rewrite_with_materialized_views.md
• sql-reference/System_variable.md
• administration/management/FE_configuration.md
• using_starrocks/async_mv/feature-support-asynchronous-materialized-views.md