fix(backfill): chunk mv_replay from the MV source so empty targets bootstrap (#187)#188
Merged
alvarogar4 merged 1 commit intoJul 8, 2026
Conversation
…otstrap (#187) An mv_replay backfill of a from-scratch empty aggregate target failed with "No partitions found for <target>". Chunk planning introspected the target's system.parts to size chunks and empty-checked it — but for mv_replay the target is legitimately empty (you're bootstrapping it), and the data actually read/sized is the view's source (its FROM table). Detect the strategy before chunk planning and, for a single shared MV source, run generateChunkPlan against that source instead of the target. The empty-check now guards the source; the copy path and multi-source fan-in (#185) are unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013tzRKHhZETTZtQtDe999Fi
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 #187. A
mv_replaybackfill of a from-scratch empty aggregate target failed withNo partitions found for <target>. The table may be empty.Chunk planning introspected the target'ssystem.partsto size chunks and empty-checked it — but formv_replaythe target is legitimately empty (you're bootstrapping it), and the data actually read/sized is the view's source (itsFROMtable), not the target.The fix detects the execution strategy before chunk planning and, for
mv_replaywith a single shared source, runsgenerateChunkPlanagainst that source table instead of the target:chunking/sql.ts—extractSourceTableRef()parses the first top-levelFROMtable out of a view'sSELECT(handlesdb.table, bare table, backticks; rejects subqueries/table functions), reusing the existing quote/paren-aware scanner.detect.ts—resolveMvReplaySource()collapses the MVs feeding a target to a single shared source (unqualifiedFROMdefaults to the view's database). Returnsundefined— falling back to target introspection — when a source is unparseable or the views fan in from different sources, preserving the multi-source replay behaviour from fix(backfill): replay every MV feeding the target, not just the first (NUM-7480) #185.planner.ts—buildBackfillPlannow detects the strategy first, chunks the resolved source for single-sourcemv_replay, and the empty-check guards the introspected table (an empty source still fails fast). Thecopypath is unchanged.Behaviour preserved
copybackfills: unchanged (introspect the target == source).Test plan
extractSourceTableRef(qualified/bare/backtick/alias/subquery/table-function/string-literalFROM),resolveMvReplaySource(single, shared, unqualified, differing sources, subquery).mv-replay-plan.e2e.test.ts, live ObsessionDB): populated source + empty SummingMergeTree target + MV →buildBackfillPlanplans one chunk per source partition,executeBackfillpopulates the target, per-bucket values match the forward MV output.typecheck+lintpass; existingplanner/detect/sql/copy-path e2e tests green.🤖 Generated with Claude Code
https://claude.ai/code/session_013tzRKHhZETTZtQtDe999Fi