Skip to content

[Feature] Physical view id: identify a materialized view by what its stored states are, and drop the logical-only id #1429

Done

Description

@milindsrivastava1997

Problem

A deployment files and finds stored view states by ViewCoverage { definition_id, selection } (docs/design_docs/physical-planning-and-deployment.md §4, "The deployment matches a view to stored states by its coverage"; kll_tumbling_window_execution::a_store_keyed_by_definition_and_time_range_answers_the_tumbling_windows).

definition_id is logical (crates/types/src/plan/view_coverage.rs): the memo group's AggregateDefinition, expanded down to the Scans, JSON-serialized and FNV-1a-128 hashed. It includes the computation and summary_type, but not:

  • θ, the sketch parameters (PhysicalASAPDAGNode::parameters, e.g. KLL k);
  • the tumbling-window width: by design SummaryMerge(TimeRange(W, Chain[w](X))) has the same coverage as SummaryAgg(TimeRange(W, X)) (aggregate_coverage.rs, doc comment of aggregate_coverage).

So two views, in one plan or in two plans, can have the same definition_id and selection while their stored states are not interchangeable (KLL k=200 vs k=400; 1-minute vs 5-minute windows). A store keyed by (definition_id, selection) returns the wrong state.

Proposal

Add a physical view id on each materialized view's node, computed the same way (canonical serialization, hashed), that changes exactly when two stored states are not interchangeable:

  • in: the logical definition (computation, summary_type, update, reduction), θ, the tumbling-window width;
  • out: refresh mode (AtIngestion / OnFirstRead) and retention_ms, which change how a state is built or how long it is kept, not what it is;
  • out: the concrete data that went in (the selection's constraints and a window's exact start and end), which stays in selection and the request's time range.

Expose it on MaterializedView (e.g. MaterializedView::view_id()), and make it the key §4 tells deployments to use.

The logical definition_id

Outside tests and docs, definition_id's only consumer is the deployment's store key (materialized_view/views.rs requires view_coverage on every view for it). Once the physical id replaces it there, nothing uses it. Remove it from the plan (ViewCoverage, PhysicalASAPDAGNode::view_coverage's id), unless capability matching (#1430) needs a logical id to find a stored view that answers a query at a different θ; in that case keep it, documented as not a store key.

Acceptance

  • Two views differing only in θ, or only in tumbling-window width, get different physical ids; two views differing only in refresh mode or retention get the same one.
  • The physical id is the same across plans and processes for the same physical view (a durable store can key recovered states by it).
  • §4 and the integration test key the store by the physical id.

Context

Needed by ASAPQuery's engine boundaries design for executing ASAPPlanner plans: ProjectASAP/ASAPQuery#935 (decisions 43–44, tabled T2).

Activity

  1. zzylol commented on Nov 19, 2026

    @zzylol
    Contributor

    Good point, I didn't realize there is no definition id with parameters.

    But wait, we need to double-think here: view_coverage aims to provide the schema/semantics of the view, or computed intermediate states; the parameters like theta and window sizes should be additional fields to the view_coverage for the physical DAG. So, can we not change the logical coverage (because we have a full derivation algorithm for the coverage and schema of each node), but just add the parameters for the view store?
    Another reason I suggest this is, we are treating parameters as properties in planning, and so does this for a physical plan, and data plane store -- meaning that when later we need capability matching based ad-hoc query planning in ASAPPlanner, we should check whether existing view properties satisfy the query accuracy requirement.

    If you agree, would you mind changing the issue accordingly? Thanks

  2. milindsrivastava1997 commented on Nov 19, 2026

    @milindsrivastava1997
    CollaboratorAuthor

    Revised proposal (supersedes the issue body), following @zzylol's comment.

    Problem. A deployment files and finds stored view states by ViewCoverage { definition_id, selection } (physical-planning-and-deployment.md §4). definition_id is logical: it hashes the view's AggregateDefinition (computation, summary_type, update, reduction) down to the Scans. It leaves out the sketch parameters θ (PhysicalASAPDAGNode::parameters) and the tumbling-window width, which by design is not part of the coverage. So two views can have equal coverage while their stored states can't be used for each other (KLL k=200 vs k=400; 1-minute vs 5-minute windows). A store keyed by (definition_id, selection) would then return the wrong state.

    Proposal.

    • Keep the logical coverage (definition_id, selection) unchanged.
    • Add the view's physical properties to MaterializedView, next to its coverage: θ and the tumbling-window width. That is exactly the set of fields that makes two stored states unusable for each other. Refresh mode and retention_ms stay out, because they change how a state is built or kept, not what it is.
    • A deployment keys stored states by (definition_id, physical properties, selection). Update §4 and kll_tumbling_window_execution's keyed-store test to match.

    Why properties instead of one physical hash. The planner already treats θ as a property of a plan. Capability matching (#1430) can then check whether a stored view's properties meet a query's accuracy requirement, which needs the logical id and the properties kept separate.

    Acceptance.

    • Two views that differ only in θ, or only in window width, have equal definition_ids and different properties.
    • Two views that differ only in refresh mode or retention have equal ids and equal properties.
    • The properties compare equal across plans and processes for the same physical view.
  3. zzylol commented on Nov 20, 2026

    @zzylol
    Contributor

    Something is missing here. Due to that a MaterializedView is a sub-DAG, not just one node, the physical properties are per node (or memo group), the actual design should be a) the invariant is to keep the original node schema/coverage and selection, b) in the selected physical plan (which has a specific plan Id), each node has the property fields for theta, etc. And in the data plane interfaces, the MaterializedView interface shows the (plan id, node in selected physical plan).

    basically, the difference I'm proposing here is to add physical properties to the physical DAG (after it's being converted from physical memo group).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions