agentleFS
apacheapache/doris-skills/skills/doris-debug/materialized-view/SKILL.md

doris-debug-materialized-view

Skill50 starsChanged 13 days agoApache-2.0View on GitHub

Use for Doris sync MV (rollup) miss or async MTMV refresh/rewrite issues. Commands: SHOW ALTER TABLE MATERIALIZED VIEW, mv_infos(), EXPLAIN, REFRESH MATERIALIZED VIEW.

The file

Files
SKILL.md

Materialized View

Kind comparison

KindCode areaCheckRewrite mechanism
SyncMaterializedViewHandler / rollupSHOW ALTER TABLE MATERIALIZED VIEWTransparent — planner auto-selects
Async MTMVfe/.../mtmv/mv_infos() RefreshStateCBO-based — EXPLAIN shows if matched

Causes

IDCauseEvidenceKind
ASync MV build pending/stuckSHOW ALTER TABLE MATERIALIZED VIEW State≠FINISHEDSync
BMTMV refresh failedmv_infos() RefreshState=FAILAsync
CMTMV rewrite missEXPLAIN shows no MATERIALIZED_REWRITEAsync
DMTMV data stalemv_infos() LastRefreshTime oldAsync
EMV not selected by plannerEXPLAIN shows TABLE SCAN not MATERIALIZEDEither

10 min triage

-- Sync MV status
SHOW ALTER TABLE MATERIALIZED VIEW FROM db;

-- Async MTMV status
SELECT * FROM mv_infos('database'='db') WHERE Name='mv'\G

-- Check rewrite eligibility
EXPLAIN VERBOSE SELECT ...;

-- Force refresh
REFRESH MATERIALIZED VIEW mv;

-- Enable external MV rewrite (for catalog queries)
SET materialized_view_rewrite_enable_contain_external_table = true;

Cause C — MTMV rewrite miss

Common reasons (see fe/.../mtmv/MTMVService.java rewrite matcher):

  1. Partition misalignment: MV has partition_sync=false and query partition doesn't match → ALTER MATERIALIZED VIEW mv SET ("partition_sync" = "true")
  2. Aggregation granularity: MV groups by (a, b) but query groups by (a) only → MV is not a valid rewrite target
  3. Filter mismatch: MV WHERE clause doesn't cover query WHERE clause → check MV definition
  4. Session var off: SET enable_materialized_view_rewrite = true
-- Debug: force the optimizer to log MV matching
SET enable_materialized_view_rewrite_debug_log = true;
EXPLAIN VERBOSE SELECT ...;  -- check fe/log/fe.audit.log for MV match details

Cause A — Sync MV stuck

-- Cancel stuck build
CANCEL ALTER TABLE MATERIALIZED VIEW FROM db ON table;

-- Check BE compaction queue (MV build competes with compaction)
./scripts/doris-debug be-metrics --be http://$BE:8040 --grep compaction

Source

  • fe/.../mtmv/MTMVService.java — MTMV lifecycle
  • fe/.../alter/MaterializedViewHandler.java — sync MV alter
  • fe/.../materializedview/MaterializedViewRewriter.java — rewrite logic
  • SessionVariable.java — enable_materialized_view_rewrite, materialized_view_rewrite_enable_contain_external_table

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.