Skip to content

Scopes of several graphs: a one-graph witness type, and the readers that still read one graph #2075

Open

Description

@aaj3f

#2010 routes every single-graph lane through one predicate (reads_exactly_one_graph) and fixes the sites that read one member's index in a scope of several graphs (the union default graph, FROM naming several of a ledger's graphs, FROM NAMED alone, a dataset spanning ledgers). What it doesn't do is make that mistake hard to write again, and a few readers still read one graph, as on main. The class, as #2010 puts it: a site that runs in every scope used an accessor that is None across several graphs and read None as nothing to do (fulltext(), BM25, S2), or read binary_g_id directly.

  • A one-graph witness in place of graph_view() and the raw binary_g_id. ExecutionContext::one_graph() -> Option<OneGraph<'_>>, built only by reads_exactly_one_graph(); graph_view() and binary_g_id move behind it (OneGraph::view(), OneGraph::g_id()), and the field becomes private to context.rs. Code that runs in every scope is then left with decode_view(), and a single-graph lane has to name one_graph(), which is its gate. Member contexts and GRAPH scopes read one graph, so their scans don't change. The legitimate any-scope readers of the id (the thread-local predicate cache key in eval/helpers.rs, the vector arena slice in eval/vector.rs) get named accessors. fix(query): compare terms by what they are, not how they're encoded #2010's estimate is roughly 600–1,000 changed lines, mostly mechanical; the option is taken once at open, so the perf check is single-graph instruction parity. (An index-only graph_view() looks like the obvious version but isn't: every remaining use decodes, legitimately, on one graph, and sending them all to decode_view() would have the arena crossing inspect every binding for a handle that can't be there.)
  • fulltext() scores every document against the scope's graph's arena statistics (the default graph's under the union). Scoring each against its own graph's would be better than what main does today.
  • The Cypher metadata functions labels, keys and properties read the scope's graph only. Property access, type, startNode and endNode already answer right.
  • A k-way merge for the partitioned GROUP BY, so it keeps its lane over several graphs instead of falling back to hashing.
  • Datalog rules over a default graph of several graphs see the primary graph's facts only. Whether they should see every member is more a scope decision than a bug, so this one wants a call before code.

The witness gives the fulltext() and Cypher-metadata fixes a natural home (each gets a named accessor), so I'd do those three together.

From #2010 (Not changed here: the one-graph witness; the two readers that read one graph; the k-way merge; rules over several graphs).

Activity

  1. added
    bug
    P2
    area:query
    on Oct 12, 2026
  2. aaj3f commented on Nov 19, 2026

    @aaj3f
    ContributorAuthor

    A note on the last item ("Datalog rules over a default graph of several graphs see the primary graph's facts only"), since it turned out to be less of a pure scope call than I made it sound. With a stored or query-time rule that negates, the primary-only view isn't just narrower, it's wrong in a way that looks right: over "from": ["data:main", "other:main"], a rule deriving ex:Candidate for any account with no ex:excluded fact marks everyone a candidate when the exclusions live in other, while a plain query over the same from joins across both and finds them. Swap the order and the same rule derives nothing. A body GRAPH <iri> naming another ledger, a graph source or a typo'd graph does the same thing.

    I've filed that as #2459 and suggested a loud refusal there first (heads are already refused that way), so the "should rules see every member" decision can stay here and doesn't have to happen before the silent part is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2area:querybug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions