This site has been retired. For up to date information, see handbook.gnome.org or gitlab.gnome.org.


[Home] [TitleIndex] [WordIndex

1. Sparql Tips & Tricks

The performance of tracker from the application point of view can vary a lot depending on the quality of the queries. Here are some tips to improve the speed from application point of view.

1.1. Retrieve ONLY what you need NOW

1.2. Minimize the number of queries

1.3. OPTIONALS are a performance killer

1.4. tracker:coalesce function

1.5. Use property functions

1.6. Syntactic sugar and performance

FIXME: Format this with examples!

Q: Is there a difference between OPTIONAL{foo}.OPTIONAL{bar} and OPTIONAL{foo. bar} ?
A: yes. { foo bar } matches nothing if only exactly one of the two is set

 # These two queries are NOT equivalent!

 SELECT ?a ?b WHERE {
   OPTIONAL {
      ?x nie:title ?a .
      ?x nie:description ?b .
 }

 ---
 
 SELECT ?a ?b WHERE {
   OPTIONAL {
      ?x nie:title ?a .
   }
   OPTIONAL {
      ?x nie:description ?b .
   }
 }

Q: Is there a difference between GRAPH x {foo . bar} and GRAPH x {foo}.GRAPH x {bar}
A: that should be equivalent

 FIXME: Example here

Q: For the graph case, is there a perf advantage of having only 1 GRAPH{} ? or is it only marginal?
A: Same overhead as {foo} {bar} compared to {foo . bar}. in many cases marginal. in some it might be significant

 FIXME Example here

Q: Same question with "resource prop1 value1.resource prop2 value2" VS "resource prop1 value1; prop2 value2" ?
A: That makes no difference at all

 # These two queries are equivalent, no performance difference:

 SELECT ?a ?b WHERE {
   ?x nie:title ?a .
   ?x nie:description ?b .
 }

 SELECT ?a ?b WHERE {
   ?x nie:title ?a ;
      nie:description ?b .
 }

Q: Does DELETE {foo rdf:type ?v} WHERE {foo rdf:type ?v} remove completely the resource foo ?
A: No, DELETE { <foo> a rdfs:Resource } does.


2024-10-23 10:59