Skip to content

fix(query): a subject probe over a graph with no branch finds nothing - #2187

Merged
aaj3f merged 7 commits into
mainfrom
fix/probe-branchless-graph
Nov 2, 2026
Merged

aaj3f merged 7 commits into
mainfrom
fix/probe-branchless-graph

Conversation

@aaj3f

@aaj3f aaj3f commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A join inside a graph the index has no branch for could fail with Internal error: PSOT index not found for graph. That's a named graph first written after the last index, or the default graph of a ledger whose indexed facts are all in named graphs. The nested-loop join's batched subject probe looked up the graph's PSOT branch and treated a missing one as an error. A graph the index has no branch for holds nothing for the probe, so the probe now finds nothing there, as the object probe already did.

A geo search over such a graph failed the same way (GeoSearch: no POST branch for g_id=…). That graph's points are all in novelty, so the search now reads them there. Separately, and with or without a branch, a geo search over a predicate that only novelty holds found nothing. That one predates this PR, and it's fixed here too.

What changes

  • When it failed. The join's left side read its rows from the graph's novelty, and the probed predicate was one the index knows from another graph but this graph's novelty doesn't hold. The probe's plan rightly admits that case (with novelty for the predicate in a branchless graph it declines), and then the probe asked for a branch the graph doesn't have.
    • Example: GRAPH <g3> { ?x ex:sel ?y . ?y ex:v ?o } after writing ex:b ex:sel ex:y0 into a new graph <g3>, when ex:v is indexed only in <g1>. The same join over the default graph failed the same way once ex:a ex:sel ex:y0 was written there.
  • Now. The probe finds no branch, clears the batch and returns no rows for it.
  • The batched probes (the join's subject, object, PSOT and SPOT probes, and OPTIONAL's object probe) now share one branch lookup, branch_or_none. It answers a missing branch with nothing, unless the probe was asked to merge novelty, which its plan never does for a branchless graph; that case is an internal error in every build rather than a debug-only assertion.
  • The same goes for the probed predicate. A probe answered a predicate the index doesn't hold with nothing, which is complete only while none of that predicate's novelty is being merged. The PSOT probe checked that with a debug assertion and the SPOT star probe with one that fired only when every predicate was missing; the join's subject and object flushes and OPTIONAL's object probe didn't check at all. They now share p_id_or_none, next to branch_or_none: nothing when no op of the predicate is merged, an internal error in every build when one is. The star probe asks per predicate, so a predicate with no novelty still reads nothing while the others merge.
  • Geo search. GeoSearchOperator resolves the graph's POST branch once at open. A graph with no branch gets an empty manifest, so the cursor has no leaves and reads the overlay ops open already translated, the way export reads a graph with no SPOT branch. Before, the search looked the branch up for every center row and failed when there wasn't one.
  • Geo search over a novelty-only predicate. open took the predicate's id from the dict overlay's own predicate numbering, which the overlay translation doesn't share, so the cursor filtered on an id none of the ops carried and returned no rows. It now takes the id the translation gave that predicate's ops.
  • The remaining branch lookups don't read a missing branch as "nothing" while novelty could hold rows. They decline when there's novelty, decline on a missing branch, or read the overlay alone.

Tests

it_named_graphs::a_join_in_a_graph_written_after_the_index_probes_it_and_finds_nothing:

  • It indexes facts in <urn:g1>, then writes ex:sel into the default graph and into a new graph <urn:g3>.
  • The join answers no rows over the default graph, FROM <urn:g3>, GRAPH <urn:g3>, and the JSON-LD ["graph", "urn:g3", …] twin. The same join in <urn:g1> answers its one row.
  • The rows alone can't tell the batched probe from the per-row path, so the default-graph and GRAPH spellings also check the join's routing event and must take the batched subject probe. FROM <urn:g3> reads g3 as a dataset, where the probe lane declines, so only its rows are checked.
  • With the old error put back, the default-graph, GRAPH and JSON-LD spellings fail with PSOT index not found for graph.

fast_path_common::tests::branch_or_none_refuses_a_merge_over_a_graph_with_no_branch covers the lookup itself: nothing to read without a merge, and an internal error with one, for PSOT, OPST and SPOT. p_id_or_none_refuses_a_merge_of_a_predicate_the_index_doesnt_hold does the same for the predicate lookup. it_join_batched_overlay::probe_helpers_merge_novelty gains a star with a predicate the ledger never had, next to two that merge novelty: it takes the SPOT star walk and matches nothing, as the reindexed ledger does, rather than refusing.

it_query_geo_search::geo_search_reads_novelty_in_a_graph_the_index_has_no_branch_for indexes geo points in <…/germany>, then writes points into the default graph, a new <…/italy>, a new <…/spain> under ex:position (a predicate the index doesn't hold, next to another novelty-only predicate), and an ex:position point into germany. The search answers the novelty's points over the default graph, GRAPH <italy> and its JSON-LD twin, GRAPH <spain>, and germany's ex:position; germany's indexed points are the control. With the old branch error put back, the four branchless spellings fail with no POST branch; with the old predicate lookup, the two ex:position cases return no rows.

The branchless-graph join test no longer runs its queries once and rebuilds tracing interest before capturing: init_test_tracing installs through scoped_default, which covers that.

Geo search cost, base vs this head, 20,000 points, three alternated rounds: indexed about 24.2M instructions on both, overlay about 33.2M on both (within 0.2%). The branch lookup now happens once at open instead of per center row.

aaj3f added 3 commits October 26, 2026 12:29
A join inside a named graph first written after the last index could
fail with "Internal error: PSOT index not found for graph". The
nested-loop join's batched subject probe asked for the graph's PSOT
branch and treated a missing one as an error. The probe's plan admits
that case, rightly: its left rows come from the graph's novelty, and the
probed predicate, which the index knows from another graph, has no
novelty there, so the graph holds nothing for the probe. It now finds
nothing, as the object probe already did.
The nested-loop join's subject, object, PSOT and SPOT probes and the
optional's object probe each looked up their graph's index branch and
answered a missing one with nothing, guarded only by a debug assertion
that their lane plan had not asked them to merge novelty. In a release
build, a merge over a graph with no branch would have dropped the
novelty's matches without a word. They now share `branch_or_none`,
which answers a missing branch with nothing when there is no merge and
refuses when there is one, in every build.

The regression test now reads the graph with no branch as the default
graph, through `FROM` and through `GRAPH` in SPARQL and JSON-LD, and
pins the `GRAPH` spellings to the batched subject probe.
The join reads `ex:sel` first only when `ex:v` has more indexed rows, so
the fixture gives it eight; the default-graph spelling then reaches the
batched subject probe as the `GRAPH` ones do, and is pinned there. The
route is read before formatting, which runs queries of its own, and a
query whose plan holds a second join still has to show the probe.
@aaj3f aaj3f added bug Something isn't working as expected area:query Query execution, planning, fast paths, overlay, result formatting labels Oct 26, 2026
@aaj3f
aaj3f requested a review from bplatz October 26, 2026 20:59
The batched probes answered a predicate the index doesn't hold with
nothing. That is complete only while none of the predicate's novelty is
being merged: the lane plans decline a novelty-only predicate with ops,
and a probe that reached one would have dropped those matches. The PSOT
probe guarded it with a debug assertion, the SPOT star probe with one
that fired only when every predicate was missing, and the join's subject
and object flushes and the optional's object probe not at all.

They now share `p_id_or_none`, next to `branch_or_none`: a predicate the
index doesn't hold reads nothing when no op of it is merged, and is
refused when one is, in every build. The star probe asks per predicate
whether the overlay holds ops of it, so a predicate with none still skips
while the others merge.

@bplatz bplatz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. Returning nothing for a graph with no branch is right here: the probe only reaches that case in Clean mode, where the graph's novelty holds nothing for the predicate. The release-mode refusals can't fire today, since the lane plans return Merge only when the predicate has a p_id and the graph has the branch the probe reads, and the plan and the flush see the same binary_g_id. An internal error is the right fallback over dropping novelty rows.

Recommended follow-up: GeoSearchOperator::execute_search (geo_search.rs, the POST branch lookup) fails the same way: GeoSearch: no POST branch for g_id=… when the geo predicate is known but the graph has no branch. There, nothing isn't the right answer: a graph first written after the last index can hold geo points in novelty, which open already translates into overlay_ops, so the search should read the overlay alone. That's outside the probes this PR covers, so I'd file it as its own issue and link it here with Follow-up: #N. (The two no POST branch for graph errors in fast_group_count_firsts.rs are fine: both callers swallow the error and fall back.)

Comment thread fluree-db-api/tests/it_named_graphs.rs Outdated
Comment on lines +5676 to +5682
// The join's routing event is shared with sibling tests, which can pin its
// interest to "never" while the subscriber installs: run each query once,
// then recompute every registered callsite's interest.
for (_, query, _, _) in &cases {
let _ = fluree.query(&db, *query).await;
}
tracing::callsite::rebuild_interest_cache();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: #2149, merged since this branch's base, routes init_test_tracing through fluree_test_support::scoped_default, which registers the floor dispatchers and rebuilds interest itself. The warm-up pass and this rebuild look redundant once main is merged in, so this block and its comment can go.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, dropped in 4aa1dab08. With main merged, init_test_tracing goes through fluree_test_support::scoped_default, which keeps the floor dispatchers alive so a callsite first registered on another thread can't get cached as never, and it rebuilds interest itself. So the warm-up pass and the extra rebuild_interest_cache() weren't buying anything. The test still pins the batched subject probe on the default-graph, GRAPH and JSON-LD spellings, and it stayed green across repeated runs alongside the rest of grp_graphsource: 10 of 10 in-process cargo test runs of the whole binary (326 tests, the siblings sharing the join's routing callsite as threads in one process), plus 5 whole-binary and 20 single-test nextest runs.

aaj3f added 3 commits October 30, 2026 13:40
A geo search over a graph the index has no POST branch for failed with
`GeoSearch: no POST branch for g_id=...`. That's a named graph first
written after the last index, or the default graph of a ledger whose
indexed facts are all in named graphs. Such a graph has nothing indexed,
and its points are all in the overlay ops `open` already translates, so
the search now reads them through an empty manifest, the way export
reads a graph with no SPOT branch. The branch is resolved once at open
rather than looked up for every center row.

A geo predicate only novelty holds found nothing, with or without a
branch: `open` took its id from the dict overlay's own predicate
numbering, which the overlay translation doesn't share, so the cursor
filtered on an id no op carried. It now takes the id the translation
gave the predicate's ops.
init_test_tracing now installs through fluree_test_support::scoped_default,
which keeps every callsite's interest from being cached as never and
rebuilds the cache itself, so the branchless-graph join test no longer
needs to run its queries once and rebuild interest before capturing.
@aaj3f

aaj3f commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the careful read, and especially for the geo catch. Rather than file it as its own issue, I folded it into this PR (18585f5aa). It's really the same shape as the probes (a graph with no branch is a graph whose facts are all in novelty), and since it's a small fix I'd rather close it here than leave it sitting in the backlog.

GeoSearchOperator::open now resolves the POST branch once, and a graph with no branch gets an empty BranchManifest, so the cursor has no leaves and drains overlay_ops alone. That's the same thing spot_branch in export.rs already does for SPOT. It also takes the branch lookup off every center row, fwiw.

Writing the test turned up a second issue in the same operator, and I don't think it's tied to the branch at all: a geo predicate that only novelty holds found nothing, branch or no branch. open took the predicate's id from DictOverlay::assign_predicate_id, whose numbering the overlay translation in open doesn't share, so the cursor filtered on an id none of the ops carried and came back with no rows (no error, just empty). It now takes the id the translation actually gave that predicate's ops (store.sid_to_p_id(..).or(novelty_p_id)). That one is pre-existing on main, not something the probe change introduced. It just only shows up once a test writes a new geo predicate after the index.

it_query_geo_search::geo_search_reads_novelty_in_a_graph_the_index_has_no_branch_for covers the default graph, GRAPH <italy> and its JSON-LD ["graph", …] twin, GRAPH <spain> with a novelty-only predicate in a branchless graph, and a novelty-only predicate in germany, which does have a branch. Germany's indexed points are the control. Putting the old no POST branch error back fails the four branchless spellings with exactly that error; putting the old predicate lookup back returns [] for the two novelty-only-predicate cases.

I also went through the rest of the branch_for_order sites for the same pattern, and I think geo was the last read that errors or answers empty on a missing branch while the overlay can still hold rows:

  • The paths that answer empty or 0 with no branch (fast_count, stats_query, fast_label_regex_type, fast_star_const_order_topk, fast_string_prefix_count_all) all sit behind fast_path_store or decline on overlay_has_novelty, so no branch really does mean nothing there.
  • Every caller of build_psot_cursor_for_predicate/build_post_cursor_for_predicate and both PsotSubjectSeek::new_with_identity sites in cyclic_bgp treat None as "decline", not "no rows".
  • binary_scan, binary_range (all three) and binary_history fall back to overlay-only reads, and the binary-index batched lookups return the empty base that their callers then merge novelty into.
  • And you're right that both no POST branch for graph errors in fast_group_count_firsts.rs are swallowed into the fallback (Err(_) => at the two operator sites and let Ok(..) else in fast_whole_graph_agg), and they're behind fast_path_store too.

If any of that reads wrong to you, happy to talk it through.

@aaj3f
aaj3f merged commit 231c5d5 into main Nov 2, 2026
19 checks passed
@aaj3f
aaj3f deleted the fix/probe-branchless-graph branch November 2, 2026 20:44
aaj3f added a commit that referenced this pull request Nov 3, 2026
…out-mapping

Brings in #2193, #2200, #2183, #2187 and #2198. The one conflict is
it_iceberg_local_fs.rs, where this branch's unmapped-source tests and
#2198's BigQuery and merge-on-read tests were appended at the same
place; both are kept.
bplatz added a commit that referenced this pull request Nov 4, 2026
Brings #2247, #2232, #2246, #2248, #2245, #2230, #2205, #2231, #2255,
#2219, #2209, #2207, #2190, #2216, #2186, #2215, #2213, #2184, #2210,
#2206, #2198, #2187, #2183, #2200, #2193, #2199, #2196 and #2145 into next.

Resolutions:
- Novelty: main's fact-state trim (a cutoff plus a bounded sweep) and the
  dictionary's coverage watermark sit on next's graph slots and per-graph
  OrdMaps. A commit's reification links count toward coverage. Planner
  stats from segment sums decline under annotations, whose link deltas
  only the walk counts, and otherwise carry the indexed link counts.
- Stats-view identity: the index root's id reaches the snapshot through
  next's root decoder (`decode` takes the id, as `take_snapshot_metadata`
  does). `LedgerState::load_record` has a decoding-root form beside
  `load_decoding_root`.
- Transact: #2184's parallel-relationship check runs in next's link
  cascade, counting the `rdf:reifies` links on the retracted edge that the
  transaction does not retract itself. Main's bundle `edge_reifiers` is
  dropped, and `subjects_with_prior_rows` and
  `enforce_single_target_reifiers` stay deleted. The upsert pre-check
  takes main's dictionary probe and bounded seek.
- Query: geo search resolves the graph's POST tree once at open (pooled
  graphs keep their filter), an empty manifest when there is none.
  `branch_or_none` reads the dedicated branch, and the batched joins keep
  next's pooled lanes. The stats-view key hashes the root id.
- Indexer: `apply_dict_novelty` and `compact_forward_streams` take the
  cycle's compaction budget, so the term dictionary keeps its reserved
  share. `Prefetched` holds `ContentBytes`. `relocalize_sorted_commit`
  rewrites next's 20-byte types records.
- Disk cache: main's in-flight write registration, with an empty entry
  still read as crash debris that a write replaces. The process-wide
  eviction walk stays removed.
- Graph import (#2232): fenced CAS and publishes, the seed carries the
  record's namespace and fence, 32-bit graph ids and next's loaders. An
  import into a graph of an existing ledger refuses triple terms and edge
  annotations: the splice merges no triple-term dictionary yet.
- Iceberg: `create_iceberg_graph_source` goes with main (a source needs a
  mapping); the R2RML path keeps next's `model_instance`.
- CLI: main's shared import flags without the leaflet flags; `graph
  import` routes through next's process-wide server routing, and
  `upload_source_import` serves next's `Destination`. Doc sources read a
  ledger through the command's open instance.
- Tests: sibling ledger ids become distinct names, `genesis_ledger` is
  awaited, Cypher state dumps include each relationship's `rdf:reifies`
  link, and the graph-import arena test checks the refusal instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:query Query execution, planning, fast paths, overlay, result formatting bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants