[redland-dev] Querying using SPARQL - misc questions

Richard Newman r.newman at reading.ac.uk
Tue Feb 7 16:51:50 GMT 2006


> 1. Querying trying to match literal nodes, I cannot find a way to  
> match literals with language and datatype set:

RDF literals cannot have both language and datatype set, so Redland  
doesn't allow you to query that way.

> 3. I noticed that the way the query is written has effects on the  
> answering time. For instance, writing:
>
> SELECT DISTINCT ?node
> WHERE {
>     ?node rdf:type <MyRDFType>
>     ?art dcterms:references ?node
> }
>
> will be much more efficient than writing:
>
> SELECT DISTINCT ?node
> WHERE {
>     ?art dcterms:references ?node
>     ?node rdf:type <MyRDFType>
> }
>
> I benched it on a graph containing more than 100,000 statements:  
> the first query was processed in 1 second, and the second one took  
> more than 15 min (did not wait till the end). This was done using a  
> graph in memory, so I suppose that's why it may have been so slow.

In-memory is fast.

Your problem is that there are far more dcterms:references triples in  
your store than there are nodes of the specified type. The second  
query creates bindings for each pair of ?art/?node in those 100,000  
statements. This is inefficient.

> Are there any tricks to know about writing efficient queries?

Make your triple patterns most-specific-first. The patterns that  
should return the fewest results should come first. E.g., to find my  
email address, do

?x foaf:name "Richard Newman" .   # Returns 1 binding
?x foaf:mbox ?mbox .              # Returns a few bindings for that 1  
result

not

?x foaf:mbox ?mbox .              # Returns all mailbox/person pairs  
in the system
?x foaf:name "Richard Newman" .   # Refines them to mine.

-R



More information about the redland-dev mailing list