Skip to content

Query: a bound relationship variable doesn't drive its edge lookup #2237

Open

Description

@aaj3f

When a relationship variable is already bound (from a VALUES seed, or an earlier pattern) and its endpoints
aren't, MATCH (s)-[r:K]->(o) plans as a scan of every K relationship per binding rather than a lookup of
r's f:reifies* bundle. The same holds for startNode(r) / endNode(r). Instruction counts on 1,000
(:R)-[:K]->(:S) relationships (release, the #2184 harness):

Shape Instructions
MATCH (a:R)-[r:K]->(b:S) RETURN a, b, r 100.6M
the same, also returning startNode(r), endNode(r) 1,024.3M
driver re-match of r's edge, r and both endpoints seeded (1,000 rows, SET r.v = 5 DELETE r) 837M
the same re-match with only r seeded 4,658M

#2184 avoids the slow shape for a relationship DELETE by seeding the re-match with the endpoints, which it
carries through the read clauses. It still takes the slow shape for a pattern read in either direction
(-[r:K]-), where no subject is known.

Plan:

  1. Planner (fluree-db-query/src/planner.rs, the EdgeAnnotation arms): when the annotation variable is bound
    before the pattern and the edge's subject/object aren't, plan it as subject lookups of the annotation's
    f:reifiesSubject / f:reifiesPredicate / f:reifiesObject facts that bind the edge, then a point check of
    the base edge.
  2. Evaluate startNode(r) / endNode(r) from the same bundle lookup.
  3. Tests: a routing stamp (MustFire / MustNotFire) on the new plan, paired with a canary where the
    annotation variable is unbound; twin SPARQL (<< ?s ?p ?o >>-style annotation reads) and JSON-LD reads
    where the shared IR reaches them.
  4. Perf: the four rows above, plus query_scan_warm and the CI compare benches, which must not move.

Raised in review of #2184.

Activity

  1. added
    enhancement
    P3
    area:query
    on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3area:queryenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions