fix(backfill): replay every MV feeding the target, not just the first (NUM-7480)#185
Merged
alvarogar4 merged 1 commit intoJul 7, 2026
Conversation
… (NUM-7480) mv_replay rebuilt a target table from only the first materialized view whose `to` matched it. ClickHouse allows several MVs to share one destination table, so the rest were silently dropped and the backfill came out incomplete. Collect all MVs targeting the table and replay them in a single `INSERT INTO target SELECT … UNION ALL SELECT …` per chunk, so one query id and one idempotency token still cover the chunk. Single-MV plans emit byte-identical SQL. Covers the local `run` and managed `submit` paths (both build chunk SQL through the shared builder). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MgxmdeV7WhPGGxDfv5H2Jp
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes NUM-7480.
backfillmv_replay rebuilt a target table from only the first materialized view whosetomatched it. ClickHouse allows several MVs to share one destination table, so the rest were silently dropped and the backfill came out incomplete.detect.ts:findMvForTarget→findMvsForTarget— returns every MV feeding the target.planner.ts/types.ts: the plan now carriesmvReplayQueries: string[](renamed frommvAsQuery).chunking/sql.ts:buildChunkExecutionSqlreplays all MV queries in a singleINSERT INTO target SELECT … UNION ALL SELECT …per chunk, so one deterministicquery_idand oneinsert_deduplication_tokenstill cover the chunk (separate statements would break query-id tracking and dedup-drop every insert after the first). Single-MV plans emit byte-identical SQL.run(plugin.ts) and managedsubmit(plugin-obsessiondb).mv_replaystrategy description for multi-MV targets.Clean rename with no back-compat shim —
@chkit/plugin-backfillis0.1.2-beta, plans are ephemeral/regenerated and read via plainJSON.parse.Test plan
findMvsForTargetreturns all matching MVs; planner produces a 2-elementmvReplayQueries+UNION ALLSQL; managedsubmitpath does the same.typecheck,lint,buildpass;@chkit/plugin-backfilland@chkit/plugin-obsessiondbtest tasks (incl. live e2e) pass underbun verify.WHEREinjection, preservedGROUP BYs, single trailingSETTINGS/dedup token.🤖 Generated with Claude Code