Repository navigation
feat(types): name a materialized view by its view state key and plan id (#1429) - #1536
Merged
Merged
Conversation
zzylol
force-pushed
the
feat/view-state-key
branch
from
November 27, 2026 17:45
8d5a968 to
2042383
Compare
Phase 2 of #1429, tests first. A materialized view's stored state is named by ViewStateKey { definition_id, window, logical_properties }, taken from the view node alone, and an installed plan by its content id, PhysicalASAPDAG::plan_id. The tests check that: - views differing only in θ or in the view node's window width get different keys; - views differing only in refresh mode, retention or storage medium get one key and different plan ids; - merges of one range over 1-minute and 5-minute chains share a key; - the three planned views of one coverage in the chains-10m-5m-3m-10s workload get distinct keys; - a view planned in two workloads keeps its key; - the key is pinned and round-trips through JSON; - the plan id round-trips through a plan file, changes only with the plan, and is pinned for a committed plan file; - a store keyed by (view state key, time range) answers the five tumbling windows, and a k = 400 query misses k = 200 states. Two known limitations are ignored tests: #1493 (a finalized exact aggregate has no coverage) and #1494 (coverage depends on where a filter sits). plan_id, MaterializedView::plan_id and MaterializedView::view_state_key are todo!() stubs. LogicalProperties gains PartialEq, Eq, Hash and serde, and SketchParams gains Eq and Hash, so the key can key a hash map.
…id (#1429) A deployment filed stored view states by the view's coverage (definition_id and selection), which leaves out θ and the view's tumbling-window width: the three views of the planned chains-10m-5m-3m-10s workload (a 5-minute chain, a 10-second chain and 60-second windows merged from it) share one coverage. - PhysicalASAPDAG::plan_id: the content id of the plan's DAG (128-bit FNV-1a of its JSON, the hash definition_id already uses, moved to plan::content_id). With node_id it names a view in one installed plan. - MaterializedView::view_state_key: ViewStateKey { definition_id, window, logical_properties }, from the view node alone. A store keys states by it and the concrete selection, across plans. - MaterializedView::plan_id; MaterializedView::coverage and ViewCoverage::definition_id/selection are public. - asap-types turns on serde_json's float_roundtrip, so a plan file read back has the plan id it was written with. - Docs: physical-planning-and-deployment.md section 4 explains the two scopes and the layering; the DataStore doc, the primitive-schema proposal and the DAG viewer README follow.
…hain's windows in its key (#1429) Review fixes: - ViewWindow::of_node walks a TimeRange or TimeShift down to the chain it selects windows from, and gives a TimeRangeCover its levels' widths (ViewWindow::TumblingLevels): TimeRange(5m, Chain[1m]) and TimeRange(5m, Chain[5m]) hold 5 rows and 1 row and no longer share a key. - ViewStateKey::of_view builds the key next to its type. - The two-workload test matches views by operator before comparing keys. - Docs: plan-id equality is equality of serializations; the five-window example names the views it means; the store contract names the key.
…view_state_key (#1429) 22 snapshots with materialized views gain plan_id and view_state_key per view. Nothing else changes: every plan, cost and coverage is as before. 43 of the 54 views share their coverage with another view of their plan; all 54 have distinct keys.
- ViewStateKey::of_view takes the view's coverage and the DAG's node map instead of a lookup closure; Candidate::new builds its logical properties with LogicalProperties::of_parameters. - A TimeRangeCover level that is no chain is a planner bug (debug_assert) rather than a silent loss of the window; a test keys a cover view's levels' widths. - The #1493 test duplicated #1535's a_finalized_rate_covers_what_the_rate_covers: removed, and that test now also asserts equal view coverages. - The integration tests share one view_over_chain helper. - Docs: concrete selection throughout; the key relies on chains serving only readers on their grid; the test table names the θ test.
…two stale snapshots (#1429) #1537 changed two sketch plans at the committed cost, so their snapshots on main passed without being rewritten: chains-10m-5m-3m-10s now sizes its KLL chains with k = 2863 (was 1404), and sql-rollup-quantile-same-window keeps one more node's result. With plan_id and view_state_key removed, every regenerated snapshot equals the one main writes itself. The pinned 5-minute chain key follows (k = 2863).
zzylol
force-pushed
the
feat/view-state-key
branch
from
November 27, 2026 19:59
2042383 to
220e0e5
Compare
This was referenced Nov 27, 2026
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
definition_id,selection). Coverage leaves out θ and the view's tumbling-window width. In the plannedchains-10m-5m-3m-10sworkload, three views share one coverage: a 5-minute chain, a 10-second chain, and 60-second windows merged from the 10-second chain. Across the 22 snapshots with views, 43 of 54 views share their coverage with another view of the same plan.MaterializedView::view_state_key()says what the stored state is, in any plan:ViewStateKey { definition_id, window, logical_properties }, taken from the view node alone.PhysicalASAPDAG::plan_id()(alsoMaterializedView::plan_id()) is a content hash of the DAG. Withnode_id, it names a view inside one installed plan.(ViewStateKey, concrete selection). All 54 snapshot views get distinct keys. Plans, costs and the plan-file format (INSTALLABLE_PLAN_WIRE_VERSION) are unchanged.Review guide
main. Not stacked.crates/types/src/plan/materialized_view/view_state_key.rs: the key, and the rule for which window a view has.crates/types/src/plan/materialized_view/views.rs(ViewIndex::views): where both ids are set.crates/types/src/plan/content_id.rs: the hash, moved here fromview_coverage.rs.docs/design_docs/physical-planning-and-deployment.md§4, "Identifying a materialized view".ViewWindow::of_node: which window each view gets.EqandHashonSketchParams(summary_type/parameters.rs).float_roundtripincrates/types/Cargo.toml.plan_idandview_state_keyto each view, plus the two inherited plan changes listed under Verification.fnv1a_128_hexmoved unchanged.Behavior: before → after
Input: the committed sketch workload
crates/planner-cli/tests/sketch_plan_snapshots/workloads/chains-10m-5m-3m-10s.json:quantile_over_time(0.5, data[10m])andquantile_over_time(0.9, data[5m])every 5 min, andquantile_over_time(0.99, data[3m])every 10 s, each withmax_error0.01 andfailure_probability0.001. Raw data is not retained (mvp.capabilities.json).Invocation:
The plan's
materialized_views:view_state_keySummaryTumblingWindowChain, 300 sdefinition_idbfbffb8f…, selection[{"columns": []}]bfbffb8f…,window: {"tumbling": {"width_ms": 300000}},parameters: {"Kll": {"k": 2863}}SummaryTumblingWindowChain, 10 sbfbffb8f…,window: {"tumbling": {"width_ms": 10000}},Kll {k: 1404}SummaryMergeWindows, 10 s → 60 sbfbffb8f…,window: {"tumbling": {"width_ms": 60000}},Kll {k: 1404}All three share
"plan_id": "f6f31722b12fc85f69ff48e068761870".(T-5m, T]with node 10's thirty 10-second rows. The executor never re-filters a view read.Who needs it: any runtime that keeps view states, and especially one that keeps them across restarts or replanning. The plan-independent key lets it reuse a stored state under a new plan.
(plan_id, node_id)addresses a view within the installed plan.Interfaces
Permalinks are at the PR head,
220e0e5.crates/types/src/plan/materialized_view/view_state_key.rs(new)crates/types/src/plan/materialized_view/mod.rscrates/types/src/plan/physical_asap_dag.rsimpl PhysicalASAPDAG { + /// The plan's content id: the 128-bit FNV-1a hash, in hex, of its JSON. Equal + /// for equal serializations across processes and plan-file round trips. + pub fn plan_id(&self) -> String; } impl ViewCoverage { + /// Logical: equal for views of different θ or widths, so not a store key alone + /// (was test-support only). + pub fn definition_id(&self) -> &str; + /// The rows that went in (was test-support only). + pub fn selection(&self) -> &[SelectionBox]; }crates/types/src/stages/logical/candidate/mod.rsandcrates/types/src/summary_type/parameters.rscrates/types/Cargo.toml:serde_jsongainsfloat_roundtrip, so a plan file read back has the plan id it was written with.Plan-file format: unchanged;
INSTALLABLE_PLAN_WIRE_VERSIONstays 15. CLI JSON: eachmaterialized_views[]entry gainsplan_idandview_state_key.Usage
Adapted from
view_state_key::planned_views_of_one_coverage_get_distinct_view_state_keysand the pinned-key test, which run at the PR head; the store lines are illustrative.Algorithm changes
None. No search, sizing or cost changes in this PR; the only plan and cost differences in the snapshots are the two inherited from
main(#1537), listed under Verification.Decisions and open questions
Needs reviewer decision: none.
Decided (2026-11-27):
LogicalProperties.SummaryMerge(TimeRange(5m, Chain[1m]))andSummaryMerge(TimeRange(5m, Chain[5m]))share a key.LogicalProperties. The per-node fields that comment asks for already exist (parametersand the operator payload), and(plan_id, node_id)gives the per-plan address it asks for.parametersfield viaLogicalProperties::of_parameters.LogicalProperties, which would need a wire-version bump and would rewrite every plan snapshot.plan_idis the content id of the DAG only, and it is set on everyMaterializedView.SketchParamshashing.Hashis the hash of its JSON text.float_roundtripis on.debug_assert), so the key never silently drops a window.TimeRangeorTimeShiftview over a chain takes the chain's width.TimeRangeCoverview takes its levels' widths (TumblingLevels). This came from review.window: None.Verification
All runs used
cargo1.100 on an eval host, on this branch rebased ontomainate727be3(after #1535 and #1537).maincargo test -p asap-typescargo test -p asap-types --test types -- known_limitation --include-ignoreddefinition_id5a060b84…≠a7a6e6a7…cargo test -p asap-integration-testscargo test -p asap-stage3-plan-selection --libcargo test -p asap-executor --libcargo test -p asap-planner-cli --test planner_clicargo test --release -p asap-planner-cli --test corpus_snapshots -- --ignored(corpus + sketch snapshots)UPDATE_SNAPSHOTS=1; diffs belowcargo test --release -p asap-planner-cli --test goldenscargo fmt --all --check,cargo clippy -p asap-types -p asap-executor -p asap-integration-tests -p asap-planner-cli --all-targets -D warningsNew tests. On
mainnone of them compiles (the #1535 test extension aside). Before the implementation, each failed withnot yet implemented, except where noted.kll_tumbling_window_execution::views_differing_only_in_sketch_parameters_have_different_view_state_keys: KLL k=200 vs k=400 have one coverage and different keys.view_state_key::chain_views_differing_only_in_window_width_have_different_view_state_keys: a 1-minute vs a 5-minute chain view.view_state_key::time_range_views_over_chains_of_different_widths_have_different_view_state_keys:TimeRange(5m)over a 1-minute vs a 5-minute chain (from review).view_state_key::merges_of_one_range_over_chains_of_different_widths_share_a_view_state_key: equivalent merges share a key.view_state_key::a_time_range_cover_view_keys_its_levels_widths: aTimeRangeCoverview's window is{"tumbling_levels": {"widths_ms": [300000, 60000]}}(from review).coverage_finalize::a_finalized_rate_covers_what_the_rate_covers(from fix(types): a finalized exact state covers what its aggregate covers #1535) now also asserts equalview_coverages, so a finalizedrateandAggregate(Rate)get one key.view_state_key::views_differing_only_in_refresh_retention_or_medium_have_equal_view_state_keys: one key, two plan ids.view_state_key::planned_views_of_one_coverage_get_distinct_view_state_keys: the three planned views above.view_state_key::the_view_state_key_of_a_planned_chain_is_pinned_and_round_trips_through_json: node 1's key, written out; its JSON reads back equal.view_state_key::a_view_planned_in_two_workloads_keeps_its_view_state_key:quantile_over_time(0.99, data[5m])alone and besidesum_over_time(other[1m]). Each view keeps its key, and the plan ids differ.physical_asap_dag::the_plan_id_survives_a_plan_file_round_trip: a literal1.0715660391465826e-75reads back bit-exact with the same plan id. Beforefloat_roundtripit read back as…825e-75.physical_asap_dag::the_plan_id_changes_with_the_plan_and_only_with_it: retention, θ, lifetime and a literal change the id;selected_physical_candidatedoes not.materialized_views::the_plan_id_of_a_committed_plan_file_is_pinned:90231c1c36f2b1660ed23d24725d635f.kll_tumbling_window_execution::a_store_keyed_by_view_state_key_and_time_range_answers_the_tumbling_windows: the renamed keyed-store test; the five shifted views share one key.kll_tumbling_window_execution::a_store_keyed_by_view_state_key_misses_states_of_another_sketch_parameter: a k=400 query over k=200 states fails with "no state for". A key ofdefinition_idalone would have answered it.Snapshot changes: 22 files. Two of them also carry plan changes that come from
main(#1537), whose committed snapshots passed at equal cost without being rewritten:chains-10m-5m-3m-10s-mvp: the 5-minute chain (node 1) and the nodes reading it are sized withk = 2863(was 1404); the 10-second chain and its merged windows stay at 1404. The cost is the committed one.sql-rollup-quantile-same-window-raw-retained: node 9's lifetime changes; its detail line goes from "holds 24 bytes" to "holds 240 bytes", its cost per second from 1.8740000046e-15 to 1.87400004601e-15,average_memory_bytesfrom …351778 to …351779 andpeak_memory_bytesfrom 3255584 to 3255800.With
plan_idandview_state_keyremoved, all 57 regenerated snapshot files equal the onesmain(e727be3) writes itself.sketch_plan_snapshots/: 12 files.corpus_snapshots/o11y_bench/: 10 files: q02, q05, q06, q18, q19, q21, q22, q23, q25, q26.Each view gains
plan_id(one per file) andview_state_key. Apart from those two inherited changes, no other byte differs: every other DAG, cost, coverage and accepted line is unchanged. In 21 views of the corpus snapshots and 22 of the sketch snapshots, the view shares its coverage with another view of its plan. All 54 keys are distinct within their plans.Follow-ups
aggregate_coveragedepends on where a filter sits, not on which rows are aggregated #1494: a coverage depends on where a filter sits. Test:memo_aggregate_coverage::known_limitation_1494_coverage_does_not_depend_on_where_the_filter_sits,#[ignore = "known limitation: #1494"]; it fails as expected.aggregate_coverage#1493 (a finalized exact aggregate had no coverage) is fixed onmainby fix(types): a finalized exact state covers what its aggregate covers #1535. This PR's ignored test for it duplicated fix(types): a finalized exact state covers what its aggregate covers #1535'sa_finalized_rate_covers_what_the_rate_covers, so it is removed, and that test now also checks the two view coverages are equal.windowby divisibility, and θ by the accuracy it guarantees rather than by equality.docs/design_docs/proposals/datafusion-query-engine-orchestration.mdstill proposes(PlanId, PhysicalASAPNodeId, window)as the view key. It is another track's proposal and is left unchanged here.Closes #1429