Skip to content

Cypher: DELETE of one relationship among several on the same edge #2234

Open

Description

@aaj3f

A relationship is a reifier on a base edge (s, T, o), and two relationships with the same endpoints and type
share that edge. DELETE r retracts the edge, and the f:reifies* cascade then takes every relationship on it,
so staging refuses a DELETE r whose edge carries more than one relationship
(fluree-db-transact/src/stage.rs, cascade_attachment_retracts, scoped by TxnOpts::relationship_deletes
since #2184):

MATCH (a {id: "a"}), (b {id: "b"}) CREATE (a)-[:K {w: 1}]->(b)
MATCH (a {id: "a"}), (b {id: "b"}) CREATE (a)-[:K {w: 2}]->(b)
MATCH (a)-[r:K {w: 1}]->(b) DELETE r
-- refused: "DELETE of relationship `r` failed: parallel relationships share its underlying edge …"

openCypher deletes the one relationship and leaves the other.

Decision needed: what a per-occurrence delete retracts. The plan below assumes "retract the relationship's
reifier (bundle and properties), and the base edge only when no other reifier names it".

Plan:

  1. Lowering (lower_cypher_update.rs, lower_delete): for DELETE r, emit the retraction of r's annotation
    subject (its bundle and properties, as the LPG cleanup already reads them) instead of the base-edge template,
    and mark the edge as conditionally retracted.
  2. Staging: after the WHERE, for each marked edge, count the reifiers edge_reifiers finds that the
    transaction does not retract; retract the base edge only when that count is zero. edge_reifiers is already
    the one lookup the cascade and the parallel check share, so this adds no second read path.
  3. The parallel refusal then goes away for DELETE r; DETACH DELETE of a node keeps retracting every edge.
  4. Tests: twin Cypher/SPARQL tests for deleting one of two, both of two (one statement and two), and one of
    two beside a SET on the other; the existing refusal tests in it_cypher_seq_writes.rs flip to commits.
  5. Perf: rel_delete_one, rel_delete_all and rel_set_delete_all in the instruction-count harness should not
    move; the extra per-edge reifier count is the lookup the cascade already does.

Raised in review of #2184.

Activity

  1. added
    enhancement
    P3
    triage:needs-decision
    area:transact
    on Nov 2, 2026
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

    P3area:transactenhancementtriage:needs-decision

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions