Search code examples
sparqlmarklogic

Optimizing range queries in SPARQL in MarkLogic


I want to write a SPARQL query that cross references an entity with a single time point with a set of entities that have time ranges. Here's the graph pattern:

{
  ?entity :atTime  ?probe. 
  ?interval :startTime ?start ; 
            :endTime ?end . 

  FILTER (?start < ?probe) 
  FILTER (?probe < ?end)
}

One way for the query engine to run this is to find all the entities with :atTime defined, find all of the intervals, and perform all of these checks. But MarkLogic (and most databases) have facilities for range indices, so that this can be done much more efficiently.

I have seen in the ML docs that you can use cts:contains in SPARQL to reach its string indices. Is there a way to do something similar with range queries?

Some databases recognize design patterns in code like what I have quoted here, and they do that optimization themselves (which keeps the code standard!). Perhaps MarkLogic does this? I can't find any documentation telling me about this.


Solution

  • MarkLogic's triple index can perform range queries directly, so there's no need for a separate range index. The optimizer should recognize and optimize this query pattern.