starrocks/starrocks-debug-skills/materialized-view

Claude Code and agent skill by starrocks/starrocks-debug-skills

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Use when async materialized views are failing to refresh, timing out, becoming inactive, or query rewrite is not triggering. Covers refresh OOM (spill-to-disk), timeout tuning, MV reactivation, staleness tolerance for query rewrite, sync MV hit verification via EXPLAIN, FE restart impact on refresh schedules, and S3 rate limiting during refresh.

Install

npx vskill@latest install starrocks/starrocks-debug-skills/materialized-view

SKILL.md

Materialized View Troubleshooting

Investigation guide for async MV refresh failures, refresh timeouts, MV inactivation, query rewrite failures, and sync MV optimization.

Five root causes account for the vast majority of cases:

  • Cause A — refresh OOM (memory exhaustion during materialization)
  • Cause B — refresh timeout (SQL takes longer than configured limit)
  • Cause C — MV inactive (base table schema change or manual deactivation)
  • Cause D — query rewrite not used (structural mismatch, staleness, or disabled)
  • Cause E — schedule persistence issue (FE restart breaks scheduler timing)

Metric Taxonomy — Read This First

Before using any metrics, understand the three observability layers:

MV state observability

`SHOW MATERIALIZED VIEWS` — primary MV health check:

FieldMeaning
is_activeWhether the MV is active (true = can refresh and rewrite)
last_refresh_stateState of the last refresh: SUCCESS, FAILED, RUNNING
last_refresh_error_messageError detail when last_refresh_state = FAILED
last_refresh_timeTimestamp of the last completed refresh
last_refresh_duration_msDuration of the last refresh in milliseconds
inactive_reasonWhy the MV was deactivated (schema change, explicit call)
refresh_typeASYNC / MANUAL / SCHEDULED
next_refresh_timeNext scheduled refresh (for scheduled MVs)
Refresh task observability
sql
-- Refresh history with error details
SELECT task_name, state, error_message, start_time, finish_time,
TIMESTAMPDIFF(SECOND, start_time, finish_time) AS duration_sec
FROM information_schema.task_runs
WHERE task_name LIKE 'mv-%'
ORDER BY start_time DESC LIMIT 20;
-- Running refresh tasks right now
SELECT * FROM information_schema.task_runs
WHERE state = 'RUNNING';
Resource consumption observability
sql
-- Queries running during refresh (to identify resource contention)
SHOW PROC '/current_queries' \G
-- Analyze a specific refresh profile (get profile_id from task_runs)
ANALYZE PROFILE FROM '<profile_id>';
Rewrite verification
sql
-- Check if a query uses MV rewrite
EXPLAIN LOGICAL SELECT ...;
-- Look for "SCAN [mv_name]" in output — if the base table name appears instead, rewrite did not fire
-- Trace why rewrite was not used (v3.2+)
TRACE LOGS MV SELECT ...;
TRACE REASON MV SELECT ...;
-- Sync MV: check via EXPLAIN
EXPLAIN SELECT ... FROM <table>;
-- Look for "Rollup: <mv_name>" and "PREAGGREGATION: ON"
How to retrieve metrics

Option 1 — SQL (primary method)

sql
-- Overall MV health
SHOW MATERIALIZED VIEWS;
-- Refresh history
SELECT * FROM information_schema.task_runs
WHERE task_name = 'mv-<mv_id>' \G
-- Resource usage during refresh
SHOW PROC '/current_queries' \G

Option 2 — FE log grep

bash
# Refresh start/end events
grep "Start refresh materialized view\|End refresh materialized view" fe.log | tail -30
# Refresh failures
grep "refresh.*failed\|MV.*inactive\|refresh.*timeout" fe.log | tail -30
# Scheduler timing issues
grep "initialDelay\|scheduleRefresh\|task_runs" fe.log | tail -30

Default HTTP ports: FE = 8030. Profile UI at http://<fe_ip>:8030.


Key rules for interpretation:

  1. is_active = false blocks both refresh and query rewrite — restoring active state is always the first step when queries are not rewriting.
  2. last_refresh_state = FAILED with last_refresh_error_message containing OOM → Cause A. Containing timeout → Cause B. Containing schema change → Cause C.
  3. If last_refresh_time diverges from now() by more than mv_rewrite_staleness_second, the MV will not be used for rewrite unless query_rewrite_consistency = LOOSE.
  4. TRACE LOGS MV output contains MV_REWRITE_FAIL_REASON — read this before assuming structural incompatibility.

MV Issue Reference

PhenomenonRoot causeQuick confirmation
Refresh ends quickly with FAILED stateOOM (Cause A)last_refresh_error_message contains OOM or heap detail; fe.gc.log shows Full GC
Refresh hangs then failsTimeout (Cause B)last_refresh_error_message contains timeout; task_runs.duration_sec > insert_timeout value
MV not refreshing at allInactive (Cause C)is_active = false in SHOW MATERIALIZED VIEWS; check inactive_reason
EXPLAIN shows base table scan despite MV existingRewrite not used (Cause D)TRACE LOGS MV shows MV_REWRITE_FAIL_REASON; or MV is stale / inactive
Scheduled refresh stops firing after FE restartSchedule persistence (Cause E)Compare next_refresh_time vs current time; FE log shows wrong initialDelay

Phase 1 — Confirm MV Issue Type

Step 1.1 — Check overall MV state
sql
-- Run on FE (any node, but Leader gives authoritative state)
SHOW MATERIALIZED VIEWS;

Classify based on output:

is_activelast_refresh_stateClassification
falseanyCause C — MV inactive (fix active state first)
trueFAILEDCause A or B (read error message to distinguish)
trueSUCCESSCause D — check query rewrite
trueSUCCESSCause E — check schedule timing
trueRUNNING for > expected timeCause B — refresh running too long
Step 1.2 — Check refresh history
sql
SELECT task_name, state, error_message,
start_time, finish_time,
TIMESTAMPDIFF(SECOND, start_time, finish_time) AS duration_sec
FROM information_schema.task_runs
WHERE task_name LIKE 'mv-%'
ORDER BY start_time DESC LIMIT 10;
  • error_message contains Out of memory or java.lang.OutOfMemoryError → Cause A
  • error_message contains timeout or insert_timeout → Cause B
  • state = FAILED, error_message contains schema → Cause C
  • All states SUCCESS but query plan shows base table → Cause D
  • No task runs scheduled despite past refresh interval → Cause E

Phase 2 — Investigate Root Cause

Step 2.1 — For FAILED refreshes (Cause A or B)
bash
# Check FE GC log for OOM evidence
grep "Full GC\|OutOfMemory" fe.gc.log | tail -20
# Check FE heap usage around refresh time
grep "heap" fe.log | grep -A2 "Start refresh" | tail -20
sql
-- Profile the last failed refresh (if profile_id is available)
ANALYZE PROFILE FROM '<profile_id>';
-- Look for: which operator consumed the most memory
-- Look for: which stage timed out
Step 2.2 — For inactive MV (Cause C)
sql
SHOW MATERIALIZED VIEWS;
-- Check: inactive_reason column
-- Common values: "base table schema changed", "manually set inactive"
Step 2.3 — For rewrite miss (Cause D)
sql
-- Confirm MV is active and fresh
SHOW MATERIALIZED VIEWS;
-- is_active = true AND last_refresh_time is recent
-- Trace the rewrite decision
TRACE LOGS MV SELECT ...;
-- Look for MV_REWRITE_FAIL_REASON in output

Common rewrite blockers:

  • Nested aggregation in query not supported by MV structure
  • Join + aggregation combination not covered by MV
  • Query filter column not included in MV SELECT
  • MV data is stale beyond staleness tolerance
  • query_rewrite_consistency = DISABLE set at session level
Step 2.4 — For schedule persistence (Cause E)
bash
# Check if FE was recently restarted
grep "FE started\|system start" fe.log | tail -5
# Check initialDelay calculation in scheduler
grep "initialDelay\|scheduleRefresh" fe.log | tail -20
sql
-- Check next_refresh_time vs now
SELECT mv_name, last_refresh_time, next_refresh_time,
TIMESTAMPDIFF(MINUTE, now(), next_refresh_time) AS minutes_until_refresh
FROM information_schema.materialized_views;
-- If minutes_until_refresh is very large (e.g., > 1440 min for a daily MV) → schedule broken

Phase 3 — Take Action by Cause

Cause A — Refresh OOM

Step A-1: Enable spill to disk (immediate, no restart)

sql
ALTER MATERIALIZED VIEW <mv_name> SET ('session.enable_spill' = 'true');

Step A-2: Increase FE heap (requires FE restart)

bash
# In fe.conf or JVM args
-Xmx16g # increase from default (e.g., 8g)

Step A-3: Reduce per-refresh data volume

sql
-- Partition-by-partition refresh (incremental)
ALTER MATERIALIZED VIEW <mv_name>
REFRESH ASYNC START('2024-01-01 00:00:00') EVERY (INTERVAL 1 HOUR);
-- Or set partition batch size
ALTER MATERIALIZED VIEW <mv_name>
SET ('mv_refresh_partition_batch_num' = '1');

Step A-4: Emergency stop if OOM is cascading

sql
CANCEL REFRESH MATERIALIZED VIEW <mv_name>;
-- Or deactivate until fixed:
ALTER MATERIALIZED VIEW <mv_name> INACTIVE;

Cause B — Refresh timeout

Step B-1: Extend timeout (dynamic)

sql
-- v3.2+: default 1 hour; pre-v3.2: default 5 min
ALTER MATERIALIZED VIEW <mv_name>
SET ('session.insert_timeout' = '7200'); -- seconds

Step B-2: Profile the refresh SQL

sql
-- Get the refresh SQL from MV definition
SHOW CREATE MATERIALIZED VIEW <mv_name>;
-- Run the SQL manually with profiling to find the bottleneck
SET enable_profile = true;
-- Execute the refresh SQL
-- Then: SHOW PROC '/current_queries' for profile_id
ANALYZE PROFILE FROM '<profile_id>';

Step B-3: Add a resource group for heavy refreshes

sql
-- Create a dedicated resource group
CREATE RESOURCE GROUP rg_mv
TO (role='root')
WITH (
'cpu_core_limit' = '4',
'mem_limit' = '0.3',
'big_query_cpu_second_limit' = '0',
'big_query_scan_rows_limit' = '0',
'big_query_mem_limit' = '0',
'type' = 'normal'
);
-- Assign to MV
ALTER MATERIALIZED VIEW <mv_name>
SET ('resource_group' = 'rg_mv');

Note: default resource group default_mv_wg has cpu_core_limit=1 which throttles large refreshes.


Cause C — MV inactive

Step C-1: Restore active state

sql
ALTER MATERIALIZED VIEW <mv_name> ACTIVE;

Step C-2: If `ACTIVE` fails (schema incompatibility)

sql
-- Check what changed in the base table
SHOW CREATE TABLE <base_table>;
SHOW CREATE MATERIALIZED VIEW <mv_name>;
-- Drop and recreate the MV with updated definition
DROP MATERIALIZED VIEW <mv_name>;
CREATE MATERIALIZED VIEW <mv_name>
REFRESH ASYNC
AS <updated_select>;

Step C-3: Prevent future deactivation from schema changes

When altering base tables that have MVs, test the MV definition against the new schema before applying the DDL. After any base table ALTER TABLE, immediately run:

sql
SHOW MATERIALIZED VIEWS;
-- Check is_active; reactivate if needed

Cause D — Query rewrite not used

Step D-1: Check staleness tolerance

sql
-- Allow rewrite even when MV is slightly stale
ALTER MATERIALIZED VIEW <mv_name>
SET ('query_rewrite_consistency' = 'LOOSE');
-- Or set allowed staleness window in seconds
ALTER MATERIALIZED VIEW <mv_name>
SET ('mv_rewrite_staleness_second' = '300');

Step D-2: Check session-level rewrite settings

sql
-- Ensure rewrite is enabled at session level
SET enable_materialized_view_rewrite = true;
SET materialized_view_rewrite_mode = 'default'; -- or 'force'

Step D-3: Trace and fix structural mismatches

sql
TRACE LOGS MV SELECT ...;
-- Read MV_REWRITE_FAIL_REASON in output

Common structural fixes:

  • Nested aggregation unsupported: flatten the MV definition; avoid SELECT SUM(SUM(x)) patterns
  • Join + aggregation unsupported: separate the join and aggregation, or use a flat MV
  • Filter column not in MV SELECT: add the filter column to MV SELECT

Step D-4: Verify sync MV hit

sql
EXPLAIN SELECT ... FROM <table>;
-- Must see: "Rollup: <mv_name>" and "PREAGGREGATION: ON"
-- If see base table name → sync MV not hitting

For sync MVs, supported aggregations: sum, min, max, count, bitmap_union, hll_union. Sync MVs on Duplicate/Aggregate models only — not Primary Key model.


Cause E — Schedule persistence issue

Step E-1: Confirm the broken schedule

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/starrocks/starrocks-debug-skills/materialized-view/badge)](https://verified-skill.com/skills/starrocks/starrocks-debug-skills/materialized-view)

Something wrong with this skill or its page? Tell us.