Repository navigation
fix(query): a subject probe over a graph with no branch finds nothing - #2187
Conversation
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.
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
left a comment
There was a problem hiding this comment.
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.)
| // 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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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.
|
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 (
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.
I also went through the rest of the
If any of that reads wrong to you, happy to talk it through. |
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.
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
GRAPH <g3> { ?x ex:sel ?y . ?y ex:v ?o }after writingex:b ex:sel ex:y0into a new graph<g3>, whenex:vis indexed only in<g1>. The same join over the default graph failed the same way onceex:a ex:sel ex:y0was written there.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.p_id_or_none, next tobranch_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.GeoSearchOperatorresolves the graph's POST branch once atopen. A graph with no branch gets an empty manifest, so the cursor has no leaves and reads the overlay opsopenalready 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.opentook 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.Tests
it_named_graphs::a_join_in_a_graph_written_after_the_index_probes_it_and_finds_nothing:<urn:g1>, then writesex:selinto the default graph and into a new graph<urn:g3>.FROM <urn:g3>,GRAPH <urn:g3>, and the JSON-LD["graph", "urn:g3", …]twin. The same join in<urn:g1>answers its one row.GRAPHspellings 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.GRAPHand JSON-LD spellings fail withPSOT index not found for graph.fast_path_common::tests::branch_or_none_refuses_a_merge_over_a_graph_with_no_branchcovers 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_holddoes the same for the predicate lookup.it_join_batched_overlay::probe_helpers_merge_noveltygains 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_forindexes geo points in<…/germany>, then writes points into the default graph, a new<…/italy>, a new<…/spain>underex:position(a predicate the index doesn't hold, next to another novelty-only predicate), and anex:positionpoint into germany. The search answers the novelty's points over the default graph,GRAPH <italy>and its JSON-LD twin,GRAPH <spain>, and germany'sex:position; germany's indexed points are the control. With the old branch error put back, the four branchless spellings fail withno POST branch; with the old predicate lookup, the twoex:positioncases return no rows.The branchless-graph join test no longer runs its queries once and rebuilds tracing interest before capturing:
init_test_tracinginstalls throughscoped_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
openinstead of per center row.