1

Following the question at Difference in performance between using VALUES keyword and using directly the URI in the query?, I learned that using a VALUES clause at the end of the query is not always equivalent in terms of performance and query optimization than using directly a URI instead of the variable in the query string.

Comment from Andy says "VALUES at the end is "like setting variables" but isn't the same. The optimizer tries to push the values in but that can't happen in all cases as it changes the semantics."

Can someone explain in which cases this can't happen? for which query structures, and why exactly? I need to understand in which situations this technique (that I happily used for years now) is not advisable.

Note that I am not fluent with SPARQL algebra, so please try using simple words :-)

(I know this is not specific to Jena or RDF4J but I tag the question with these 2 tags since I understood the optimization of this might be different depending on the framework used).

TallTed
  • 9,069
  • 2
  • 22
  • 37
ThomasFrancart
  • 470
  • 3
  • 13
  • 1
    I don't have any specific examples right off the bat, but typically, structures where this is a problem are sub-selects and grouped graph patterns - that is any patterns where variable bindings from outside the group are _not_ in scope. In those situations, the query planner can often not do a like-for-like substitution, which can result in a difference in performance between the version using `VALUES` and the version where you have manually replaced the variable. – Jeen Broekstra Jul 06 '19 at 04:34
  • 1
    In addition to Jeen's points, use in BOUND, and EXIST (which is a kind of subquery), other VALUES clauses, AS (BIND and SELECT expressions), and if it was a literal rather than a URI, GRAPH. Double nested OPTIONALs can also be difficult. – AndyS Jul 06 '19 at 21:46
  • Also some interesting examples regarding bottom-up semantics: https://wiki.blazegraph.com/wiki/index.php/SPARQL_Bottom_Up_Semantics#Other_Problematic_Cases:_BIND_and_VALUES – UninformedUser Jul 07 '19 at 11:45
  • Great to know, thanks. Could you/we compile a list of example queries as an answer, illustrating the most common cases (FILTER NOT EXISTS, grouped graph patterns, subqueries, OPTIONAL ?) – ThomasFrancart Jul 08 '19 at 07:11

0 Answers0