Skip to main content

Module datalog

Module datalog 

Source
Expand description

Datalog-style fixed-point computation of dirty objects, clusters, and schemas.

Implements the propagation rules documented in the parent module’s header. The evaluator is organized as:

  1. immutable input facts (BaseFacts)
  2. precomputed join indexes and helper relations (FactIndexes)
  3. mutable derived relations (DirtyState)
  4. rule-group evaluators that collect pending derivations before merging

Each derive_* helper corresponds to one or more Datalog rules and is annotated with the exact rule it encodes.

§Algorithm

  1. Seed: Initialize dirty_stmts from changed_stmts (objects whose hashes differ between the old and new snapshots) and dirty_schemas from forced_dirty_schemas (schemas the caller redeploys unconditionally).
  2. Build indexes: Pre-compute reverse lookup maps and the current ClusterBoundary relation from base facts for O(1) rule evaluation.
  3. Fixed-point loop: In each iteration, apply all five rule groups in a fixed order:
    1. Cluster dirtiness (from changed statements only, within ClusterBoundary)
    2. Statement dirtiness from dirty clusters
    3. Dependency propagation (downstream of dirty statements, excluding replacement MVs, whose dirtiness does not fan out to dependents)
    4. Schema dirtiness (from dirty statements, excluding sinks)
    5. Statement dirtiness from dirty schemas
  4. Termination: The loop converges when no set (dirty_stmts, dirty_clusters, dirty_schemas) grows in an iteration. Convergence is guaranteed because all sets are monotonically non-decreasing and bounded by the finite project universe.

§Rule Application Order

The ordering within a single iteration matters for convergence speed but not correctness — the fixed-point semantics guarantee the same result regardless of order. The chosen order (clusters → stmts-from-clusters → dependencies → schemas → stmts-from-schemas) maximizes information propagated per iteration, typically converging in 2–3 rounds.

ClusterBoundary is materialized as all clusters referenced by statements or indexes in the project.

Structs§

DirtyState 🔒
Mutable working sets carried across fixed-point iterations.
Evaluator 🔒
Fixed-point evaluator for the dirty propagation rules.
FactIndexes 🔒
Pre-computed indexes for efficient Datalog rule evaluation.
PendingFacts 🔒
Newly derived facts from one rule group before they are merged into DirtyState.

Functions§

compute_dirty_datalog 🔒
Compute dirty objects, clusters, and schemas using fixed-point iteration.