Skip to content

fix(query): several graphs answer from the graphs they name, at lane speed; typed literals and string filters keep their terms - #2214

Merged
aaj3f merged 307 commits into
mainfrom
fix/lanes-and-typed-strings
Nov 17, 2026
Merged

aaj3f merged 307 commits into
mainfrom
fix/lanes-and-typed-strings

Conversation

@aaj3f

@aaj3f aaj3f commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

This is the follow-up #2010 said was coming ("Lanes that read one graph, and typed strings on the range scan"), and it grew, on purpose. The first half of it is what the original follow-up was: several single-graph lanes asked "does this query span ledgers?" when what they need is "does this scope read exactly one graph?", so over the union default graph, FROM naming several of a ledger's graphs, or FROM NAMED alone, they read one member's index and answered from that — silently wrong. The honest fix for that is to stand those lanes down and let the general plan answer, which is right but slow over several graphs (up to a few hundred × main on the counts), and I didn't think we should ship a correctness fix that turns fast-but-wrong into slow-but-right on shapes people actually run. So the bulk of this PR is making those shapes fast again correctly: a scope type that says what a query's default graph is (one graph, several graphs of one store, or none), and a union variant of each lane that reads every member's index and answers as the merged graph does. Measured on a clean EC2 box, every one of those shapes is now within its target of main's (wrong) cost, and several are faster than main was.

Along the way the union itself needed fixing: a default graph of several graphs is the set union of their facts, and the dedup was keying on the emitted row, so it collapsed solutions the graph alone keeps apart (a list's repeated value, or a constant that matches 1 and 1.0e0) and adding an empty graph could change an answer. That's now storage's fact identity (#2109's FactIdentity), and the union's rows stay encoded instead of being decoded at every member scan (#2015). Lists follow #2217: SPARQL reads a list's members as values, as JSON-LD does, so every lane answers list patterns on both surfaces, a repeated member a row each time. Two smaller things rode along because they touch the same seams and were wrong on main: FILTER string comparisons that were pushed into the scan compared text only (so = "a" matched "a"@en), and STRDT / typed literals failed the whole query for a datatype namespace the ledger hadn't seen (#1765). Each is its own section below, fwiw, so it can be reviewed on its own.

Fixes #1771
Fixes #1765
Fixes #2015

Partially addresses #2075 — the one-graph witness is in (IndexScope, and one_graph_view() is None under a union, so an index read there doesn't compile), and so is the k-way merge for the partitioned GROUP BY. Still open there: fulltext()'s arena statistics under a union, the Cypher metadata functions (labels, keys, properties), rules over several graphs, and making binary_g_id private (it's deprecated, 128 sites).

Follow-up: #2072

Wrong results this fixes

Reproduced on main (42bb9646c for the rows added here, f3c3b00ec for the original follow-up's), each pinned by a test with a hand-written answer.

Scope Reproducer Main returns Right answer
FROM <g2> FROM <g3> SELECT ?v (COUNT(*) AS ?k) WHERE { ?s ex:amount ?v } GROUP BY ?v 1.5:1, 1.5:1, 2.5:1, 2.5:1 (each group split per graph) 1.5:2, 2.5:2
union default graph the same GROUP BY (and its JSON-LD groupBy twin) 1.5:1, 1.5:2, 2.5:1, 2.5:1 1.5:3, 2.5:2
union default graph a triangle, ?x ex:knows ?y . ?y ex:knows ?z . ?z ex:knows ?x no rows 6 rows (one cycle across graphs, one inside g2)
FROM NAMED <g2> alone the same triangle g2's 3 rows no rows (the default graph is empty)
union default graph ?x ex:amount ?v FILTER(EXISTS { ?x ex:label ?l } && ?v > 0) x1 x1, y1
union default graph SELECT (COUNT(?s) AS ?n) WHERE { ?s ex:kind ex:T } 1 3
union default graph SELECT ?p (COUNT(?s) AS ?n) WHERE { ?s ?p ?o } GROUP BY ?p kind:1, tag:1 kind:4, tag:3
union default graph a geof:distance(…) <= 500000 filter paris brussels, london, paris
Cypher, f:unionDefaultGraph a label count; a triangle; a count per related node 1; no rows; Sales split in two 4; 3 rows; Ops:1, Sales:3
FROM <g1> FROM <gEmpty> ?s ex:p 1 over a p 1, 1.0e0 a a, a (as FROM <g1> alone)
FROM <g1> FROM <gEmpty> ?s ex:q ?o over d q (5 5 7) (d,5) (d,7) (d,5) (d,5) (d,7)
FROM <g1> FROM <g2>, both holding `alice worksFor acme { role Engineer }` `?s ex:worksFor ex:acme {
one graph, ex:a ex:knows (ex:b ex:b) closing a triangle the triangle one rotation short (the cyclic lane took a pair stored twice once on its closing edge) both rotations, as the general plan
FROM <A> FROM <B> (two ledgers) ?s ex:label "chat"@fr, VALUES of it, a join on it, the JSON-LD twin; the same for "A1"^^ex:Code; SPARQL parameters bound to them no rows a, b
one ledger, a view policy on ex:label / ex:code ?s ex:label "chat"@fr, "chat"@en, "A1"^^ex:Code no rows b, c, b
FROM <C> FROM <D>, ct: only in D, or coded differently (#1771) ?s ex:p "a"^^ct:T; ?s ex:p ?o no rows; D's ct:T printed as another IRI d1; ct:T
push retracting an indexed "chat"@fr refused: "retraction invariant violated" accepted
one ledger FILTER(sameTerm(?o, "abc"^^ex:custom)); FILTER(?o = "abc"^^xsd:token); BIND("abc"^^ex:custom AS ?x) then DATATYPE(?x) the plain "abc"; every "abc" of any type; xsd:string s2; s4; ex:custom
one ledger FILTER(?o = "a") over "a", "a"@en, "a"^^ex:T (pushed) all three "a" only, as the evaluated filter answers
one ledger BIND(STRDT(?v, <http://nowhere.example/T>) AS ?x) the query fails: "Unknown datatype IRI" the literal
one ledger, a stored "…T10:00:00.2Z"^^xsd:dateTime FILTER(?at > "…T10:00:00.5Z") FILTER(?at > "…T10:00:00Z") (two string bounds the merge ordered as text) the row no rows, as evaluated
one ledger INSERT { ex:s ex:ref ?o } WHERE { ex:s ex:p "a" VALUES ?o { <http://unseen-a.example/o> } } ; INSERT DATA { <http://unseen-b.example/y> ex:p "b" } (and, with this PR, the same through IRI(), a constant BIND or STRDT) namespace conflict: code 14 …, on every retry commits

#2187 fixed one more row of this table first (a batched subject probe over a graph the index has no branch for), so it's not here anymore; this branch takes main's fix for it. The last two rows came out of review. (So did a cross-ledger double count, but that one never reached main: there the query matched nothing, the #1771 row above.)

Several graphs, fast: the lanes, against their targets

The targets are the multiples of main we set before any lane was built — main is fast on these shapes only because it reads one graph's index, so "as fast as main" isn't reachable while being right, and each target is what that shape's correct answer can reasonably cost. The grouped count has its own target: at most 2× the one-graph lane over a single graph holding the same deduplicated facts (the "floor").

Measured on a c7i.4xlarge (Xeon 8488C), release profile (fat LTO), one harness (fluree-db-api/examples/multigraph_lanes_ab.rs) built against main 42bb9646c, the general plan (this branch's tests with no lane) and this branch. Three rounds in a Latin square, 5 reps each, wall-clock per query; for the targets defined in instructions, perf stat instructions per query (the difference of two runs). Scopes, 3,000 subjects per graph: mg = FROM <g1> FROM <g2> (half overlap), mgd = two disjoint graphs, mg3 = three graphs, mgu = the union default graph (four). Every union cell's answer equals its floor's; main's is wrong in all 25 union cells.

Lane Shape Target mg mgd mg3 mgu Met
EXISTS cache FILTER(EXISTS {…} && …) ≤ 1.34× main 0.35× 0.39× 0.37× 0.37× ✓ (faster than main)
object count COUNT(?s) over ?s ex:kind ex:T1 ≤ 4× main (≤ 1.35× disjoint) 1.04× 0.88× 1.10× 1.19× ✓
per-predicate count COUNT(?s) per predicate ≤ 7.7× main 4.3× / 5.75׆ 1.4× / 1.32׆ 4.4× / 5.70׆ 5.2× / 6.75׆ ✓
cyclic join triangle ≤ 5.6× main 1.88׆ 2.01׆ 3.21׆ 4.43׆ ✓
grouped count COUNT(*) grouped by ?v ≤ 2× its floor 0.28× floor 0.17× 0.27× 0.21× ✓ (main: 0.01×)
annotation chain first row / COUNT ≤ 1.1× main 1.00× — — 1.00× ✓
annotation chain driven — 0.26× main — — (main errors)
union probes subject / object / existence joins — 0.06× / 0.06× / 0.06× 0.05× 0.05× 0.04× (main: wrong)

Wall-clock ÷ main on EC2 unless marked. † is instructions ÷ main counted locally (macOS proc_pid_rusage, release, three interleaved rounds of 10 reps, every cell's spread ≤ 0.6%), for the two lanes whose targets are instruction counts and whose EC2 instruction readings needed settling. Absolute, e.g. mg_exists 3.30 ms against main's 9.42 ms (general plan 58.7 ms), dgs_mg_count 10.25 ms against 10.24 ms.

Two lanes want a word:

  • The cyclic join over four graphs (mgu_cyclic) first missed its target: on EC2, 5.64× main in instructions against 5.6×, and 6.7× on the clock. It still decoded every row it emitted under a union, which the union's term view made unnecessary, so ca5cf37a2 emits them encoded, as a scan of the union does. Counted locally, that takes mgu_cyclic from 221.7M to 176.4M instructions against main's 39.8M (5.57× → 4.43×), and the other three cells down 20–24% (mg 94.2M → 74.7M). The EC2 wall-clock figures were measured before that change; on the clock it was 2.8× / 3.0× / 4.9× / 6.7× main.
  • The per-predicate count's EC2 instruction ratios read 7.8–8.5×, but main's count there is ~0.24M instructions and moved ±15–35% run to run on the box (the process-wide counter takes in background threads). Counted locally, where each cell's spread is ≤ 0.6%, main is 0.29–0.34M and the lane 1.86–1.94M: 5.7–6.75× with overlap, 1.32× disjoint. On the clock it's 4.3–5.2×.

One graph, the hot path: parity. Against the general-plan build, the one-graph cells (sg_*, g1_*, the floors f2*/f3*/fu*, and the one-graph chain dgs_g1_*) are within +2.7% on the clock on EC2, inside each cell's own spread (≤ 9.7%), and within ±1.5% in instructions. The one outlier there, g1_count_pred at +5.1% with a ~20% spread, is noise: counted locally it's 0.314M against main's 0.313M (+0.1%, spread ≤ 0.8%), and sg_count_pred is +0.4%. The one-graph cyclic join is 2.6% under main locally. Against main on EC2, the largest is dgs_g1_driven at +1.7%, which predates the lanes (it's the same at their merge base).

What changed

One definition of "reads one graph", then a scope type. The original follow-up added ActiveGraph::reads_one_graph(dataset) and gated every single-graph lane on it. Here that becomes ExecutionContext::index_scope() -> Option<IndexScope>: One(IndexMember), Union(MemberSet) (two or more graphs of one store, each member with its g_id, overlay and to_t, certified to share the store and its dictionary novelty), or Empty. Members of FROM <L#g1> FROM <L#g2> only shared a store when the ledger cache served both loads; each ledger is now loaded once per time per dataset (f2a72cfbd), so the certificate holds on every load path. The view split is in the types: one_graph_view() returns None under a union, and a union gets a decode-only TermView with no g_id and no index access.

Union lanes. Each lane gates on match ctx.index_scope(): One is today's lane unchanged, Union is its union variant (stamped as its own site, …_union), Empty answers nothing without reading an index, anything else falls back. A union variant that can't prove a case exact declines with a named reason (fallback:novelty, fallback:arena_type, fallback:list_view, fallback:store_mismatch, fallback:kill_switch). The union variants sit behind the fast-path kill switch, so the general plan stays a differential oracle for them.

  • A merge cursor, a k-way merge over the members' index ranges (5dbaa226c), deduplicating by adjacency on the full key (s, p, o_type, o_key, o_i), which is exact in every index order. The object count, the per-predicate count and the grouped count read through it.
  • The EXISTS cache builds its subject set from every member (43d844871).
  • The object count counts distinct subjects of a bound object over the merge (bd4911ee4).
  • The per-predicate count counts facts per predicate by identity (219aefe52), keying big numbers by value.
  • The cyclic join reads each edge's relation from every member as a set of facts (3b96f416c), and emits its rows encoded (ca5cf37a2).
  • The grouped count (the partitioned GROUP BY) merges the members' ranges and counts runs of equal keys (a787bf7ac).
  • The union probes: the nested-loop join's batched probes read every member and keep one row per fact (3945cb0b5). Each member resolves its branch and the probed predicate through main's branch_or_none / p_id_or_none with its own plan, as one graph does (be4c6ae4a), so a member the index has no branch for reads nothing, and one asked to merge novelty there is refused rather than answered short. Today plan_union_probe declines any member with novelty, so this changes no answer; it keeps the union from depending on that.

Fact identity. A member scan records beside each row the fact it matched (RowFact: the term a constant object matched, and the list position), and the union's dedup keys on the row plus its fact (608869cb2). Every reader that collapses a union's rows now keys on one set, UnionFactSet (c0edf3f9b), whose keys are 16-byte terms in one buffer, so a kept row allocates nothing of its own. The edge-annotation chain under a union is built once over the whole union instead of once per source (1c756de51).

Union rows stay encoded (#2015). Members no longer decode every value as they scan (b14f0cda5). The one kind of value that's only meaningful inside its graph — an arena handle (a big decimal, a vector), numbered per (graph, predicate) — now carries its graph in Binding::EncodedLit (arena_g_id, 9f9869c0d), so it decodes through its own graph anywhere and compares by value where equality matters. Decoding fails closed: an encoded value that can't be decoded is an error, not a value passed through (0e1262e09), with the per-row paths kept as lean as before (7d0f33cbb).

Lists (#2217). A list's members are values of the predicate that holds it on both surfaces, a fact per list position, so the union lanes run on list predicates for SPARQL as for JSON-LD, and a repeated member counts each time. Where a request still reads lists as RDF (the Graph Store GET), a union lane meets cells no stored row is, and stands down with fallback:list_view for the general plan.

The original follow-up's typed-string and expression work is unchanged from its review: the range scan keeps a bound string's datatype, re-coded into the scanned ledger (that's #1771); a SPARQL typed literal in an expression lowers as STRDT; and the re-coding happens only where codes can differ.

From review. Each of these has a test that fails without it.

  • A multi-op update reserves every lowered namespace before it stages (8a41c82c6). Every op is lowered before the first one stages, but each carried only the namespaces lowered up to it, so an op that registered a namespace while staging (an IRI it binds and writes) took a code the lowering had already given a later op's namespace, and the request failed on every retry. Each op of a multi-op request now carries the whole request's lowered namespaces.
  • A cross-ledger union keys a fact on the query's datatype codes (bfded8dfc): the fact a member matched is re-coded with its row (stamp_row_facts). With ex: coded differently in two ledgers, ?s ex:p "v"^^ex:dt over both returned a subject both hold twice, and a ground COUNT(*) counted 2, once this branch made the Multi-ledger datasets: datatype-constraint Sid is never re-encoded per graph, so cross-ledger custom-datatype matches silently drop #1771 shape match.
  • The union count lanes answer to the memory budget and cancellation (da06179fd, cdd0d7c7c). The per-predicate count checkpoints per batch, reads through the fuel tracker and charges its by-value set as it grows, reserving at most 64K entries up front; a cancellation or an exhausted budget ends the query instead of declining to the general plan as a failed read does (QueryError::ends_the_query). The grouped count charges its runs per batch.
  • Two string bounds a temporal row reads differently keep both filters (42c79e490), in the pushdown's merge and the planner's: as text "…00.5Z" sorts before "…00Z", as instants after it. Both ask the scan's own comparison (ObjectBounds::string_orders_temporals).
  • STRDT refuses a datatype that can't be an IRI (f5fab7a83, eaa4c1bff), a number or a string with a space in it, as a type error; a datatype name with no scheme stays one term, as on every write path (graph_registry::is_iri_reference).
  • Search targets decode through the scope's terms (c5a7ed68f): BM25's target and S2's geometry decode through term_view(), and one the scope can't decode fails the query instead of skipping the row. Unreachable today (the planner puts search patterns first), so the tests drive the operators.
  • A plan built without its scope reads no index (e8b749d30): PlanningContext::current() / history() default to ScopeKind::None, as their doc said; EXPLAIN's physical plan and policy queries name their scope (with_dataset_scope(None)).
  • A tagged constant's range read narrows to its tag (60f3b9aac), under a view policy and across ledgers: a tag the index holds reads its own object type, a tag it doesn't hold reads novelty only.
  • A context builds its decoder once for per-value decoding (d9b3b2592). Union rows stay encoded, so a FILTER or BIND over a union decoded each value through term_view(), which walked the dataset and rebuilt the member set every time. On an EC2 c7i.8xlarge (dev-fast profile, two interleaved rounds, the median of 9 runs each): FILTER(STRLEN(?o) > 3) over a 200,000-value union ~103 ms → ~97.5 ms, its BIND twin ~106 → ~100 ms, and one graph 32.8 → 31.2 ms, since the one-graph decode built a view per value too.
  • An = against a typed literal pushes into the scan as that term (154b64e7d, d8ed067ad). FILTER(?o = "x"^^ex:T), for a datatype with no value space of its own (a custom datatype, xsd:anyURI, xsd:token), was evaluated per row, since SPARQL lowers the literal to STRDT("x", ex:T) and a pushed string bound could only be the xsd:string term (main pushed it as the plain string, and matched the text under any datatype). STRDT of two constants now folds into an = bound that carries its datatype (ObjectBounds::string_datatype), on both surfaces (JSON-LD's (str-dt "x" "ex:T") too); each reader resolves the datatype against what it reads, and an indexed scan seeks the term as ?s ex:p "x"^^ex:T does. Numeric, temporal, boolean and JSON datatypes compare by value and stay evaluated. On an EC2 c7i.8xlarge (dev-fast profile, two interleaved rounds, the median of 9 runs each), over 100,000 values: FILTER(?o = "v7"^^ex:T) ~90 ms evaluated → 0.05 ms pushed, the xsd:anyURI twin 122 → 0.05 ms; main took 6.0 and 7.8 ms, and for the custom datatype also returned the plain "v7". The controls held: a plain = 0.06 → 0.05 ms (main 6.0 ms, with the typed row too) and a numeric range 1.30 → 1.27 ms (main 1.37 ms).
  • Index reads on the range path charge fuel (5297e5c5f): the scan's range fallback (a view policy that touches the predicate, a dataset spanning ledgers), property paths' Sid lane, list entries, the RDF list view, shortest paths and search readability read the index without the query's tracker, so the leaflets they touched cost nothing; they're charged at the index-touch rate now, like the scan's index lane.
  • Fast paths charge the index they read (090d29cb0). The fast paths read the index through cursors that carried no tracker and through raw leaflet loads, and the property path's id lane through batched lookups with no tracker, so a tracked query one of them answered paid its floor and its rows however much it read, and max-fuel couldn't stop it. Every one of those reads now charges the query's tracker one index touch per leaflet, as the scan's cursor does: the cursor builders in fast_path_common and the cursors the lanes build themselves (count plans, union star counts, vector and constant-star top-k, string-prefix counts, label regex, geo search), the count plans' leaf iterators, the group-by-object count's loads, whole-graph aggregates, and batched_lookup_* under the frontier's sweeps. Raw leaflet loads go through two helpers that take the tracker (load_leaflet_projection, cached, and load_leaflet_columns_charged), so a load that skips the charge doesn't compile; a cache hit is charged like a miss. A leaf-directory read that decodes no leaflet isn't charged, as in the cursor. The charge sits where the cancellation check already did, once per leaflet, never per row.
  • The join probes charge the leaflets they read (e99940414). The batched probes read the index through LeafScan::load_leaflet: the subject probe and the subject star, the bound-object walk (POST, perf(query): probe bound objects in the predicate's POST partition #2374's) and the union's walk, the semijoin's index walk. They charged the rows they matched but not the leaflets they read; load_leaflet now takes the query's tracker and charges one index touch per leaflet, so a probe that loads a leaflet is charged by construction. What stays uncharged: a leaf-directory read that decodes no leaflet (as in the cursor), and the reads that aren't a query's own, such as a view policy's class lookups, the time resolution of an as-of, a ledger view, the indexer and the formatter. History scans already charged their leaf touches.
  • A fuel refusal inside a lane comes back as a fuel error (090d29cb0). About 50 cursor and leaflet reads in the fast paths folded the read's error into QueryError::Internal, which turned a fuel refusal (or a residency miss) into a 500, including in the merged-cursor lanes that already charged. They go through QueryError::from_io now, which keeps both.
  • The merges of main (f033bc823, 06fc82468): the union probes' per-member plans take LaneOutput::Encoded (Batched join lanes run under reasoning and decode what they emit #2271), since they emit encoded rows and the union probe declines eager materialization; the cyclic cascade, which main now has decode for an eager caller, takes DecodesForEager, and its union reads decode the same way; and main's flush now hands a declined plan's rows to the per-row path, which under a union (where the one-graph plan always declines) would have stamped the union probe proceed and never run it. That check is kept to the one-graph lane, and the lane suites now also require a batched flush span wherever the union probe must fire (b2aeb8e68).

What the fuel costs. Every lane charges the exact leaflets it reads; none needed an estimate, since the charge costs nothing measurable, tracking off or on.

  • The count iterators' refills moved out of the per-group loop (d86a29734). The one cost the charge showed was in the count iterators: their refill is inlined into the per-group loop, and the charge kept the tracker live across it, so every group paid for one more saved register, about 1.1% more instructions on the count plan, tracking off or on. Those refills are out of line now, and charge_leaflet inlines only its enabled check. Measured on an EC2 c7i.8xlarge (fat-LTO release builds, 1,000,000 subjects, rayon on one thread so its spinning doesn't count), instructions per query against main, the same with tracking off and on: the count plan −1.9%, MINUS −4.1%, EXISTS −4.1%, OPTIONAL −0.9%; the chain fold, a class-anchored aggregate, geo search, a numeric-compare count and the path's id lane within 0.6%; a range scan −5.1%. Against the commit before the charge, every lane is within 0.1% but the group-by-object count, whose ±1% is inside its run-to-run spread. Wall time over 5 interleaved runs of 20 queries: the single-threaded lanes within 1% of main (label regex and the range scan 2% faster), and the parallel count lanes 2–21% faster than main, though at a few milliseconds a query their run-to-run spread (5–30%) is wider than the difference between commits.
  • After the last merge of main (ae72f55f6, perf(query): probe bound objects in the predicate's POST partition #2374), on the same box and build, 100,000 subjects, instructions per query against main f42ea3784 and this branch's head before that merge (06fc82468), tracking off and on alike: the count plan −1.94% against main and the same as before; the cyclic join and a one-or-more path count unchanged; the union bound-object probe 3.3% under the head before the merge; and a union join on a string object, which the merge first sent to the per-row scan (+2.6%), 68.8% under it once the union's walk took strings (09da10e44): 247M instructions a query against 790M, 25 ms against 96 on the clock, and 3.6× under main's (wrong) answer. The leaflet charge in load_leaflet (e99940414) costs nothing measurable: against the commit before it, the one-graph subject and bound-object probes and both union probes are within 0.1%. The one-graph bound-object probe, main's code now, reads +0.1% against main and the subject probe +0.25%, and a constant GRAPH block +0.5%; all three were there before the merge too, in the branch's shared query path rather than the probes, and the clock doesn't see them: wall time is within ±2% of main on every lane that takes over a millisecond. (The count plan, at under a millisecond, swings more run to run than any of these differences.)
  • Two lanes read higher than main for a reason unrelated to fuel. The constant-star top-k is +0.86% instructions against main and label regex +0.83%, both at those levels before the charge. Neither lane's code, nor the cursor or dictionary code it runs, differs from main; a bisect across this branch and main puts the difference in LTO's inlining choices. The star top-k's count takes one of two values, about 110.9M or 111.8M instructions a query at 100,000 subjects, and main takes both: it drops 0.74% from 42bb9646c to 149d02d81, 223 commits that don't touch the lane. Profiled, main inlines the numeric filter (filter_subjects_by_numeric_gt and the row walk under it) into the operator, and this branch keeps the filter as its own function; #[inline(always)] on the filter made it worse (112.44M, +1.4% against main), and on both functions brought it to +0.27%, never to main's count. Label regex moves 0.4% between main commits that don't touch it as well. Wall time is flat on both at 1,000,000 subjects (77.97 against 77.80 ms; 53.60 against 54.69 ms), so they stay as they are, rather than pinned to an inlining the next unrelated change can flip.

Behavior changes against main

  • Queries over several graphs, or none, answer from the graphs they name — the shapes in the first table — and, for the lane shapes, at about lane speed rather than the general plan's.
  • A default graph of several graphs is the union of its facts. A fact two members both hold collapses, and nothing else does: a list's repeated value and a constant's matches of two datatypes stay separate, as in one graph. An annotated edge two graphs both hold is one solution.
  • The cyclic join on one graph returns a pair stored twice (two list items with one value) twice on its closing edge, as the general plan does.
  • A union default graph of one member counts as one graph at plan time, as it already did at run time.
  • On the range scan, a language-tagged or custom-datatype constant matches its rows, a member ledger's custom datatypes print with their own IRI, and push accepts a retraction of an indexed typed string.
  • A SPARQL typed literal in FILTER, BIND, IN or HAVING is its own term.
  • FILTER string comparisons are exact on every lane (SPARQL, JSON-LD and Cypher WHERE): a pushed = "a" no longer matches "a"@en or "a"^^ex:T. The full table is in the string-filter section below.
  • A plain string is never = a temporal, while ordering still reads it as one, so <= and >= can both hold where = doesn't. SPARQL has no = operator for an xsd:string and an xsd:dateTime, so it's a type error and the FILTER is false. Two of fix(transact): write fidelity, part 2 — one fact identity, microsecond temporals, value reads #2109's microsecond tests expected = to hold there (a JSON-LD filter's bare string against a stored dateTime, and a stored plain string against a typed constant); they now expect false, and their ordering checks are unchanged (ba1d81980).
  • STRDT, typed literals and JSON-LD str-dt build their literal for any datatype IRI, and an update can write an IRI IRI() / UUID() / (iri …) builds in an unseen namespace. JSON-LD's str-dt and constant iri arguments expand through the @context under the insert's compact-IRI guard. Table in the STRDT with an unregistered datatype IRI fails the query instead of producing the literal #1765 section below.
  • JSON values are their own datatype in comparisons: ?j1 != ?j2, ?j1 < ?j2 and the truth value of a JSON value are now type errors, so those rows drop.
  • A bound "…"^^rdf:JSON is refused on insert: binding one and then inserting it now returns 400. It used to be stored as a plain string.
  • JSON-LD constant iri arguments go through the compact-IRI guard, which by default refuses a prefix the @context doesn't define, so an IRI in a scheme like tag:, arn:, doi: or info: is refused as an undefined prefix unless opts.strictCompactIri is false.
  • STRDT with a datatype that can't be an IRI (a number, or a string with a space) is a type error: unbound in a query, and an update fails. It used to build a literal typed with the string, which an update stored, or for a number a plain string.
  • A multi-op update whose first op writes an IRI in an unseen namespace commits, where it failed with a namespace conflict when a later op also named an unseen namespace.
  • Two string bounds on a temporal object stay two filters, so FILTER(?at > "…00.5Z") FILTER(?at > "…00Z") answers as evaluated.
  • A union count over large data can stop on the memory budget or a cancellation, as the other lanes already do.
  • Fuel totals rise for queries whose scans read the index through the range path (a view policy that touches the scanned predicate, a dataset spanning ledgers, property paths over several graphs or under a policy, the RDF list view, shortest paths): each leaflet they read is now charged at 0.01, as the index lane charges it, so a query near its max-fuel may now be refused.
  • FILTER(?o = "x"^^ex:T) and its JSON-LD twin push into the scan for a custom datatype, xsd:anyURI or xsd:token, and match only that term; the answers are those the evaluated filter gave on this branch.
  • Fuel totals rise for batched joins: the nested-loop join's subject, bound-object and existence probes, and the range semijoin, now charge 0.01 per leaflet their probe reads, on top of the rows they match.
  • Fuel totals rise for queries a fast path answers (counts, aggregates, top-k, string-prefix counts, label regex, geo search, one-or-more paths): each leaflet they read is now charged at 0.01, as the scan charges it, so a query near its max-fuel may now be refused. A refusal inside one of these lanes is a fuel error (400), where it could surface as an internal error (500).
  • COUNT(?s) over a bare decimal or big integer takes the one-graph count instead of falling back; same answers.

No wire or index format changes. ObjectBounds has a new field, string_datatype (a struct literal needs string_datatype: None). Two more API notes for an embedder: fluree_db_core::RangeMatch has a new public field, lang (a struct literal needs lang: None, or ..Default::default()), and PlanningContext::current() / history() now plan for no index until with_dataset_scope gives them their scope (with_dataset_scope(None) for a ledger's own default graph). fluree_db_binary_index::batched_lookup_predicate_refs, batched_lookup_subject_properties and batched_lookup_inbound_refs take the reader's &Tracker last (&Tracker::disabled() reads unpriced). New public items, additive: QueryError::ends_the_query, ObjectBounds::string_orders_temporals, graph_registry::is_iri_reference, ExecutionContext::with_term_view, fluree_db_core::StringDatatype, Expression::as_typed_string_literal.

Known limits

  • Novelty is judged per ledger. The EXISTS cache, the object count, the per-predicate count and the grouped count take a union only when every member is current with its index, and novelty in any graph counts, so a write to one graph turns those lanes off for every union of that ledger until the next index build; the general plan answers right meanwhile. The cyclic join and the union probes follow each member's own novelty. Per-graph currency would change every lane, one-graph ones included, so it's out of scope here.
  • fulltext() under a union still scores against one graph's BM25 arena (Scopes of several graphs: a one-graph witness type, and the readers that still read one graph #2075).
  • The grouped count decodes each group's key under a union, once per group rather than per row (20 groups in the harness), so keeping it encoded isn't worth a change.
  • Arena types (vectors, spatial) decline in the merge-based lanes; big numbers are keyed by value in the per-predicate count and declined in the object count's top-k, where handle order isn't value order.

Tests

Every lane runs on one shared fixture, the multigraph fixture (fluree-db-api/tests/support/multigraph.rs): 17 scopes (each union spelling, FROM NAMED alone, GRAPH, two ledgers, time travel below the index, and unions over a default graph the index holds no leaf for) in three states (indexed, novelty in g2, read below the index), SPARQL and JSON-LD, against hand-written answers and against the general plan with fast paths off, with routing stamps (MustFire the union site, MustNotFire the one-graph site, and the reverse on one graph). it_multigraph_lanes holds each lane's matrix, plus two list fixtures — lists on every lane's own predicate in two members, and the same lists only in novelty — where every lane shape answers a hand-written answer on both surfaces, fast paths on and off, SPARQL routes as JSON-LD does, and over indexed lists every union site must fire. One canary keeps the RDF view honest: the per-predicate count with the Graph Store GET's execution option must stand down with fallback:list_view and answer the cells. Wherever the nested-loop union probe must fire, the run must also have opened a batched flush span, since the stamp is set at planning, before a flush could still hand its rows to the per-row path. The union probes have their own fixture (support/union_probes.rs) for fact-identity cases its probes must keep apart, and traps for arena literals crossing every consumer (scan, ORDER BY, FILTER, DISTINCT, GROUP BY), on both union spellings, indexed and with novelty. it_union_annotation_chain, it_cyclic_bgp_multiplicity and it_string_filter_pushdown are their own binaries, since they toggle the kill switch; it_union_fact_identity holds the switch lock inside grp_query. it_sparql_list_members's CONSTRUCT case (from #2217) also runs against an index and over FROM <g1> FROM <g3>, where only one of the two graphs holds the list, so the list rows reach the template encoded and decode through the scope's terms (be4c6ae4a).

The red/green record (each fix shown failing without it), the merge log for all seven main merges, and the per-area test lists are in this comment, to keep the description under GitHub's size limit.

Gates

On Linux (EC2 c7i.8xlarge, Amazon Linux 2023 with gcc 14, linked with mold as CI does), all at the head, 09da10e44:

  • cargo fmt --all -- --check, and in testsuite-sparql/: clean.
  • cargo clippy --all --all-features --all-targets --locked -- -D warnings: clean. In testsuite-sparql/, cargo clippy --all-targets -- -D warnings: clean.
  • cargo check --workspace --all-targets --locked and cargo check -p fluree-db-server --no-default-features --features native --locked: clean.
  • wasm32 clippy (the engine stack, and the parse layer with no default features): clean; the wasm32 runtime probe under Node passes.
  • The lane routing tests first (it_multigraph_lanes, it_union_annotation_chain, it_cyclic_bgp_multiplicity, and every union / lane / fast-path / batched / probe test of fluree-db-api, it_fast_path_fuel included): 269 of 269.
  • cargo nextest run --workspace --all-features --no-fail-fast --locked: 16,305 of 16,305.
  • cargo test -p fluree-db-api --all-features --test harness_coverage: 2 passed.
  • cargo test --workspace --all-features --doc: 48 passed.
  • cargo test --no-fail-fast in testsuite-sparql/: 85 tests across its 31 result groups (the W3C manifest groups, its unit tests and the w3c_rdf manifests) pass.

Earlier full runs this round, at the heads before main moved, each met one of main's load flakes, both of which passed alone right after: it_wal::a_transaction_costs_one_flush and it_transact_update_indexed::multi_op_reversal_nets_a_value_the_index_keeps_less_of.

Merged with main

Seven merges of main, the last ae72f55f6 (main f42ea3784, with #2374), plus 09da10e44, which lets the union object probe walk string objects too after that merge. How each conflict was resolved is in the evidence comment.

FILTER string comparisons keep their term semantics when pushed

FILTER(?o = "a"), and <, <=, >, >= against a plain-string constant, are pushed into the scan as object bounds and the filter is dropped. The bounds compared only the decoded value, so a pushed = "a" also matched "a"@en, "a"@fr and "a"^^ex:T. The same comparison evaluated (under ||, or as !=) is strict, as decided in D-12 / #1462, so "a"@en satisfied both = "a" and != "a". This hit SPARQL, JSON-LD filters and Cypher WHERE s.p = "a" alike, and it's why W3C expr-equals#eq-4 was on the skip register. The register's note there blamed late materialization; the filter never actually ran on that test, since it was pushed.

A pushed bound now answers what the evaluated filter answers, for every kind of stored value, on every lane that applies bounds. A string bound is the xsd:string term: it equals only xsd:string objects, and it orders xsd:string objects and (as the evaluator does) temporal values it can be read as, never a tagged or otherwise-typed string, a number, a boolean or an IRI.

What changes

  • ObjectBounds matching takes the stored object's datatype. matches(value, dt) for a flake, matches_encoded(value, o_type) for a binary-index row, and matches_number for the range semijoin's numeric check. The old value-only matches is gone, so the compiler listed every consumer (16 sites, in the binary scan, the batched join probes, the range provider, history, and the range semijoin), and none of them can apply a string bound by text alone anymore. is_xsd_string_datatype in fluree_db_core::datatypes recognizes every form a datatype Sid takes.

  • = never equates a string with a temporal. <, <=, > and >= do order a plain string against a dateTime, date or time value by reading it as a value of that kind, as the evaluator does, so FILTER(?at < "2026-01-02T00:00:00Z") over xsd:dateTime keeps returning what it did. Both sides now order through one function, fluree_db_core::temporal::cmp_with_lexical. That's the function fix(transact): write fidelity, part 2 — one fact identity, microsecond temporals, value reads #2109 introduces to read such strings to the microsecond, so when it lands the scan and the evaluator move together. The temporal slices a string bound seeks are derived from the same function. = and >= && <= push the same two bounds, though, so ObjectBounds now carries temporal_string_ordering, set only when no = contributed (RangeConstraint::from_equality tracks it through the planner's merges). Before this, FILTER(?d = "2026-01-01") over xsd:date matched when pushed, and so did FILTER(?s = "2026-01-01"^^xsd:date) over an xsd:string (on novelty; the index already seeks only dates there), while both are false when evaluated.

  • The binary index seeks the slice the bound admits. POST orders by (p, o_type, o_key), so a string bound now seeks the predicate's xsd:string slice instead of decoding every row the predicate holds. An equality seeks its one string id, as the constant ?s :p "a" does, or falls back to novelty alone when the index has never seen the string. A range whose string parses as a date (or another temporal) also seeks those temporal slices. The string_bound_seek routing stamp marks it.

  • Separate FILTERs that can't be merged keep their filter. Two FILTERs on one variable with bounds that can't be ordered against each other (FILTER(?o > 1) FILTER(?o > "a")) used to merge by picking one bound by type order and consuming both filters, which dropped the other filter. merge_object_bounds now returns None there, and the second filter stays as a filter. Two string bounds on one side are unorderable too when the bounds order strings against temporals and either string reads as one, since a temporal row orders them by instant and a string row by text (42c79e490, from review; the planner's merge does the same).

  • Only a plain string is read as a temporal. The evaluator read any string-backed literal as a date for </>, so "2026-01-01"@en and "2026-01-01"^^ex:T passed FILTER(?d < "2026-02-01"^^xsd:date), though each is a term of its own type. Now it's a plain string only (a simple literal or xsd:string), in either direction, in the evaluator and the bounds alike.

  • A string bound is read as a temporal once per kind. A plain-string range over temporal rows parsed the bound for every row. temporal::lexical_as_kind_of reads a lexical as a temporal kind by the same parse cmp_with_lexical uses (a test pins that the two agree), and ObjectBounds::prepare keeps that reading per kind for the scan and the flake lanes.

  • A temporal range also seeks the xsd:string slice. A typed-date range sought only the date slice on the index, so a plain string stored as "2026-01-01", which < orders against the date, passed on novelty and was never read on the index. The scan now seeks the xsd:string slice beside the date one, without the date key range. = never equates the two and keeps the single seek.

  • @fulltext and JSON compare as their own datatypes, and the string builtins read them as text. An @fulltext value is f:fullText (as docs/indexing-and-search/fulltext.md puts it), so a pushed string bound leaves it out. The evaluator matched it as a plain string on the index only, where it stays late-materialized, and now carries f:fullText there too. JSON reached the evaluator as a plain string on both lanes, so evaluated = and < matched it where the pushed bound didn't; it's an rdf:JSON literal now. On novelty, CONTAINS, REGEX, STRSTARTS, SUBSTR, CONCAT and STRBEFORE refused an @fulltext value (SUBSTR failed the whole query). All the string builtins now take arguments through one accept-set, reads_as_text (a simple literal, xsd:string, a language tag, @fulltext, rdf:JSON), where string_arg, STRBEFORE/STRAFTER and CONCAT each kept a copy, and CONCAT's had drifted.

  • An = against a typed literal is a bound of its datatype. A string bound used to be the xsd:string term only, so FILTER(?o = "a"^^ex:T) was evaluated rather than pushed. ObjectBounds now carries a datatype for an =-only string bound (string_datatype), folded from STRDT of two constants for a datatype whose value is a string; it matches only objects of that datatype, and an indexed scan seeks the term (typed_string_bound_seek).

The R2RML / Iceberg lanes didn't need a change. Their pushdown only prunes files and keeps the FILTER as a residual, and the SQL lane already compares by RDF class (exact_eq).

Out of scope, unchanged and pinned: a bare JSON string as a constant object in a JSON-LD where ("ex:p": "a"), and a Cypher property map {p: "a"}. Both still match the text under any string datatype or tag, as docs/concepts/datatypes.md documents.

Behavior changes

Data on one property: ex:plain "a", ex:xs "a"^^xsd:string, ex:en "a"@en, ex:fr "a"@fr, ex:typed "a"^^ex:T, ex:other "zzz", ex:b_en "b"@en; and on a date property, ex:day "2026-01-01"^^xsd:date, ex:day_s "2026-01-01".

Query Before After
FILTER(?o = "a"), "a" = ?o, ?o = "a"^^xsd:string (SPARQL); (= ?o "a"), ["=", "?o", "a"] (JSON-LD); WHERE s.p = "a" (Cypher) plain, xs, en, fr, typed plain, xs
FILTER(?o < "b"), ?o >= "a" && ?o <= "a", (< "" ?o "b") plain, xs, en, fr, typed plain, xs
FILTER(?o > "") every string-backed value plain, xs, other
FILTER(?d = "2026-01-01") over dates and strings day, day_s day_s
FILTER(?at = "2026-01-01T10:00:00Z") over xsd:dateTime the dateTime and the string (pushed), while != also held for the dateTime the string only, as BIND, VALUES and || already answered
FILTER(?d = "2026-01-01"^^xsd:date) day, day_s on novelty; day on the index day
FILTER(?d < "2026-02-01"), FILTER(?at < "2026-01-02T00:00:00Z"), and ?at >= "…" && ?at <= "…" with one string ordered by reading the string as a temporal unchanged
FILTER(?o > 1) FILTER(?o > "a") (two FILTERs, SPARQL or JSON-LD) the strings above "a" nothing, as the two filters evaluated give
FILTER(?at > "…T10:00:00.5Z") FILTER(?at > "…T10:00:00Z") over a stored …T10:00:00.2Z the row (the merge kept the bound greater as text) nothing, as the two filters evaluated give
FILTER(?o = "a"^^ex:T), "a"^^xsd:anyURI, (= ?o (str-dt "a" "ex:T")) typed (main: every "a" of any type, pushed as the plain string) typed, pushed and seeking the term
FILTER(?d < "2026-02-01"^^xsd:date) over "2026-01-01"@en, "2026-01-01"^^ex:T kept (evaluated, and pushed on novelty) excluded on every lane
FILTER(?d < "2026-02-01"^^xsd:date) over a plain "2026-01-01", pushed, on the index missed kept, as on novelty and as evaluated
@fulltext value, evaluated = "Hello World" / < "Z" on the index matched excluded, as on novelty and as pushed
@fulltext value with CONTAINS, REGEX, STRSTARTS, SUBSTR, CONCAT, STRBEFORE on novelty refused (SUBSTR failed the query) read as text, as on the index
JSON value, evaluated = '{"a":1}' / < "~" matched excluded, as pushed
BIND(?json AS ?x), then DATATYPE(?x) xsd:string rdf:JSON
!=, || forms, = "a"@en, sameTerm strict unchanged
"ex:p": "a" (JSON-LD constant object), {p: "a"} (Cypher map) lenient unchanged

Release note: FILTER string comparisons are now exact on every surface. Earlier releases pushed these comparisons into the index scan and matched the string's text under any datatype or language tag, while != and the same comparison under || were already exact, so "a"@en satisfied both = "a" and != "a". An LLM- or hand-written FILTER(?label = "Jazz") over "Jazz"@en labels no longer matches; to compare the text whatever the tag, use FILTER(STR(?label) = "Jazz"), and to match the tag, FILTER(?label = "Jazz"@en). Likewise FILTER(?d = "2026-01-01") no longer matches an xsd:date value, nor FILTER(?at = "2026-01-01T10:00:00Z") an xsd:dateTime one; write the typed literal ("2026-01-01"^^xsd:date). Ordering a date against a plain string with < or > is unchanged, but a language-tagged or custom-typed literal is no longer ordered against a typed date or time. An @fulltext or JSON value no longer equals (or orders against) a plain string on any lane; on an indexed ledger FILTER(?ft = "…") used to match an @fulltext value. Compare STR(?ft) = "…", or use the string functions, which read both as text everywhere. The same holds for JSON-LD filters and Cypher WHERE.

Checked, not changed: the integer = seek

FILTER(?v = 7) seeks one numeric type only when every leaflet of the predicate holds it (predicate_otype_uniform), and that check skips leaflets whose p_const names another predicate. That's sound because no POST leaflet spans two predicates: the rebuild writer and the incremental merge both cut leaflets at a p_id change (should_flush_for_segmentation, find_segment_end). The test pins it with two-row leaflets: a double 7.0 answers = 7 from the index, and from novelty over an all-integer index. A mutant that always claims uniform fails those rows, and the fast-path kill switch doesn't catch it (the seek isn't a fast path); only the evaluated form does.

Performance

Measured locally (macOS, instructions retired per query, proc_pid_rusage), release profile (fat LTO), an indexed ledger of 20,000 subjects, the mean of three interleaved passes (each the median of 5 reps), the parent c898d982e vs this branch. ex:pa holds only xsd:string values; ex:pb the same text, nine in ten tagged @en/@fr; ex:n an integer control; ex:dt only xsd:dateTime values; ex:mdt the same instants with one in ten as a plain string.

query before after ratio rows before → after
pa: FILTER(?o = "v7") 21,992,197 331,936 0.015 20 → 20
pa: FILTER(?o >= "v1" && ?o < "v2") 25,984,717 24,002,836 0.924 2,220 → 2,220
pa: FILTER(?o < "v5") 31,191,276 30,252,233 0.970 8,900 → 8,900
pb: FILTER(?o = "v7") 22,183,104 274,607 0.012 20 → 0
pb: FILTER(?o >= "v1" && ?o < "v2") 26,074,579 2,757,547 0.106 2,220 → 220
pb: FILTER(?o < "v5") 30,995,408 3,343,697 0.108 8,900 → 900
n: FILTER(?o > 500 && ?o < 600) 11,021,450 10,857,221 0.985 1,980 → 1,980
n: FILTER(?o = 7) 9,624,212 9,387,690 0.975 20 → 20
dt: FILTER(?o < "2026-06-01T00:00:00Z") 33,151,859 27,885,147 0.841 10,080 → 10,080
dt: FILTER(?o < "2026-06-01T00:00:00Z"^^xsd:dateTime) 27,415,974 27,173,173 0.991 10,080 → 10,080
mdt: FILTER(?o < "2026-06-01T00:00:00Z"^^xsd:dateTime) 25,574,802 29,173,183 1.141 (accepted: the rows it was missing) 9,072 → 10,080
dt: FILTER(?o = "2026-03-05T10:00:00Z") 27,566,837 273,954 0.010 3 → 0
evaluated: FILTER(?o = "v7" || ?o = "v8") 287,823,307 288,021,286 1.001 40 → 40
evaluated: FILTER(?o < "2026-06-01T00:00:00Z" || false) 126,573,492 127,020,158 1.004 10,080 → 10,080

The equalities used to decode every value of the predicate, and now they seek the one string id, as ?s :p "a" does. The tagged-heavy ranges drop with the values the xsd:string slice seek no longer reads, and their rows change, which is the fix. The plain-string range over dateTime values is 16% cheaper: the bound string used to be parsed again for every row, and now it's parsed once per temporal kind (ObjectBounds::prepare), through the same reading temporal::cmp_with_lexical uses. The extra xsd:string seek beside a typed-date range costs nothing measurable on a property with no strings (0.991).

The one that's up is the mixed property, by 14.1%, and that's accepted as the cost of the 1,008 plain-string rows it now correctly returns and used to drop (about 3% per row, mostly decoding the strings). The evaluated temporal comparison is +0.4%, about the run-to-run spread (0.4%); what it pays for is the plain-string check the evaluator now makes before reading a string as a temporal.

Along the way, the first cut of the term check cost a numeric range scan about 2% in release, because the generic bound comparison stopped inlining under fat LTO. It's force-inlined now (the numeric rows above). An early version of the parse-once change boxed the parsed lexical on every evaluated comparison (+6.7% on the evaluated temporal shape); cmp_with_lexical parses onto the stack again, and a test pins that it and the parse-once path read every lexical alike.


STRDT and typed literals build their literal for any datatype IRI

A BIND of STRDT(…, <iri>), of a SPARQL typed literal like "a"^^<http://nowhere.example/T>, or of JSON-LD str-dt, failed the whole query with "Unknown datatype IRI" whenever the datatype's namespace wasn't registered on the ledger. SPARQL 1.1 §17.4.2.9 builds the literal from any IRI, and a SPARQL INSERT DATA (or a JSON-LD insert with an absolute @type) of the same literal already succeeds and registers the namespace, so the error wasn't protecting anything a write didn't already allow. The typed-literal case is new with this branch: it now lowers as STRDT (above), so it reached the same error, where main silently bound the plain "a". The strict check came in as an example in a utility's doc comment rather than as a documented requirement, and #1765 records the spec reading.

ComparableValue::to_binding resolved the datatype with the strict encoder, which returns nothing for an unregistered namespace. Triple-pattern constraints and VALUES rows already used the non-strict form since #1746: a registered namespace gives its Sid, and any other IRI the EMPTY-namespace full-IRI Sid, which matches nothing stored. That rule is now one function, IriEncoder::encode_datatype (fluree-db-query/src/parse/encode.rs), used by SPARQL lowering, to_binding and DATATYPE(). DATATYPE(STRDT(..)) used to return an IRI where DATATYPE(?bound) on the same value returned a Sid. Grouping already counted those as one, but a join on the two found nothing, and the output printed them two ways (nw:T and the full IRI); they're one term now.

The JSON-LD side needed one more piece. A JSON-LD insert runs @type through the strict compact-IRI guard, so {"@value": "x", "@type": "bad:datatype"} is refused as a compact IRI whose prefix the @context doesn't define, and str-dt has to follow the same rule or it becomes a looser second path to the same store. (str-dt ?v "xsd:integer") with no xsd in the context is the slip that makes this matter: main refused it by accident, as an unknown namespace, and without the guard it would have built a literal typed with the IRI xsd:integer, which an update would then persist under a new xsd: namespace. A constant str-dt datatype is now expanded the way an insert's @type is (expand_str_dt_datatype in parse/where_clause.rs): through the @context, under the same guard, at parse time. A datatype computed at run time (a variable, IRI()) is already an IRI. SPARQL keeps taking any absolute IRI in angle brackets, as its INSERT DATA does.

An update that stores such a literal goes through the flake generator's canonicalization (#2009), which re-encodes an EMPTY-namespace datatype through the transaction's registry, so the stored flake carries the namespace code the write registers. That's the same Sid a direct insert of the literal gets, after a reload, an index build and a reindex at the same t. A DELETE of a literal no fact can carry retracts nothing and registers nothing. A datatype name with no scheme ("T") splits to the empty prefix on every path, so a JSON-LD insert, INSERT DATA, str-dt and STRDT all store it as the same EMPTY-namespace term.

IRI() in an update, and JSON-LD iri constants

The same gap had an IRI side. An update whose template took IRI("http://unseen.example/x"), UUID() or JSON-LD (iri ..) from a BIND, in a namespace the ledger hadn't registered, failed with "Raw IRI from graph source cannot be used as object for flake generation" (or subject, or predicate), while INSERT DATA of the same IRI succeeds and registers the namespace. A query already returned the IRI, as §17.4.2.8 says it should. Flake generation now gives such a binding the encoder's fallback Sid(EMPTY, iri), the form a WHERE constant in an unseen namespace already has (bound_iri_sid in fluree-db-transact/src/generate/flakes.rs). An assertion canonicalizes it under the namespace the write registers (#2009), so the update stores the term INSERT DATA stores, and a retraction keeps it, so a DELETE of an IRI nothing holds retracts nothing and registers nothing. A _: label (BNODE() output) or a string that isn't an absolute IRI still names nothing to write, and is refused as before.

That made JSON-LD's iri the same kind of looser second path that str-dt was. (iri "ex:x") never expanded through the @context, so with only the flake fix an update would have stored the IRI ex:x under a new ex: namespace instead of the term {"@id": "ex:x"} stores. A constant iri argument is now expanded the way an insert's @id is (expand_iri_argument in parse/where_clause.rs): through the @context, under the same strict compact-IRI guard, so "bad:thing" with no bad prefix is the insert's "Unresolved compact IRI" error and opts.strictCompactIri: false takes it verbatim. An argument computed at run time is taken as it is. This applies in queries too, which is why it's its own commit: ["iri", "ex:knows"] used to match nothing, and filter_iri_operand_forms_across_spellings pinned that; it now matches as the full IRI does. While in there, array-form filters turned out to skip this walk entirely, so a constant str-dt datatype in an array-form filter wasn't expanded either; both arguments now expand in every expression form, and the array form's bare atoms stay strings.

Behavior changes

Surface Expression Before After
SPARQL BIND(STRDT(?v, <http://nowhere.example/T>) AS ?x), namespace unregistered query fails: "Unknown datatype IRI" the literal; DATATYPE(?x) is the IRI
SPARQL / JSON-LD STRDT(?v, "not an iri"), STRDT(?v, 5), (str-dt ?v "not an iri") a literal typed with the string (an update stored it); for a number, a plain string a type error: unbound in a query, and an update fails; a name with no scheme (<T>, "T") is still one term, as on every write path
SPARQL BIND("a"^^<http://nowhere.example/T> AS ?x) plain "a" on main; the error above at this branch's parent the literal
SPARQL STRDT("a", <bad:datatype>), "a"^^<bad:datatype> query fails the literal (an absolute IRI, as INSERT DATA accepts)
SPARQL / JSON-LD INSERT { ?s ex:p ?x } WHERE { … BIND(STRDT(…) AS ?x) } and the JSON-LD str-dt update update refused stored under the namespace the write registers; the same term as a direct insert
SPARQL / JSON-LD DATATYPE(STRDT(?v, <T>)) against DATATYPE(?x) with ?x the same literal (from VALUES, or bound), joined or printed no join rows (VALUES on main; a BIND failed); the two printed differently one term: the join matches, and both print alike
JSON-LD (str-dt ?v "urn:example:dt"), "http://…", or ?dt bound to an IRI query fails the literal
JSON-LD (str-dt ?v "ex:T") with ex in the @context query fails: "Unknown datatype IRI: ex:T" the literal, typed with the expanded IRI
JSON-LD (str-dt ?v "bad:datatype"), (str-dt ?v "xsd:integer") with no such prefix "Unknown datatype IRI" "Unresolved compact IRI …", the error the same @type gives in an insert
any a typed literal in FILTER, IN, sameTerm matches nothing stored unchanged
SPARQL / JSON-LD INSERT { … ?x } WHERE { BIND(IRI("http://unseen.example/x") AS ?x) }, UUID(), (iri ..), as subject, predicate or object update refused: "Raw IRI from graph source …" stored under the namespace the write registers; the same term as INSERT DATA of it
SPARQL / JSON-LD a DELETE template with such an IRI — retracts nothing, registers nothing
JSON-LD (iri "ex:x") with ex in the @context, query or update the IRI ex:x (a query matched nothing; an update was refused) the expanded IRI
JSON-LD (iri "bad:thing") with no such prefix the IRI bad:thing in a query; refused in an update "Unresolved compact IRI 'bad:thing'", the error the insert {"@id": "bad:thing"} gives (strictCompactIri: false takes it verbatim)
JSON-LD ["str-dt", ?v, "ex:T"] in an array-form filter not expanded expanded, as in the s-expression form
Cypher — no STRDT or typed-literal constructor unchanged

Release note: STRDT, a SPARQL typed literal and JSON-LD str-dt now build their literal for any datatype IRI, including one in a namespace the ledger hasn't seen, where they used to fail the query with "Unknown datatype IRI". In JSON-LD, a str-dt datatype written as a string is expanded through the @context and checked by the same compact-IRI guard as an insert's @type: "ex:T" with ex defined is the expanded IRI, and "xsd:integer" with no xsd prefix is refused with "Unresolved compact IRI" (set opts.strictCompactIri: false to take it verbatim, as an insert does). An update now writes an IRI that IRI(), UUID() or JSON-LD iri builds in a namespace the ledger hasn't seen, where it used to fail with "Raw IRI from graph source cannot be used as …". A constant JSON-LD iri argument is expanded through the @context like an @id: ["iri", "ex:knows"] with ex defined is the full IRI (it used to match nothing), and an undefined prefix is refused with "Unresolved compact IRI" unless strictCompactIri is false. A datatype that can't be an IRI (a number, or a string holding a space or another character no IRI holds) is now a type error, where it used to build a literal typed with that string.

aaj3f added 30 commits October 19, 2026 13:45
`<`, `<=`, `>` and `>=` read a string as a value of a temporal type to
order it against a typed date, time or dateTime. The evaluator applied that
to any string-backed literal, so `"2026-01-01"@en` and
`"2026-01-01"^^ex:T` ordered against `"2026-02-01"^^xsd:date` and passed,
though a tagged or custom-typed literal is a term of its own type. Pushed
into the scan, the same filter kept them on novelty and dropped them on the
index, which seeks only the date slice.

Only a plain string (a simple literal or `xsd:string`) is read as a
temporal now, in the evaluator and in the scan's object bounds alike;
both still order through `temporal::cmp_with_lexical`.
A range against a typed temporal (`FILTER(?o < "2026-02-01"^^xsd:date)`)
seeks the temporal slice of the predicate on the index, but `<` also
orders a plain `xsd:string` row against it by reading the string as a date,
so a stored "2026-01-01" passed the filter on novelty and was never read on
the index. The scan now seeks the `xsd:string` slice beside the temporal
one, without the temporal key range, which does not order string ids. An
`=` never equates the two and keeps the single temporal seek.
The evaluator compared a stored `@fulltext` value as a plain string on the
index, where it stays late-materialized, and as `f:fullText` on novelty, so
`FILTER(?o = "Hello World" || false)` matched it on one lane and not the
other. It now carries `f:fullText` on both. A JSON value reached the
evaluator as a plain string on both lanes, so `FILTER(?j = '{"a":1}')`
matched it when evaluated and not when pushed into the scan; it is an
`rdf:JSON` literal now, and a BIND of it keeps that datatype instead of
becoming an `xsd:string`.

Both are text to the string builtins, which on novelty refused an
`@fulltext` value (CONTAINS, STRSTARTS, REGEX; SUBSTR failed the query).
The builtins now take their arguments through one accept-set,
`reads_as_text` (a simple literal, `xsd:string`, a language tag,
`@fulltext` and `rdf:JSON`), where `string_arg`, STRBEFORE/STRAFTER and
CONCAT each kept a copy; CONCAT's had drifted and refused an explicit
`xsd:string`.
A typed date or dateTime bound against plain, tagged and custom-typed
strings; `=` and `<` on `@fulltext` and JSON values; seven string builtins
on `@fulltext` and three on JSON, plus BIND keeping `rdf:JSON`; and the
integer `=` seek over two-row leaflets, with a double `7.0` in the index and
in novelty over an all-integer index.
On novelty a builtin that refuses its argument fails the whole query, which
panicked the test at the first such row and hid the rest.
A counting lane projects no column, yet the merge recorded a run per
emitted row to gather from. With an empty projection it now counts the
rows it emits and returns batches that are a row count alone. The
randomized test checks the count against a full merge of the same
members over leaflets cut differently.
…mpare as themselves

Only a plain string is read as a temporal by `<` and `>`, in both
directions; an @fulltext or JSON value is excluded by `=` and `<`
against a string while the string functions read it as text.
Lane C on T's fixture: in every scope, state and surface the answer is the
hand-written one with fast paths on and off, and the cache's route is the
one design §5 gives it. The union site takes a default graph of several
graphs and of none, the one-graph site takes one graph, and novelty or a
read below the index declines the union with its reason.
Under the release profile (fat LTO, one codegen unit) the generic bound
check stayed a call per bound, and a numeric range scan cost ~2% more
instructions than before the term-aware check. Forced inline, it is back
below where it started (release A/B against a9336a9).
…e move

Where two inputs' heads are the same row, the first emits it and the
second steps past its copy, instead of taking a turn of its own to drop
it as a repeat. Release, instructions retired per input row, no output
column: two identical members 117 -> 100, half overlap 59 -> 50.
…okup of its own key"

This reverts commit 36dfa27. #2119 on main makes the same change (a
persisted subject's Sid without a reverse lookup); this branch takes main's
version when the parent merges main.
…l graphs

`?s <p> ?o GROUP BY ?o` with `COUNT(?s)`, top k, fell back to the general
plan over a default graph of several graphs. It now reads the predicate's
POST range through the merged cursor across the members: each fact once, in
object order, so a group's run is the distinct subjects holding that object
in some member, which is what the general plan's dedup on `(?s, ?o)` counts.
List rows and arena-typed objects decline, with their reason, at the lane's
own site, `group_by_object_count_topk_union`. IRI groups are emitted decoded,
since no graph view decodes an encoded subject downstream of a union.

The bound-object count reads its dedup identity from one function,
`union_count_key` (today the subject: the general plan's union dedup keys
on the emitted row, which is `?s` alone). Its merge checks each source's key
order as it reads and declines only where a list puts a key out of order. A
single member's list rows now go through the merge instead of declining.
A range with a plain-string bound over temporal rows
(`FILTER(?at < "2026-06-01T00:00:00Z")` over `xsd:dateTime`) parsed the
bound string again for every row it compared. `temporal::cmp_with_lexical`
is now built on `temporal::lexical_as_kind_of`, the one reading of a
lexical as a temporal kind, and `ObjectBounds::prepare` gives the scan and
the flake lanes a `PreparedBounds` that keeps that reading per temporal
kind, so the bound is parsed on the kind's first row. It answers exactly as
the bounds do (pinned by a unit test), and the comparison is still the one
`cmp_with_lexical` makes.
A merge over several graphs reads every member's branch for one order.
A member with none declines the lane; the fallback is stamped as
fallback:no_branch, after the shared reasons.
…its code

A direct insert of a literal whose datatype is in a namespace the ledger
has never registered stores it under the code the write gives that
namespace, never under the EMPTY-namespace full-IRI form a query builds
for an unseen datatype. A lookup by the literal finds it before and after
an index build, after a reindex at the same t, and after a reload. A
DELETE of a literal no fact can carry retracts nothing and registers no
namespace.

The JSON-LD insert covers an http and a urn datatype; SPARQL INSERT DATA
covers `<bad:datatype>`, an absolute IRI SPARQL accepts and a JSON-LD
@type refuses as an unexpanded compact IRI.

File-backed, without background indexing, with explicit builds. The
commit walk checks the stored form directly: no committed flake has an
EMPTY-namespace datatype.
…nothing

The closing edge's pair count cost about 1% of a one-graph triangle over
the membership test it replaced. A miss now costs the one binary search
the test cost, and a hit steps outward over the rare repeats. The
bound-bound edge no longer builds a candidate list either: it only
multiplies the assignment by the rows it holds, so the join recurses that
many times.
Building `cmp_with_lexical` on `lexical_as_kind_of` boxed the parsed
lexical on every call, which the FILTER evaluator makes once per row:
`FILTER(?at < "2026-06-01T00:00:00Z" || false)` over `xsd:dateTime` cost
6.7% more instructions (release). `cmp_with_lexical` parses onto the stack
again, as before; `lexical_as_kind_of` stays for the scan's parse-once
bounds, and a test pins that the two order every value against a lexical
alike.
`COUNT(?s)` over `?s <p> 1.5`, or over a big integer, fell back to the
general plan on one graph as on several: only a bare integer or double was
sliced into the (o_type, o_key) seeks the counts read. One function now
slices every bare number, `untyped_numeric_slices`: an integer slice where
the value is an exact `i64`, a float slice where an `f64` holds it exactly
(as `numeric_cmp` compares), and the NumBig arena's handles for it, decimal
aliases and, past `i64`, the integer. Integers and doubles slice as before.

Both counts read it. Over several graphs each member translates the value
into its own arena, and the count still dedups on the subject, so a handle
is never compared across members. A typed decimal stays out: the count
detector takes no datatype-constrained object.
…p path

Charging the tracker in the count iterators' refills cost the count plan
about 1.1% more instructions per query, tracking off or on. The refill is
inlined into next_group, and the charge kept the tracker live across it,
so every group paid for one more callee-saved register (a push and a pop
per call, two instructions a row on a one-row-per-subject star).

The refills of the five fast_path_common iterators and the count plans'
subject-object iterator are now #[inline(never)], and charge_leaflet
inlines only the enabled check, with the charge itself #[cold]. The chain
fold's seek cursor keeps its refill inline: out of line it measured
slower there.

On an EC2 c7i.8xlarge, fat-LTO release builds, 1M subjects, rayon on one
thread, instructions per query against main: count plan -1.9%, MINUS
-4.1%, EXISTS -4.1%, OPTIONAL -0.9%, chain fold, whole-graph aggregate,
geo and the property path's id lane flat (within 0.6%), tracking off and
on alike.
Brings in main through fe5febc (#2316 and the deterministic-order fixes).
One conflict, in grp_query.rs's module list: this branch's
it_union_fact_identity and main's it_unordered_output_order are both kept.
…e it flips it

Its two tests turn the process-global kill switch on and off without the
write side of support::FAST_PATH_SWITCH, so under cargo test a routing
test in grp_query that holds the read side could run inside the window
and see fallback:kill_switch (exists_semijoin_cache_over_one_graph_and_a_union
failed so once in seven runs). They hold the write side now, as the binary's
other togglers do.
Brings in main through 4adc62e. Four files conflicted:

- graph.rs: main streams a GRAPH block's inner subplan instead of buffering
  it. The branch's scope crossing (ScopeCrossing, whose enter and leave are
  fallible) and its fallible graph-IRI extraction now live in main's
  streaming path: the crossing is built when the subplan opens and kept in
  InnerStream, and next_streamed propagates a decode failure instead of
  dropping the row.
- cyclic_bgp.rs: main decodes every binding the cyclic join emits under
  eager materialization, and its cascade probes plan for an eager caller
  (LaneOutput::DecodesForEager). That flag now lives in the branch's Emit,
  set in open_reads for the one-graph and the union reads alike, with the
  emit view built from the first member read whenever the lane decodes.
- fast_path_common.rs, count_plan_exec.rs:
  predicate_unsafe_for_cross_predicate_o_key_join takes main's replay_to and
  this branch's tracker.
Brings in main through f42ea37, with #2374, which moves the one-graph
bound-object probe from OPST to POST, hands its matches over a run of
subjects at a time and builds rows from them on demand. join.rs and
optional.rs conflicted:

- The one-graph flush, the walk and the row builder (next_object_probe_step)
  are main's.
- The union object probe keeps its member walk, which hands over each
  match's list position for the union's fact identity, as
  for_each_object_probe_match_by_fact. Its matches, one per fact of the union,
  now land in main's per-object subject lists, so the union and the one graph
  share main's row building and charging. It probes ref objects; a left row
  on a string object, which main's lane now keys too, goes to the per-row
  scan, which reads the union.
- optional.rs takes main's call of the POST walk.
Main's bound-object lane now keys string terms as well as refs. Over a
union it probes refs only and leaves a row on a string object to the
per-row scan: this pins that answer, before and after indexing, with fast
paths on and off. Sending the string keys to the union's ref walk answers
nothing on the indexed fast-path run.
The batched probes read the index through LeafScan::load_leaflet: the
subject probe and the subject star, the bound-object walk (POST, #2374's
design) and the union's by-fact walk, the semijoin's index walk and
scan_matches. They charged their matched rows, but not the leaflets they
read, where the scan's cursor charges each one. load_leaflet now takes the
query's tracker and charges one index touch per leaflet (charge_leaflet: an
inlined enabled check, the charge itself out of line), so a probe that
loads a leaflet is charged by construction.

it_fast_path_fuel gains a batched subject probe and a bound-object probe:
with the charge removed, the 3-row leaflets cost what the left scan's
leaflets alone add (a gap of about 1, against 1.5 wanted).
@aaj3f

aaj3f commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Evidence for the description, moved here to keep it under GitHub's size limit: the red/green record, the merge log, and the per-area test lists.

Shown red without their fix

Each mutation was committed first, made after cargo fmt, checked against its needle, and restored. The per-lane rows ran at each lane's own head; the rest at the head of the work they pin.

Mutation Result
a union lane never takes Union (grouped count, cyclic join, EXISTS cache, per-predicate count) that lane's union MustFire cases fail; answers stay right
a union lane's duplicate removal dropped, or main's one-member read put back (cyclic join, EXISTS cache, object count, per-predicate count) the shared-fact cases fail on answers
the dedup keyed without normalization 3 tests fail
scans tag arena literals with no graph the query fails closed with an error
decoding ignores the literal's graph wrong answers
the fact set compares kept terms by index, or drops the × width key offset its unit tests fail
the union's fact key drops the list position every list test fails on answers, SPARQL included: a repeated member comes back once
the per-predicate count ignores the RDF view the RDF-view case fails: the lane answers the members, not the cells, and names no decline
the union probe stands down as if every request read lists as RDF 56 MustFire failures, both surfaces
the merge's union guard removed from the flush 3 lane tests fail, every union-probe MustFire "proceeded but never flushed"; answers stay right
a multi-op request's ops carry only their own lowered namespaces namespace conflict: code 14 …
the cross-ledger facts left un-re-coded 6 checks fail: a shared subject twice, COUNT(*) 2, both surfaces, novelty and indexed
the per-predicate union count's charge removed; the grouped count's removed; a budget error turned back into a decline the budget test passes the count (Ok); fails only after every group folds (used_bytes 1,024,000); names fallback:gate_declined
the pushdown merge's temporal check off; the planner's off the two-FILTER rows fail (8); the && rows fail (4)
STRDT's datatype check removed STRDT(?t, "not an iri") is bound
the search decoders back on one_graph_view() both unit tests: the undecodable target is skipped
the plan's scope default back to One its unit test
the tagged range read ignores the tag the range read returns 60 rows, not 6
the decoder cache ignores a changed store or dictionary novelty its unit test: a stale decoder after the store is dropped
STRDT of constants never folds 65 checks: nothing pushes, no typed_string_bound_seek
a typed bound's datatype ignored on flakes; on index rows the novelty runs match the text under every datatype (t, u, plain, en, …); the join's batched probe and the property-join star do the same on the index
the pushdown merges a plain and a typed = the two-filter case answers t
the join's probes left unresolved the VALUES join and the star answer nothing on the index
the scan's range fallback untracked; property paths' edge reads untracked ~100 leaflets cost what 1 does (1.6 fuel each); 300 hops cost 1.6 fuel
the fast paths' and the id lane's reads untracked (the commit's sources reverted) all nine lane families: 3-row and default leaflets cost the same; 300 hops cost 1.3 fuel, under the 4.0 floor
one lane's read error folded back into Internal under max-fuel 1.2 the label-regex lane answers 500 Internal error: binary cursor: Fuel limit exceeded
the group-by-object count's load uncharged its fuel gap is 0, and it runs to 1.0 fuel under a 1.2 limit
the union object walk's fact dedup dropped, with strings walked a string alias both graphs hold answers twice
LeafScan::load_leaflet uncharged the subject probe and the bound-object probe cost only the left scan's leaflets more on 3-row leaflets (a gap of 0.99, against 1.5 wanted)

The original follow-up's red/green (each half's sources set back to main's) and the string-filter and #1765 sections' own are unchanged.

The list rows were re-pinned to #2217's values reading after main brought it in, and those three mutations re-run against them; the rows after them are the review round's, each run locally at its commit (logs kept).

Merged with main

Main is merged seven times, each with a merge commit at the top: 42bb9646c, then 807902bbf (9169ef4b8), 149d02d81 (849e158ef), 467f0da4d (f033bc823), fe5febcb9 (05841305f), 4adc62e89 (06fc82468) and f42ea3784 (ae72f55f6).

  • 42bb9646c merged without conflicts; fix: a retraction and an assertion of one fact at one t resolve the same way everywhere #2153's same-t rule reaches the lanes through the shared overlay resolvers, which every lane uses.
  • 807902bbf brought fix(query): a subject probe over a graph with no branch finds nothing #2187 and fix(lists): SPARQL reads list members as values, CONSTRUCT writes lists, deleting a value takes every entry #2217. fix(query): a subject probe over a graph with no branch finds nothing #2187 conflicted in two hunks of join.rs, the batched subject and object probes: the lane's split into a union source and a one-graph source stays, and the one-graph side takes fix(query): a subject probe over a graph with no branch finds nothing #2187's branch_or_none. be4c6ae4a then puts the union members through the same lookups. fix(lists): SPARQL reads list members as values, CONSTRUCT writes lists, deleting a value takes every entry #2217's list-member operator (list_entries.rs) merged clean but didn't compile here: it decoded its rows through graph_view(), which this branch doesn't offer under a union. It now decodes through the scope's terms (term_view()), which work on one graph and on a union alike, and an encoded value they can't decode is an error, not a value compared as encoded (the fail-closed rule from Late decoding for a default graph of several graphs of one ledger #2015, above).
  • 149d02d81 merged without conflicts.
  • 467f0da4d brought feat: DROP takes a graph and its history out of the ledger #2251 (graph drop), Batched join lanes run under reasoning and decode what they emit #2271 (reasoning batched probes), fix(query): filters on the index lane answer as they do over novelty #2226 and the rest. It conflicted in join.rs (the batched gate, the reset in open, and both probes' object bindings), cyclic_bgp.rs (the subject probe plan) and the W3C register. The batched gate takes main's deferred overlay plan and eager rule and keeps this branch's one-graph scope test; the one-graph probes take main's code as is; the cascade and the union probes' per-member plans take LaneOutput::Encoded; main's new open_per_row_scan takes the scope's TermView; main greened the optional-complex cluster and this branch open-eq-05/06, so both leave the register. One seam merged clean and would have read green (the flush reroute, under "From review" above), and a test helper follows main's rename of graph_id_for_iri to assigned_graph_id.
  • fe5febcb9 conflicted only in grp_query.rs's module list (this branch's it_union_fact_identity and main's it_unordered_output_order, both kept). Main's other query changes fix iteration order and add graph-source work, and read the index nowhere new, so every fast path still charges its reads. One seam showed under cargo test: main's it_filter_pushdown_operators flips the kill switch in a binary where this branch's routing tests hold the read side of support::FAST_PATH_SWITCH, without the write side, so a routing test could run inside its window (once in seven runs). It holds the write side now (9c6a5ba50).
  • 4adc62e89 conflicted in graph.rs, cyclic_bgp.rs, fast_path_common.rs and count_plan_exec.rs. Main now streams a GRAPH block's inner subplan instead of buffering it: this branch's scope crossing, whose decode can fail, is built when the subplan opens and kept with the stream, and a decode that fails fails the query rather than dropping the row, in the per-row and the batched paths. Main's cyclic join decodes every binding it emits for an eager caller: that rides in this branch's emit state, for the one-graph and the union reads alike, and the cascade's probes plan for it (DecodesForEager, above). predicate_unsafe_for_cross_predicate_o_key_join takes main's replay_to and this branch's tracker; main's new parameter reads only leaflet directories, so there is nothing more to charge.
  • f42ea3784 brought perf(query): probe bound objects in the predicate's POST partition #2374, which moves the one-graph bound-object probe from OPST to POST, hands its matches over a run of subjects at a time and builds rows from them on demand; join.rs and optional.rs conflicted. The one-graph probe is main's as written. The union object probe keeps its member walk, which reads each match's list position for the union's fact identity, and its matches, one per fact of the union, now land in main's per-object lists, so the union shares main's row building and charging. Main's lane now keys string terms too, and the union's walk takes them as it takes refs (09da10e44): the members share one store and its dictionary novelty, so a string's key is one key in every member. Sending those rows to the per-row scan instead, as the merge first did, cost a union string join 2.6% (a_string_object_joins_across_a_union_once_per_fact, f4e9ef949, fails with the walk's fact dedup dropped).

An open PR that will conflict, to merge main again after it lands: #2201 (the arena-identity sites in binding.rs, group_aggregate.rs, materializer.rs, object_binding.rs, sort.rs, cyclic_bgp.rs, binary_index_store.rs and the SQL lane — this branch carries the graph in the handle, and #2201's GROUP BY and join additions come in on top). (Still open on 11-13; #2202, which would have conflicted in one hunk of the binary scan, was closed in favor of #2217.)


Tests: FILTER string comparisons keep their term semantics when pushed

it_string_filter_pushdown (own binary: it toggles the fast-path kill switch and captures routing stamps). Each pushed shape must give the expected answer as written, with the plan carrying object-bounds; with fast paths disabled; and through three evaluated oracles that don't share its plan ((F) && BOUND(?o), (F) || false, and BIND((F) AS ?k) FILTER(?k)). The table covers xsd:string, tagged and custom-typed strings, @fulltext, JSON, a boolean, an IRI, a number, and typed dateTime, date and time values, against plain-string and typed-temporal bounds, including a keyset pager's timestamp tiebreak. Seven string builtins are pinned on @fulltext and three on JSON, plus BIND keeping rdf:JSON, on both lanes. Each fix was reverted on its own to show its rows red. A nested-loop join now reports pushed bounds in explain the way a scan does, which is how the pager case shows its pushdown. That runs on a novelty-only ledger, on the index (string_bound_seek must proceed), and with novelty over the index, including a string the index has never seen. It covers SPARQL, JSON-LD and Cypher. The two constant-object leniencies above are pinned unchanged, and so is the unorderable-merge case. Unit tests cover the term-aware matching, the coercion flag, the = provenance through extraction and merging, and the slice computation. eq-4 passes and has left the skip register. it_typed_filter_pushdown (own binary) does the same for typed =: hand-written answers in SPARQL and JSON-LD over novelty, the index and novelty over the index (a datatype and a string only novelty holds included), through the scan, the join's batched probe, a property-join star and two ledgers coding the datatype's namespace differently; typed_string_bound_seek must proceed where the bound is pushed, and must not for a numeric STRDT, ||, two datatypes, or a plain and a typed =. it_fuel_floor::range_path_reads_charge_the_leaflets_they_touch pins the range path's fuel. it_fast_path_fuel (own binary) runs nine lane families (a count plan, a class-anchored Cypher aggregate, a constant-star top-k, a group-by-object top-k, a string-prefix count over an imported ledger, label regex, a one-or-more path count, the path's id lane and geo search) over the same facts in 3-row and default leaflets: each must give its hand-written answer, its site must proceed, and the 3-row leaflets must cost the fuel their leaflets explain (the id lane, a leaflet a hop). It also runs a batched subject probe and a bound-object probe, whose 3-row leaflets must cost more than their left scan's leaflets alone add. A second test puts each SPARQL lane under max-fuel 1.2 and expects a 400 fuel error.

Tests: STRDT and typed literals build their literal for any datatype IRI

  • it_literal_identity::an_unseen_datatype_literal_is_stored_under_its_namespace_code, file-backed with explicit builds:

    • three updates (SPARQL STRDT, a SPARQL typed literal, JSON-LD str-dt) and SPARQL STRDT on <bad:datatype>, each against its direct-insert twin;
    • lookups by the literal and COUNT(DISTINCT) per predicate, which find one term for both writes after a reload, after an index build, and after Fluree::reindex at the same t;
    • a walk over every committed flake, which finds no EMPTY-namespace datatype.

    The direct-insert half lands first, as a commit of its own that passes on the parent.

  • unseen_datatype_literal_from_an_expression_is_a_term, SPARQL and JSON-LD, unindexed and indexed: STRDT, a typed BIND and STRDT over a stored value. The literal is sameTerm and = to itself and matches nothing stored. DATATYPE(?x) = <T> holds, and DATATYPE(STRDT(..)) and DATATYPE(?bound) join as one term and print one way in SPARQL and JSON-LD.
    JSON-LD's twin of the VALUES join, (datatype ?x) of a typed values literal against (datatype (strdt ..)) from a subquery, finds its row; on the parent it returns no rows.

  • it_query_datatype::datatype_values_join_plans_alike_for_registered_and_unseen_datatypes passes with and without the change. The VALUES join over DATATYPE() gets one physical plan for an unseen datatype and for xsd:token, and over xsd:token it finds its row, so the parent's empty answer comes from the two terms, not from a different plan.

  • a_datatype_name_with_no_scheme_is_one_term_on_every_write_path.

  • it_transact_update::sparql_update_writes_an_iri_in_an_unseen_namespace: IRI() as subject, predicate and object, and UUID(), each the term INSERT DATA stores; a DELETE of an unseen IRI, in an update that also inserts so it commits, registers no namespace. update_where_bind_iri_in_an_unseen_namespace is the JSON-LD twin, and keeps refusing "not an iri".

  • update_where_bind_iri_expands_through_the_context and it_query_jsonld::jsonld_bind_iri_expands_through_the_context: ex: expands, an absolute https IRI is itself, bad:thing is refused with the insert's error (in an update, alongside the insert itself), and strictCompactIri: false takes it verbatim; the query test also covers both arguments in an array-form filter.

  • multi_operation_request_failing_mid_request_leaves_no_trace now fails op 2 on a vector length the property can't take (a 422 by contract), since its old triggers, STRDT and then IRI() in an unseen namespace, are valid writes now.

  • it_query_jsonld: the bad:datatype error case now pins the guard's message; there's a new "xsd:integer" refusal, and a positive case for a urn IRI, an http IRI, a context prefix and a variable-bound IRI. it_transact_update: the error case pins the guard's message, and a positive update stores the same term as a direct insert of it.

  • The behavior change is one commit, so a revert puts back the old error and the tests that pinned it, and leaves the persistence test passing.

  • it_transact_update::str_dt_refuses_a_datatype_that_is_not_an_iri: SPARQL and JSON-LD, query (unbound) and update (refused), against a urn, IRI() and angle-bracket datatype that still work.

@aaj3f

aaj3f commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for such a careful pass, and for the #2271 heads-up, which saved me a confusing merge. Everything's in on the branch now:

  • The three must-fixes: the multi-op namespace conflict (8a41c82c6), main's branch_or_none in the one-graph probes (9169ef4b8, kept as-is through the new merge) and the union members (be4c6ae4a), and the cross-ledger dedup keying facts on the query's codes (bfded8dfc).
  • Every thread has a fix and a test that fails without it, the STRDT fold included: a typed = now pushes into the scan as its term (154b64e7d).
  • One more thing I fixed while in there, since it's the same class as your union-count budget note: a lot of index reads charged no fuel, where the scan's index lane charges every leaflet it reads. The range path (a view policy that touches the predicate, a dataset spanning ledgers, property paths' Sid lane, list entries, the RDF list view, shortest paths, search readability) is 5297e5c5f. Every fast path and the property path's id lane is 090d29cb0: their cursors and leaflet loads now charge the same index touch per leaflet, and raw loads go through two helpers that take the tracker, so a new lane can't quietly skip it. The join probes, which charged their matched rows but not the leaflets they read, charge those too now, in LeafScan::load_leaflet itself (e99940414). While in there I found about 50 of those reads folding their error into QueryError::Internal, so a fuel refusal inside a lane came back as a 500. They go through from_io now and come back as fuel errors. Fuel totals rise for those queries, and one near its limit can now be refused; it's under Behavior changes in the body. I was careful that it costs no speed: every lane charges the exact leaflets it reads, and on a box (fat-LTO builds, 1M subjects) every lane it touches costs what it did before the change, within 0.1%, tracking off and on alike. Getting there took one fix: the charge inside the count iterators' refill kept a register busy for every group, about 1% on the count plan, so those refills moved out of the per-group loop (d86a29734), which also leaves the count shapes 1–4% under main. Two lanes read a bit higher than main for an unrelated reason, LTO inlining that main flips by the same amount between commits that don't touch them; the bisect and the numbers are in the body.
  • Main is merged again (f033bc823, then 05841305f, 06fc82468 and ae72f55f6 for today's main, the last with perf(query): probe bound objects in the predicate's POST partition #2374's POST object probe, which the union probe now feeds), feat: DROP takes a graph and its history out of the ledger #2251, Batched join lanes run under reasoning and decode what they emit #2271 and fix(query): filters on the index lane answer as they do over novelty #2226 included. Per your note, the union probes' per-member plans take LaneOutput::Encoded: they emit encoded rows, and plan_union_probe declines eager materialization before it plans them, so DecodesForEager would have been a promise they don't keep. The cyclic cascade's subject probe took Encoded at f033bc823 too, since it emitted encoded bindings then. Main has since taught the cyclic join to decode for an eager caller and its probes to plan for one, and with 06fc82468 the branch's union reads decode the same way, so the cascade takes DecodesForEager, on one graph and over a union.
  • That merge had one seam that answered right and so read green: Batched join lanes run under reasoning and decode what they emit #2271's flush now hands a declined plan's rows to the per-row path, and the one-graph plan declines every union scope, so the union probe stamped proceed and then never ran. The merge keeps that check to the one-graph lane, and the lane suites now also require a batched flush span wherever the union probe must fire (b2aeb8e68), so the stamp can't vouch for a probe that didn't run.
  • The behavior changes you listed are in the body and its release note (JSON comparisons and truth value as type errors, a bound "…"^^rdf:JSON refused on insert, constant iri arguments under the compact-IRI guard), along with the fix(lists): SPARQL reads list members as values, CONSTRUCT writes lists, deleting a value takes every entry #2217 adaptation and two API notes for embedders (RangeMatch::lang, and PlanningContext::current() planning for no index until it's given its scope).

The full gate set is green on Linux at the head (09da10e44), numbers in the body: the lane routing tests 269 of 269, cargo nextest run --workspace --all-features 16,305 of 16,305, clippy, fmt, the wasm32 checks and probe, docs and the W3C suite all clean.

The description is updated for all of this. It was over GitHub's size limit, so the red/green record, the merge log and the per-area test lists are in a separate comment.

Since #2374 the bound-object lane keys string terms, and over a union the
probe sent a left row on a string object to the per-row scan after
keying it, which cost a union string join 2.6% more instructions than
before that merge (790M to 811M a query at 7,500 rows). The members share
one store and its dictionary novelty, so a string's key is one key in
every member: the union's walk now takes the object type and walks any
type the lane keys, keeping one match per fact as it does for refs.

a_string_object_joins_across_a_union_once_per_fact now runs through the
walk: with its fact dedup dropped, ex:b, whose alias both graphs hold,
answers twice on the indexed fast-path run.
@aaj3f
aaj3f merged commit 88c3cf1 into main Nov 17, 2026
19 checks passed
@aaj3f
aaj3f deleted the fix/lanes-and-typed-strings branch November 17, 2026 16:42
bplatz added a commit that referenced this pull request Nov 18, 2026
it_union_annotation_chain came from main (#2214) with cases that query
annotated edges across two ledgers. They pass on main, where an
annotation is plain triples on a reifier, and answer nothing on next,
where it is a triple-term link the chain reads from one store's
dictionary. The same-ledger cases still run; the two-ledger ones are off
behind TWO_LEDGERS until #2444 fixes the chain across ledgers.
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 performance Performance improvement (release notes: Performance)

Projects

None yet

2 participants