Skip to content

perf(query): seek bounded ranges in overlay walks instead of scanning the whole graph's novelty #1648

Open

Description

@bplatz

Follow-up to #1645 (review discussion: #1645 (comment)).

Problem

OverlayProvider::for_each_overlay_flake takes first/rhs bound flakes, and the novelty layer fully implements them — Segment::range (fluree-db-novelty/src/lib.rs:238) does a partition_point seek, and may_overlap (:279) does zone-map pruning to skip whole segments without touching their contents.

Nothing in the query or transact layers uses it. 24 leaf call sites pass a literal None, None, so every overlay consultation walks the entire graph's novelty no matter how narrow the pattern is.

The plumbing is already in place: the 17 wrapper delegations (schema_bundle, reasoning, api/overlay.rs, historical, the novelty-internal ones) forward first/rhs correctly. Only the leaf callers discard them.

Evidence

#1645 removed the clone-and-sort from open_overlay_only_fallback, which was the dominant cost on that path. What remains is the walk itself: a probe-heavy transaction issuing N bounded lookups still costs N × |novelty| comparisons. The cost scales with novelty size, so it bites hardest exactly when the indexer is lagging behind the write rate.

Scope, ranked by heat

site note
fluree-db-query/src/binary_scan.rs:1583 open_overlay_only_fallback, reached from six call sites; the bound (s,p) is already in hand
fluree-db-query/src/binary_range.rs:1124, :1468, :1526 batched ref/subject probes with a known subject set
fluree-db-transact/src/stage.rs:2983 query_novelty_for_graph, bound (s,p) per call
fluree-db-transact/src/stage.rs:2862 the novelty_present walk — once per graph per transaction, so lower priority

Remaining ~18 across fast_whole_graph_agg, geo_search, eval/metadata, eval/fulltext, frontier, binary_history, format/cypher_typed, query/helpers, ledger/historical, ledger/staged, rewrite_owl_ql, execute/reasoning_prep.

Why this needs one shared helper

The window is half-open and asymmetric: first is exclusive (range starts at partition_point(|f| index.compare(f, first) != Greater), skipping everything at or below it) while rhs is inclusive. leftmost: true means "ignore first, start at 0". So a caller who naively builds first = (s, p, MIN_o) silently drops a flake sitting exactly on that bound — and each of the four index orders sorts different fields.

Twenty-four hand-rolled bound constructions is a recipe for silent under-reads. This should be a single bounds constructor plus migration, not per-site bounds.

Acceptance criteria

  • A shared bounds constructor covering SPOT/PSOT/POST/OPST, with the (first, rhs] asymmetry encoded once and unit-tested at the boundary flakes specifically
  • Differential test: for each order, bounded-walk results are identical to unbounded-walk-then-filter, over multi-segment novelty and across a time-travel to_t
  • A before/after on a probe-heavy workload, stating its novelty depth — the payoff is large over deep novelty and roughly nil once the indexer has caught up, so an unqualified number will read as a bigger win than it is

Non-goals

No change to overlay semantics, retraction resolution, or the (first, rhs] contract itself. The wrapper delegations stay as they are.

Activity

  1. added
    enhancement
    on Aug 13, 2026
  2. aaj3f commented on Aug 25, 2026

    @aaj3f
    Contributor

    Sweep update at 47e96b7b6: partial progress since filing. #1657 (merged 8/18) converted the top-ranked site — open_overlay_only_fallback now does bounded seeks — and its overlay_walk_bounds helper already encodes the four-order (first, rhs] bound construction plus the leftmost interaction that this issue's "why one shared helper" section warns about. So the natural implementation path is now concrete: lift that helper out of BinaryScanOperator, generalize the pinned-component inputs, unit-test the boundary flakes, then migrate sites onto it.

    Remaining scope verified still unbounded: binary_range.rs:64/:1124/:1468/:1526, stage.rs:1659/:2918/:3039, and roughly the 18 others in the issue's table.

    Updating the body accordingly: striking scope-table row 1 (done in #1657), repointing the drifted stage.rs line numbers, and noting the helper-extraction starting point.

  3. added
    P2
    area:query
    on Aug 25, 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

    P2area:queryenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions