I have a fairly complex SPARQL query with the structure outlined below, involving multiple graph patterns, UNION
and nested FILTER NOT EXISTS
.
I want the query to remain generic, and I want to be able to inject values for certain variables at execution time, and my idea is to append a VALUES
keyword at the end of the query to specify the value of certain variables in the query. In the structure below, I set the value of ?x
, and I illustrate all the places in the query where ?x
applies.
However, in Fuseki I see that executing the query like that takes around 4 to 5 seconds, but manually replacing the ?x
variable in the query with a URI, instead of specifying a VALUES
clause, makes it run very fast.
- I always thought that using the
VALUES
keyword at the end of theWHERE
clause was like setting values inline for some variables, so I would expect using theVALUES
clause or replacing the variables with their corresponding URI was the same in terms of query execution. Can someone confirm the expected behavior of theVALUES
keyword? also explain the difference between using it outside of theWHERE
clause or inside of theWHERE
clause ? - Does the fact that the variable set using
VALUES
appears inFILTER NOT EXISTS
clause change something? - Can you confirm this is the correct approach for the requirement above (I want the query to remain generic and I want to be able to inject values for certain variables at execution time)?
- Is it possible that this behavior is specific to how Fuseki handles
VALUES
?
Thanks !
SELECT DISTINCT ...
WHERE {
# ?x ...
# ... basic graph pattern here
{
{
# ... basic graph pattern here
FILTER NOT EXISTS {
# ?x ...
# ... basic graph pattern here
}
FILTER NOT EXISTS {
# ... basic graph pattern here
FILTER NOT EXISTS {
# ?x ...
# ... basic graph pattern here
}
}
}
UNION
{
?x ...
# ... basic graph pattern here
}
UNION
{
# ... basic graph pattern here
FILTER NOT EXISTS {
?x ...
# ... basic graph pattern here
}
FILTER NOT EXISTS {
# ... basic graph pattern here
FILTER NOT EXISTS {
?x ...
# ... basic graph pattern here
}
}
}
UNION
{
?x ...
}
}
}
VALUES ?x { <http://example.com/Foo> }