Jonathan Du
02/18/2026, 3:53 AMJonathan Du
02/18/2026, 4:49 AMRocky
02/18/2026, 4:49 AMTony Wasson
02/18/2026, 8:34 PMRocky
02/18/2026, 8:35 PMCREATE MATERIALIZED VIEW without the REFRESH keyword) are essentially indexes that are updated in real-time whenever the base table is modified.
When you perform a DELETE (or UPDATE) on a base table that has a synchronous MV:
1. StarRocks must also update the data within that MV index to keep it consistent.
2. To perform this update efficiently, the engine requires that the columns used in the WHERE clause of your `DELETE`/`UPDATE` statement must exist in the synchronous materialized view.
In your example:
• Your base table orders has the column user_id.
• Your MV orders_daily_volume is defined as:
sql
SELECT
DATE_TRUNC('day', dt) as day,
SUM(amount) as amount
FROM jdu.orders
GROUP BY day;
• This MV only contains the columns day and amount. It does not contain user_id.
• When you run DELETE FROM jdu.orders WHERE user_id = '2', the engine tries to apply this filter to the orders_daily_volume index to identify which records to update/remove, but it fails because user_id is missing from that index.
Solutions
1. Use Asynchronous Materialized Views (Recommended)
If you need to perform frequent DELETE or UPDATE operations on arbitrary columns, it is recommended to use Asynchronous Materialized Views.
Asynchronous MVs are independent physical tables. Deleting data from the base table does not require an immediate, synchronous update of the MV index, so there are no restrictions on the WHERE clause columns.
sql
CREATE MATERIALIZED VIEW jdu.orders_daily_volume
REFRESH ASYNC EVERY(INTERVAL 1 MINUTE) -- or REFRESH DEFERRED
AS
SELECT
DATE_TRUNC('day', dt) as day,
SUM(amount) as amount
FROM jdu.orders
GROUP BY day;
2. Include the column in the Synchronous MV
If you must use a Synchronous MV, you would need to include the filtering column (user_id) in the MV's GROUP BY clause. However, this changes the granularity of your aggregation:
sql
CREATE MATERIALIZED VIEW jdu.orders_daily_volume
AS
SELECT
DATE_TRUNC('day', dt) as day,
user_id, -- Adding this allows DELETE WHERE user_id = ...
SUM(amount) as amount
FROM jdu.orders
GROUP BY day, user_id;
3. Drop the MV before the operation
If this is a one-time maintenance task, you can drop the synchronous MV, perform your DELETE, and then recreate the MV.
For more details, you can check the StarRocks documentation on Synchronous Materialized Views.
References
• using_starrocks/Materialized_view-single_table.md
• using_starrocks/async_mv/use_cases/query_rewrite_with_materialized_views.md
• sql-reference/sql-statements/materialized_view/CREATE_MATERIALIZED_VIEW.md
• sql-reference/sql-statements/table_bucket_part_index/DELETE.mdJonathan Du
02/18/2026, 10:07 PM