You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fast-stats over-count: novelty asserts not reconciled against the base index #1391
assemble_fast_stats applies a blind ±1 per novelty flake on top of the indexed base counts, with no reconciliation against whether the asserted fact already exists in the base index. An idempotent re-assert of a fact that has already been reindexed into the base therefore transiently inflates fast-stats counts until the next reindex collapses the duplicate.
Detail
fluree-db-novelty/src/runtime_stats.rs (assemble_fast_stats_inner): delta = if flake.op { 1 } else { -1 }, added to indexed.flakes and the per-graph / class / property counts, with no base-presence check.
Within-novelty dedup (NoveltyFactState) prevents re-asserting a fact already asserted in the novelty window, but it is novelty-window-scoped and cannot see the base index. Once a fact is reindexed into base (and dropped from novelty), a subsequent assert of the same (s, p, o, dt, m) is kept as a novelty flake and counted again.
Net effect: counts (total flakes, class instance counts, property counts) can over-report by the number of such idempotent re-asserts, until the next reindex merges novelty into base under set semantics and the count self-corrects.
Transient (self-corrects at the next reindex), and query results are unaffected — set semantics make the duplicate assert idempotent at read time. Only the stat counts drift.
Note on whether to fix
These stats are used primarily for query optimization / planning, not as an authoritative user-facing count. Reconciling every novelty assert against base presence (e.g. a base-index existence probe per asserted fact) could add non-trivial cost to the stats-assembly path. If making the counts 100% accurate carries a significant performance implication, it may not be worth doing — the planner tolerates approximate counts. Recording here for future consideration / measurement rather than as an urgent fix.
Scoping note so this issue stays truthful once #1699 lands: that PR is deliberately marked Partially addresses, not Fixes, and this issue should stay open with the remainder below.
What #1699 does close: the blind +1/-1 novelty delta on the user-facing count surfaces — fluree info (both the full and fast ledger_info arms), apoc.meta.data, and the db.* catalog shims — now resolve against base-index presence rather than charging a re-asserted already-indexed fact a second +1. It also closes the mirror case nobody had noticed, where a DELETE matching nothing charged -1 against a count that never included it.
What remains, and why the issue stays open:
Above the MAX_RECONCILED_NOVELTY_FLAKES cap (50k), the fixed surfaces still drift. The probe declines and both lanes fall back to the estimate. This one alone makes "counts no longer drift" untrue, which is why the PR doesn't claim to fix this issue.
The planner (stats_cache) and policy_builder lanes keep the blind merge by design — per-identity probes there would be quadratic in the window for the planner, and uncached per-query for policy. Right call, but it means those lanes still carry the drift.
stats.size still charges duplicate bytes — only counts were reconciled.
LedgerState::current_stats() is structurally unable to reconcile (no probe available at that layer).
class_property.rs retains the same blind ±1 shape, seeded from a prior. It's currently unreachable — compute_class_property_stats_parallel has no call sites — so it isn't a live bug, but anyone wiring that module up would inherit it.
An adversarial review of #1699 also disproved, by execution, the invariant its first draft rested on: novelty's set semantics are one-sided (lib.rs:887 gates on flake.op &&, so redundant asserts are suppressed but retractions are always accepted), and a same-t assert+retract resolves retract-wins while cmp_post sorts op ascending — so kept flakes do not alternate. The shipped resolver folds presence rather than assuming alternation, which handles arbitrary arrival order including two same-t pairs back to back.
Measurement, since this issue asked for it: ~4.3µs per flake — a 10k-flake window goes 1.5ms → 41.7ms, 48k goes 7.6ms → 210ms, and a 50,008-flake window declines at the cap with both lanes converging.
Correcting a claim in this issue, since it's now been disproved by execution.
The body says of the blind ±1 novelty lane that "query results are unaffected — set semantics make the duplicate assert idempotent at read time. Only the stat counts drift."
That holds for the assert direction it analyzes. It does not hold for the retract direction, because one consumer of the merged stats view isn't an estimate at all: StatsView::property_ref_only feeds filter_fold's node-only soundness guard, and merge_property_datatypes drops any datatype whose merged count reaches zero. A spurious -1 — from a delete that matches nothing, or a replayed delete — can drop a predicate's last literal datatype tag, flip the flag, and license an unsound query rewrite.
Demonstrated end to end: three triples under a mixed ref/literal predicate, a DELETE DATA of triples that aren't in the graph (a spec no-op), and a FILTER(?x = ?y) goes from 3 rows to 5 — the two extra rows asserting "abc"^^xsd:string = "abc"@en. The data is provably unchanged across the delete. It heals at the next index publish, because the indexer's on_record_with_base_presence already reconciles retractions against base presence, so the corruption window is bad-delete → next publish.
Tracked as #1721, with a second and unconditional defect in the same fold as #1723. Neither is a reason to reconcile the planner lane — that's still quadratic in the novelty window and still the right call to leave on Estimate; the repair belongs on the consumer side.
Flagging it here because this issue's severity note is the thing a reader would rely on to decide the blind lane is harmless, and in the retract direction it isn't.
Activity
fix(stats): fold novelty presence, not ops, when reconciling against …
aaj3f commentedon Aug 26, 2026
Scoping note so this issue stays truthful once #1699 lands: that PR is deliberately marked
Partially addresses, notFixes, and this issue should stay open with the remainder below.What #1699 does close: the blind
+1/-1novelty delta on the user-facing count surfaces —fluree info(both the full and fastledger_infoarms),apoc.meta.data, and thedb.*catalog shims — now resolve against base-index presence rather than charging a re-asserted already-indexed fact a second+1. It also closes the mirror case nobody had noticed, where a DELETE matching nothing charged-1against a count that never included it.What remains, and why the issue stays open:
MAX_RECONCILED_NOVELTY_FLAKEScap (50k), the fixed surfaces still drift. The probe declines and both lanes fall back to the estimate. This one alone makes "counts no longer drift" untrue, which is why the PR doesn't claim to fix this issue.stats_cache) andpolicy_builderlanes keep the blind merge by design — per-identity probes there would be quadratic in the window for the planner, and uncached per-query for policy. Right call, but it means those lanes still carry the drift.stats.sizestill charges duplicate bytes — only counts were reconciled.LedgerState::current_stats()is structurally unable to reconcile (no probe available at that layer).class_property.rsretains the same blind±1shape, seeded from a prior. It's currently unreachable —compute_class_property_stats_parallelhas no call sites — so it isn't a live bug, but anyone wiring that module up would inherit it.An adversarial review of #1699 also disproved, by execution, the invariant its first draft rested on: novelty's set semantics are one-sided (
lib.rs:887gates onflake.op &&, so redundant asserts are suppressed but retractions are always accepted), and a same-tassert+retract resolves retract-wins whilecmp_postsortsopascending — so kept flakes do not alternate. The shipped resolver folds presence rather than assuming alternation, which handles arbitrary arrival order including two same-tpairs back to back.Measurement, since this issue asked for it: ~4.3µs per flake — a 10k-flake window goes 1.5ms → 41.7ms, 48k goes 7.6ms → 210ms, and a 50,008-flake window declines at the cap with both lanes converging.
aaj3f commentedon Aug 27, 2026
Correcting a claim in this issue, since it's now been disproved by execution.
The body says of the blind
±1novelty lane that "query results are unaffected — set semantics make the duplicate assert idempotent at read time. Only the stat counts drift."That holds for the assert direction it analyzes. It does not hold for the retract direction, because one consumer of the merged stats view isn't an estimate at all:
StatsView::property_ref_onlyfeedsfilter_fold's node-only soundness guard, andmerge_property_datatypesdrops any datatype whose merged count reaches zero. A spurious-1— from a delete that matches nothing, or a replayed delete — can drop a predicate's last literal datatype tag, flip the flag, and license an unsound query rewrite.Demonstrated end to end: three triples under a mixed ref/literal predicate, a
DELETE DATAof triples that aren't in the graph (a spec no-op), and aFILTER(?x = ?y)goes from 3 rows to 5 — the two extra rows asserting"abc"^^xsd:string = "abc"@en. The data is provably unchanged across the delete. It heals at the next index publish, because the indexer'son_record_with_base_presencealready reconciles retractions against base presence, so the corruption window is bad-delete → next publish.Tracked as #1721, with a second and unconditional defect in the same fold as #1723. Neither is a reason to reconcile the planner lane — that's still quadratic in the novelty window and still the right call to leave on
Estimate; the repair belongs on the consumer side.Flagging it here because this issue's severity note is the thing a reader would rely on to decide the blind lane is harmless, and in the retract direction it isn't.