Skip to content

perf(executor): OPTIONAL with a filter on the right side's own variables on term ids (#11) - #177

Open
MathiasVDA wants to merge 10 commits into
mainfrom
claude/project-thread-n3oul3-2
Open

MathiasVDA wants to merge 10 commits into
mainfrom
claude/project-thread-n3oul3-2

Conversation

@MathiasVDA

@MathiasVDA MathiasVDA commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

What and why

#11, the second gap noted in #172. OPTIONAL { ?o ex:qty ?q FILTER(?q > 90) } is a left join with a filter, and the id executor sent it to the evaluator whole.

SPARQL evaluates that filter on the merged row (left plus right). It equals the right side's own filter when every variable it reads is in one of two groups:

  • always bound on the right side, so both rows give the same value;
  • never bound on the left side, so the right row decides it.

In that case Eval::eval now filters the right table with the usual filter kernels and then left-joins. Other filters, such as FILTER(?x > ?y) with ?y from the left, give up as before. The check is on the tables (maybe columns), not on the algebra, so a right side whose variable may be unbound (a nested OPTIONAL) is handled correctly. direct::covered accepts a LeftJoin whose expression the filter kernels cover.

How it was tested

  • tests/id_rows.rs BINDS has six new cases, each compared with the evaluator:

    • on ids:
      • a filter on the right side's variable;
      • a filter on the shared ?s with &&;
      • !BOUND(?x) of a nested OPTIONAL's variable;
      • arithmetic in the filter, with ORDER BY and LIMIT;
    • left to the evaluator:
      • a filter on a left variable;
      • a variable bound on the left and maybe unbound on the right.
  • tests/counts.rs:

    • The count passes read the same tables, so ?s a ?c OPTIONAL { ?s ex:feat ?f FILTER(?f != ex:f1) } is now counted on ids under both executors, and its counts match the rows'. Its assertion now expects ids.
    • A new case, FILTER(?f != ?c), reads a left variable and expects the evaluator.
  • Full tripletrail suite under the default executor: all pass. Oracle with ids as the default: all pass, apart from the two known plan-shape assertions in bind_keyed_lookup.

  • 133k orders, result cache off, same answers:

    query spareval ids
    ?o ex:placedBy ?c OPTIONAL { ?o ex:qty ?q FILTER(?q > 90) } 183 ms 35 ms
    ?c ^ex:placedBy ?o OPTIONAL { ?o ex:qty ?q FILTER(?q > 90) } 156 ms 28 ms
    COUNT(?q) with OPTIONAL { … FILTER(?a > 4000 && ?q < 10) } 20 ms 18 ms
  • cargo fmt --check and cargo clippy -p tripletrail --all-targets -D warnings pass.

Documentation

  • docs/store.md: the id tables paragraph, which said a filtered OPTIONAL is always evaluated as usual. It now says such a pattern is counted on ids, and under ids answered on ids.
  • docs/server.md: the --executor list.
  • CHANGELOG: a line under Unreleased / Changed.

Docs checked:

  • In the repo: the guide's --executor ids section (13-production.md) names OPTIONAL in general and stays true. The README has no list.
  • On the website: tripletrail-website has no page on the executor, so it needs no change.

docs/server.md touches the same line as #175. Whichever merges second needs a small merge, and I'll do it.

A product of decimals with more than 18 digits after the point gave
no value (oxsdatatypes refuses it). It is now the exact product, as
Jena's BigDecimal product: a decimal when it fits 18 fraction digits,
else the literal with all its digits, as a long quotient is.
…-n3oul3-2

# Conflicts:
#	CHANGELOG.md
#	crates/tripletrail/tests/id_rows.rs
#	docs/store.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant