Skip to content

docs(specs): diagram-traversal algebra derivation (expand/restrict) in diagram.md - #249

Open
dimitri-yatsenko wants to merge 6 commits into
mainfrom
docs/diagram-traversal-derivation
Open

docs(specs): diagram-traversal algebra derivation (expand/restrict) in diagram.md#249
dimitri-yatsenko wants to merge 6 commits into
mainfrom
docs/diagram-traversal-derivation

Conversation

@dimitri-yatsenko

Copy link
Copy Markdown
Member

Consolidates the full diagram-traversal derivation into the datajoint-docs specs, where the normative specs live — relocating it from datajoint-python's DESIGN-expand-restrict.md (PR #1524, now closed).

What

Adds a "Traversal algebra" design rationale to reference/specs/diagram.md deriving the traversal operations from first principles:

  • one primitive — propagating a restriction across a foreign key is itself a restriction (&), either direction;
  • R1 (edge rule) — restrict the neighbor by the projected/renamed restricted table; identity fast-path when the FK is the whole PK, unrenamed;
  • R2 (group rule) — a restriction touching any part lifts to the master and re-expands to all its parts;
  • two operations — additive expand(direction) (of which cascade = down, trace = up) and subtractive restrict;
  • renamed FKs — the three seed-restriction kinds (materialized / subquery / string) and the relabel fast-path;
  • master↔part — R2 via relabel-drop + re-expansion, and why a key reaching a part via its master carries no part-specific constraint.

cascade.md and trace.md now point to this rationale as the downstream/upstream cases, keeping only their operation-specific content.

Notes

  • Single source of truth: the derivation is in diagram.md; the other specs reference it rather than re-deriving.
  • Terminology/notation follow the house style (restriction/anti-restriction, DataJoint operators, "diagram" not ERD).
  • Supersedes the old-framing draft docs: diagram operations — fold cascade/trace/restrict derivation into the specs (WIP) #234 (which predates the expand/restrict model).
  • Further de-duplication of cascade.md/trace.md's older per-rule enumerations (F1–3/U1–3) and the DiGraphMultiDiGraph wording is a follow-up reshape.

Consolidate the expand/restrict traversal algebra (derived from first
principles: the one primitive, edge rule R1, group rule R2, the additive expand
and subtractive restrict, renamed-FK relabel fast-path, and the master-part group
rule) into diagram.md as a 'Traversal algebra' design rationale — the single
source of truth. cascade.md and trace.md now point to it as the downstream and
upstream cases (expand down/up), keeping only their operation-specific content.

Relocated from datajoint-python's DESIGN-expand-restrict.md (PR #1524), which is
closed; the derivation and spec live with the other specs in datajoint-docs.
Drop restrict and the additive/subtractive split from the diagram.md derivation.
The model is now one operation, expand(seed, direction in {up,down,both}): cascade
= down, trace = up, export = both, over the two rules R1 (edge) and R2 (group).
A filter over several independent tables is not a second operation — it either
seeds a common descendant (which inherits both keys) and expands both ways, or,
lacking one, is a union of expansions; the per-table 'AND of upstream conditions'
carving is a UI-layer composition of expands, not a core primitive.
@dimitri-yatsenko

Copy link
Copy Markdown
Member Author

Revised the derivation to expand-only: dropped restrict and the additive/subtractive framing. The model is now one operation — expand(seed, direction in {up,down,both}) (cascade = down, trace = up, export = both) — over R1 (edge) + R2 (group). Multi-condition filtering reduces to seeding a common descendant or a union of expands, so it's a UI-layer composition, not a core primitive. (Note: the Operational Methods section still documents the shipped Diagram.restrict(); it's subsumed by expand in the model and would be removed when the redesign lands.)

cascade.md: DiGraph -> MultiDiGraph; the part-to-master walk enumerates all
simple FK paths (not shortest_path) and defers the edge rule to diagram.md's R1.
trace.md: recast the convergence table as the two directions of expand (cascade
= down, trace = up), drop the restrict/AND row, and defer the rules to diagram.md
(R1 + R2). Fixes statements that were stale after the MultiDiGraph migration and
the expand-only model.
De-duplicate cascade.md's F1-3/U1-3 per-rule enumerations against the unified
edge rule R1 in diagram.md#traversal-algebra, keeping the cascade-specific
behavior on top. Rewrite worked examples to name R1's copy/rename/project cases
instead of the old rule codes; drop the subset-symbol notation.

Reframe part_integrity per the group rule R2: with cascade the master-part group
is one item — master-first pulls in all parts, part-first lifts to the master
then re-expands to all parts; ignore treats master and part as regular tables.

Update trace.md's allowed-table-set contract so an ancestor master's whole
part-group is in scope (R2 upstream), replacing the old non-descending note.
Sweep residual unicode arrows to ASCII.
Downward expansion for delete cannot leave a restriction referencing a
downstream table: reverse-topological delete empties it first, so the subquery
matches zero rows and strands what should be deleted (#1496). State this as a
general Delete-time materialization section — seed-referencing-descendant and
the part-to-master master-key freeze are its instances — applied on every
backend by delete-order reason, not as a MySQL-only (error 1093) concern.
Preview/counts pays none of it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant