Repository navigation
Description
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 commitThe 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
bplatz commentedon Oct 20, 2026
The opposite direction drops a fact
The same per-fact counting loses a stored fact when an update deletes it on more
WHEREsolutions than it re-inserts it on. @aaj3f found this reviewing #2127.Expected:
ex:r1 ex:p "v"stays, and nothing is committed. Row 1 instantiates theINSERTtemplate, so the fact is inI, and under(DS − D) ∪ Iit is in the result. Rows 2 and 3 leave?keepunbound, so they insert nothing.Observed: the commit holds one retraction,
ex:r1 ex:p "v", and the fact is gone. The constantDELETEtemplate is staged on all three rows and theINSERTon 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 currentmain(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.