Skip to content

WHERE/DELETE/INSERT over several rows commits a redundant assertion of an unchanged fact #2129

Closed

Description

@bplatz

Summary

A WHERE/DELETE/INSERT update whose WHERE matches several rows, and which deletes and re-inserts a fact that does not change, commits a redundant assertion of that fact. The data is right, but:

  • the commit counts the fact as asserted, and its change list shows it;
  • an update that changes nothing at all still writes a commit;
  • after an index build, history shows the unchanged fact as retracted and asserted again at that t. Before the index build, history over novelty shows nothing, so the two disagree.

The same replacement staged as two writes in one transaction (a DELETE, then an INSERT DATA) nets to the difference, as expected.

Reproduced on current main (f3c3b00ec, 4.2.4), in SPARQL UPDATE and JSON-LD.

Reproduction

PREFIX ex: <http://example.org/>
INSERT DATA { ex:a ex:v 1 . ex:b ex:v 2 }
PREFIX ex: <http://example.org/>
DELETE { ?s ex:v ?o }
INSERT { ex:a ex:v 1 . ex:b ex:v 3 }
WHERE  { ?s ex:v ?o }

Expected: one retraction (ex:b ex:v 2) and one assertion (ex:b ex:v 3).

Observed: 2 assertions, 1 retraction. The commit's change list:

assert  ex:a ex:v 1    <- unchanged fact
retract ex:b ex:v 2
assert  ex:b ex:v 3

After an index build, history for ex:a ex:v reports (1, assert, 1), (2, retract, 1), (2, assert, 1); over novelty it reports only (1, assert, 1).

Restating every fact changes nothing yet still commits:

# data: ex:a ex:v 1 . ex:b ex:v 2 . ex:c ex:v 3
DELETE { ?s ex:v ?o } INSERT { ex:a ex:v 1 . ex:b ex:v 2 . ex:c ex:v 3 } WHERE { ?s ex:v ?o }
# commit written: 3 assertions, 0 retractions; expected: no commit

The JSON-LD form behaves the same:

{
  "@context": {"ex": "http://example.org/"},
  "where":  {"@id": "?s", "ex:v": "?o"},
  "delete": {"@id": "?s", "ex:v": "?o"},
  "insert": [{"@id": "ex:a", "ex:v": 1}, {"@id": "ex:b", "ex:v": 4}]
}

With a WHERE that matches one row (DELETE { ex:a ex:v ?o } INSERT { ex:a ex:v 1 } WHERE { ex:a ex:v ?o }), nothing is committed, as expected.

Cause

INSERT templates are instantiated once per WHERE row (SPARQL 1.1 Update §3.1.3), so with two rows the constant template ex:a ex:v 1 is staged twice, while ex:a ex:v 1 is retracted once. The mixed accumulator in fluree-db-transact/src/generate/accumulator.rs cancels one for one per fact (cancel = min(assert_count, retract_count)), so one assertion survives. Under SPARQL's (DS − D) ∪ I, I is a set: an assertion repeated across rows should cancel against one retraction of a stored fact, which is the set-semantics cancellation the accumulator already has for another mode.

Expected

An update's commit contains only the facts whose stored state it changes. An update that changes nothing commits nothing. History is the same over novelty and over the index.

Activity

  1. added
    bug
    P2
    area:transact
    on Oct 15, 2026
  2. bplatz commented on Oct 20, 2026

    @bplatz
    ContributorAuthor

    The opposite direction drops a fact

    The same per-fact counting loses a stored fact when an update deletes it on more WHERE solutions than it re-inserts it on. @aaj3f found this reviewing #2127.

    PREFIX ex: <http://example.org/>
    INSERT DATA { ex:r1 ex:p "v" }
    PREFIX ex: <http://example.org/>
    DELETE { ex:r1 ex:p "v" }
    INSERT { ?keep ex:p "v" }
    WHERE  { VALUES (?x ?keep) { (1 ex:r1) (2 UNDEF) (3 UNDEF) } }

    Expected: ex:r1 ex:p "v" stays, and nothing is committed. Row 1 instantiates the INSERT template, so the fact is in I, and under (DS − D) ∪ I it is in the result. Rows 2 and 3 leave ?keep unbound, so they insert nothing.

    Observed: the commit holds one retraction, ex:r1 ex:p "v", and the fact is gone. The constant DELETE template is staged on all three rows and the INSERT on one, so retractions outnumber assertions and the accumulator keeps a retraction.

    The same happens with both templates inside GRAPH <http://example.org/g> { … }. With a single solution, VALUES (?x ?keep) { (1 ex:r1) }, the fact stays. Reproduced on current main (2a1d5dd).

    Unlike the redundant assertion above, this changes the data, not only the commit. The set-semantics cancellation this issue proposes fixes both directions. A fact in the update's insert set is present afterward, whatever the counts. A fact in only its delete set is absent. The update commits only the facts whose stored state changes.

  3. added
    P1
    and removed
    P2
    on Oct 20, 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

    P1area:transactbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions