Skip to content

A no-op delete can narrow a scan to the wrong datatype and return non-matching rows (graph-scoped sibling of #1721) #1738

Closed

Description

@aaj3f

A delete that removes nothing — a no-op DELETE DATA, or a replayed delete — can make a scan return rows that don't match the query. This is the graph-scoped sibling of #1721, on a lane #1728 deliberately doesn't touch.

Reproduced, with a control

ex:p carrying "25"^^xsd:int and "25"^^xsd:long, published index, novelty non-empty on both measurements, query SELECT ?s WHERE { ?s ex:p 25 }:

action result
no-op delete of "999"^^xsd:int — a datatype the predicate does carry [] → [ex:b]
control: no-op delete of "999"^^xsd:short — a datatype it does not carry [] → []

The control is what makes this conclusive: only a retraction naming a tag already present in the base perturbs the answer, which is exactly the mechanism below.

Mechanism

update_graph_property_datatypes → increment_count (fluree-db-novelty/src/runtime_stats.rs:507) applies a blind ±1 with retain(|e| e.1 > 0) onto the base index's graph-scoped datatypes. A spurious -1 zeroes a base tag and drops it from the set. That leaves a singleton, and infer_exact_datatype_sid_from_stats (fluree-db-query/src/binary_scan.rs:3366) narrows the scan to that exact datatype on the strength of it — its comment asserting the premise #1721 disproved, that the set "reflects base + novelty, so 'only one string-compatible tag' is a conclusive statement about the whole logical DB."

So a row that doesn't satisfy the query is returned, rather than an optimization merely being declined.

Relationship to #1721 and #1728

#1728 fixes the aggregate PropertyStatEntry by adding observed_datatypes — base tags ∪ novelty-asserted tags, monotone under retraction. This is the same defect on the graph-scoped GraphPropertyStatEntry, which that PR doesn't touch. So #1721's class isn't fully closed by #1728, and this issue is the remainder.

Why it wasn't folded into #1728

The correct fix mirrors observed_datatypes onto GraphPropertyStatEntry: six construction sites across five crates (core and binary-index decoders, id_hook.rs ×2, the novelty merge, ledger_info.rs), plus per-(graph, predicate) asserted-tag tracking in the merge, plus a StatsView field and its own regression test — roughly the same size again as the #1721 half of that PR, on a lane it otherwise leaves alone.

There is a cheaper alternative, and it needs a decision rather than a drive-by: veto the narrowing from the now-monotone aggregate set. That's sound, but it silently declines narrowing for any predicate whose datatype set differs across graphs, and it depends on IndexStats.properties being present (it's an Option). That's a performance trade-off someone should choose deliberately.

Notes

Found while remediating #1728's review; the reviewer flagged the site and the fix work confirmed it end to end.

Activity

  1. added
    bug
    P1
    area:query
    on Aug 28, 2026
  2. aaj3f commented on Aug 28, 2026

    @aaj3f
    ContributorAuthor

    Update: this is now folded into #1728 after all — Fixes #1738 is wired there, so it closes on that merge.

    What changed the calculus: #1728's review pushed on the global time-travel clearing, and the answer was to persist the observed-tag sets on the stats wire (an appended tail behind the existing length prefix — invisible to old readers, no format bump). Once the wire tail and its producers had to visit all six of this issue's construction sites anyway, the marginal cost of mirroring the sets onto GraphPropertyStatEntry collapsed, and the "same size again" estimate above stopped being true.

    The fix is the set-based veto this issue's "cheaper alternative" section discusses, but per-graph rather than aggregate — so it doesn't decline narrowing for predicates whose datatype sets differ across graphs, which was the trade-off that made the aggregate veto a decision rather than a drive-by. infer_exact_datatype_sid_from_stats now narrows off a per-(g, p) tag set that a spurious -1 cannot shrink, and the control case above (no-op delete of a tag the predicate doesn't carry) is pinned alongside the mechanism case. It also closes the time-travel variant of the narrowing, which nothing previously covered.

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:querybug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions