Hello Sebastian,

One variant to check is

select distinct
   ?r
   (bif:concat(bif:search_excerpt(bif:vector('lego'), ?v2))) as
       ?_n_f_t_m_ex_
where {
 {{select distinct ?r ?v2 where
   { ?r ?v1 ?v2 .
     ?v2 bif:contains 'lego' .
     ?r nao:userVisible "1"^^xsd:int .
   } limit 10 } }
   UNION
 {{select distinct ?r ?v2 where
   { ?r ?v1 ?v3 .
     ?v3 ?v4 ?v2 .
     ?v4 rdfs:subPropertyOf rdfs:label .
     ?v2 bif:contains 'lego' .
     ?r nao:userVisible "1"^^xsd:int .
   } LIMIT 10 } }
} LIMIT 10

because in this case no one side of union will needlessly generate data that 
does not fit LIMIT 10.

Next optimization is to give a hint that some triples should reside in one 
graph, if this is applicable to the task in question.
E.g. if both ?r ?v1 ?v2 . and ?r nao:userVisible "1"^^xsd:int . are supposed to 
be in same graph,

?r ?v1 ?v2 .
?v2 bif:contains 'lego' .
?r nao:userVisible "1"^^xsd:int .

 can be replaced with

graph ?g { ?r ?v1 ?v2 .
?r nao:userVisible "1"^^xsd:int .
?v2 bif:contains 'lego' . }

Best Regards,

Ivan Mikhailov
OpenLink Software
http://virtuoso.openlinksw.com


On Fri, 2010-11-19 at 19:25 +0100, Sebastian Trüg wrote:
> Hi list,
> 
> as always my question is about query performance.
> The following very simple query performs very well on a V6.3rc1 with
> default indexes:
> 
> select distinct
>    ?r
>    (bif:concat(bif:search_excerpt(bif:vector('lego'), ?v2))) as
>        ?_n_f_t_m_ex_
> where {
>    { ?r ?v1 ?v2 .
>      ?v2 bif:contains 'lego' .
>    }
>    UNION
>    { ?r ?v1 ?v3 .
>      ?v3 ?v4 ?v2 .
>      ?v4 rdfs:subPropertyOf rdfs:label .
>      ?v2 bif:contains 'lego' .
>    } .
> } LIMIT 10
> 
> However, in Nepomuk we need to hide certain types from the user. To that
> end we have the nao:userVisible property. Adding that to the query,
> however, slows down the query considerably:
> 
> 
> select distinct
>    ?r
>    (bif:concat(bif:search_excerpt(bif:vector('lego'), ?v2))) as
>        ?_n_f_t_m_ex_
> where {
>    { ?r ?v1 ?v2 .
>      ?v2 bif:contains 'lego' .
>    }
>    UNION
>    { ?r ?v1 ?v3 .
>      ?v3 ?v4 ?v2 .
>      ?v4 rdfs:subPropertyOf rdfs:label .
>      ?v2 bif:contains 'lego' .
>    } .
>    ?r nao:userVisible "1"^^xsd:int .
> } LIMIT 10
> 
> Suddenly a query which was done in no time takes up to several seconds.
> This confuses me as I would think simply adding one condition on the
> results should not make such a difference.
> 
> Any ideas?
> 
> Cheers,
> Sebastian
> 
> ------------------------------------------------------------------------------
> Beautiful is writing same markup. Internet Explorer 9 supports
> standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
> Spend less time writing and  rewriting code and more time creating great
> experiences on the web. Be a part of the beta today
> http://p.sf.net/sfu/msIE9-sfdev2dev
> _______________________________________________
> Virtuoso-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/virtuoso-users



Reply via email to