On 05/09/11 23:23, Yves Raimond wrote:
> Hello!
>
> I noticed the following weird behavior on the public DBpedia endpoint:
>
> """
> select ?uri ?subject
> where {
> FILTER (str(?uri) = 'http://dbpedia.org/resource/London' || str(?uri)
> = 'http://dbpedia.org/resource/Family_(biology)')
> ?uri<http://purl.org/dc/terms/subject> ?subject
> }
> """
>
> hangs forever, while
>
> """
> select ?uri ?subject
> where {
> FILTER (str(?uri) = 'http://dbpedia.org/resource/London')
> ?uri<http://purl.org/dc/terms/subject> ?subject
> }
> """
>
> is very quick.
>
> Looking at the queries, the earlier seems of approximately the same
> complexity as the latter?
Not quite. Your first query involves a disjunction (the '|'), which
means that a SPARQL engine can not optimize the query by "inlining" the
comparison.
Effectively, your first query forces the SPARQL engine to iterate over
all statements in the database that have a dc:subject property, and for
each statement check if either of two string comparisons hold. In the
second query, however, the engine can simply look for one particular
subject-predicate combination (dbpedia:London and dc:subject). This is
far simpler.
By the way: I am not sure if it makes a difference in the Virtuoso
SPARQL engine, but generally speaking a value comparison is far more
efficient than a string comparison. You might get faster results by
changing your FILTER conditions to:
FILTER(?uri = <http://dbpedia.org/resource/London>)
HTH,
Jeen
------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev
_______________________________________________
Dbpedia-discussion mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dbpedia-discussion