Hi Nicola,

A slightly faster form is to make one OPTIONAL with an UNION instead of 
two OPTIONALs.

e.g.
CONSTRUCT {<http://dbpedia.org/resource/Coen_brothers>  ?p ?o.
?sub ?p_sub ?o_sub.
?type ?p_type ?o_type.
    }
where {
    <http://dbpedia.org/resource/Coen_brothers>  ?p ?o
OPTIONAL {
    {
    <http://dbpedia.org/resource/Coen_brothers> 
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>  ?type.
    ?type ?p_type ?o_type.
    } UNION {
    <http://dbpedia.org/resource/Coen_brothers> 
<http://purl.org/dc/terms/subject>  ?sub.
    ?sub ?p_sub ?o_sub.
    }
   }
}

However they do run very fast on http://lod.openlinksw.com/sparql.
So your settings or hardware might not be balanced for your performance 
needs.

Regards,
Jerven

PS.
The query can be further simplified by using the PATH query syntax

CONSTRUCT {<http://dbpedia.org/resource/Coen_brothers>  ?p ?o.
?type ?p_type ?o_type.
    }
where {
    <http://dbpedia.org/resource/Coen_brothers>  ?p ?o
OPTIONAL {
    <http://dbpedia.org/resource/Coen_brothers> 
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>|<http://purl.org/dc/terms/subject>
 
  ?type.
    ?type ?p_type ?o_type.
    }
}


On 21/03/14 16:54, ghirardi nicola wrote:
> I have this kind of queries that do not perform as expected (transaction
> timeout usually).
> Here an example on dbpedia:
>
> CONSTRUCT { <http://dbpedia.org/resource/Coen_brothers> ?p ?o.
> ?sub ?p_sub ?o_sub.
> ?type ?p_type ?o_type.
>    }
> where {
>    <http://dbpedia.org/resource/Coen_brothers> ?p ?o
> OPTIONAL {
>    <http://dbpedia.org/resource/Coen_brothers>
> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?type.
>    ?type ?p_type ?o_type.
> }
> OPTIONAL {
>    <http://dbpedia.org/resource/Coen_brothers>
> <http://purl.org/dc/terms/subject> ?sub.
>    ?sub ?p_sub ?o_sub.
> }
> }
>
> The query answer very fast if I remove one of the optional or the "?p
> ?o" part.
> Is it something expected?
> Can you suggest me another query to get the same response?
> Would use all the properties in separated optional works faster?
>
> Thanks
> Nicola
>
> ------------------------------------------------------------------------------
> Learn Graph Databases - Download FREE O'Reilly Book
> "Graph Databases" is the definitive new guide to graph databases and their
> applications. Written by three acclaimed leaders in the field,
> this first edition is now available. Download your free book today!
> http://p.sf.net/sfu/13534_NeoTech
> _______________________________________________
> Virtuoso-users mailing list
> Virtuoso-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/virtuoso-users
>

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Virtuoso-users mailing list
Virtuoso-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/virtuoso-users

Reply via email to