← Home

SPARQL Exit Conditions (UNTIL)

Standard SPARQL property paths (+, *) have no way to stop early — they exhaustively traverse the entire reachable graph. sutraDB adds UNTIL: a predicate evaluated at each step that terminates traversal the moment a condition is met. Compare both approaches below.

SELECT ?president
WHERE {
  :Washington :successor+ ?president .
  ?president :diedInOffice true .
}
UNTIL (?president :diedInOffice true)
Standard SPARQL traverses every reachable node via :successor+, collecting all of them, then filters for :diedInOffice true as a post-filter. On a chain of 46 presidents, this means 46 hops even if the answer is at hop 9.
The UNTIL clause evaluates the exit predicate at each step during traversal. The moment :diedInOffice true is found, that branch terminates immediately. The remaining nodes are never visited. This is per-step predicate evaluation, not post-filtering.