Hello Frode,

The difference means that the optimizer overestimated the selectivity of
the new triple pattern and placed it before free-text. There are two
typical fixes for such cases: an accurate one and a "dirty hack".

The accurate is possible if you know that some of triples in question
are always in same graph, or you know that some triple pattern appears
only in some source graphs, not in all of them.

For triple patterns resided in one graph, the pattern graph ?g
{ pattern1 . pattern2 } could be much faster than just two patterns.
Typical examples are
graph ?g { ?s foaf:firstName ?fname ; foaf:familyName ?lname }
and
graph ?g { ?s geo:lat ?lat ; geo:long ?long }

For triple pattern from a fixed graph, use graph <const> {...}.

In both cases, pay attention to the difference between FROM and FROM
NAMED and adjust that part of query as needed.


The dirty hack is to read the execution plan of a "good" query via
explain() BIF, then reorder triple patterns to match the order of
filtering in the execution plan, then ensure that the query is executed
with same speed if define sql:select-option "ORDER" is added to the
front. If it's so then place the additional triple pattern at the very
end of the "good" pattern and keep define sql:select-option "ORDER"
unchanged. In this case, an extra triple pattern will not severely
change the performance. This method is simple but using graph group
patterns may give you better speed even on original fast version.

Best Regards,

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

On Tue, 2010-09-14 at 12:42 +0200, Frode Roxrud Gill wrote:
> I am preparing for an upgrade to Virtuoso 6.1.2, and during testing I
> see that two almost identical queries give very different response time
> - the one with an extra restriction takes a lot longer(!) to complete.
> 
> At <URL: http://msoneutv.computas.no:8890/sparql >, copy&pasting the
> following query gives an almost immediate response:
> ==============================
> prefix sub: <http://xmlns.computas.com/sublima#>
> prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> prefix rdfs:<http://www.w3.org/2000/01/rdf-schema#>
> prefix owl:<http://www.w3.org/2002/07/owl#>
> prefix xsd:<http://www.w3.org/2001/XMLSchema#>
> prefix yago:<http://dbpedia.org/class/yago/>
> prefix dct:<http://purl.org/dc/terms/>
> prefix foaf:<http://xmlns.com/foaf/0.1/>
> prefix cc:<http://creativecommons.org/ns#>
> prefix mo:<http://purl.org/ontology/mo/>
> prefix mm:<http://musicbrainz.org/mm/mm-2.1#>
> prefix mediasone:<http://www.computas.com/mediasone#>
> prefix mv:<http://www.computas.com/mediasone-vokabular/>
> prefix mi:<http://www.computas.com/mediasone-instanser/>
> DESCRIBE ?resource  FROM <http://msone.computas.no/graphs/instance/nfi>
> FROM <http://msone.computas.no/graphs/help/mediasone>
> FROM <http://msone.computas.no/graphs/instance/mo>
> FROM <http://msone.computas.no/graphs/inferred/nfi/agent-realisation1>
> FROM <http://msone.computas.no/graphs/inferred/nfi/realisation1>
> FROM <http://msone.computas.no/graphs/inferred/mo/agent-realisation1>
> FROM <http://msone.computas.no/graphs/inferred/mo/realisation1>
> FROM <http://msone.computas.no/graphs/index/vocab_mediasone>
> FROM <http://msone.computas.no/graphs/index/mo_agent-classification>
> FROM <http://msone.computas.no/graphs/index/inferred_classification>
> FROM <http://msone.computas.no/graphs/index/nfi_agent-classification>
> FROM <http://msone.computas.no/graphs/index/instance_nfi>
> FROM <http://msone.computas.no/graphs/index/instance_mo>
> FROM <http://msone.computas.no/graphs/index/ontology_mediasone>
> WHERE  { ?resource sub:literals ?title. ?title bif:contains "'her*'" .
> ?resource a <http://creativecommons.org/ns#Work> . ?resource dct:title
> ?actualtitle  } ORDER BY ?actualtitle LIMIT 120 OFFSET 0
> ==============================
> 
> However, adding an extra restriction on ?resource, "?resource  a
> <http://www.computas.com/mediasone-ontologi#Aktoer>", gives a very slow
> response
> ==============================
> prefix sub: <http://xmlns.computas.com/sublima#>
> prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> prefix rdfs:<http://www.w3.org/2000/01/rdf-schema#>
> prefix owl:<http://www.w3.org/2002/07/owl#>
> prefix xsd:<http://www.w3.org/2001/XMLSchema#>
> prefix yago:<http://dbpedia.org/class/yago/>
> prefix dct:<http://purl.org/dc/terms/>
> prefix foaf:<http://xmlns.com/foaf/0.1/>
> prefix cc:<http://creativecommons.org/ns#>
> prefix mo:<http://purl.org/ontology/mo/>
> prefix mm:<http://musicbrainz.org/mm/mm-2.1#>
> prefix mediasone:<http://www.computas.com/mediasone#>
> prefix mv:<http://www.computas.com/mediasone-vokabular/>
> prefix mi:<http://www.computas.com/mediasone-instanser/>
> DESCRIBE ?resource  FROM <http://msone.computas.no/graphs/instance/nfi>
> FROM <http://msone.computas.no/graphs/help/mediasone>
> FROM <http://msone.computas.no/graphs/instance/mo>
> FROM <http://msone.computas.no/graphs/inferred/nfi/agent-realisation1>
> FROM <http://msone.computas.no/graphs/inferred/nfi/realisation1>
> FROM <http://msone.computas.no/graphs/inferred/mo/agent-realisation1>
> FROM <http://msone.computas.no/graphs/inferred/mo/realisation1>
> FROM <http://msone.computas.no/graphs/index/vocab_mediasone>
> FROM <http://msone.computas.no/graphs/index/mo_agent-classification>
> FROM <http://msone.computas.no/graphs/index/inferred_classification>
> FROM <http://msone.computas.no/graphs/index/nfi_agent-classification>
> FROM <http://msone.computas.no/graphs/index/instance_nfi>
> FROM <http://msone.computas.no/graphs/index/instance_mo>
> FROM <http://msone.computas.no/graphs/index/ontology_mediasone>
> WHERE  { ?resource  a
> <http://www.computas.com/mediasone-ontologi#Aktoer> . ?resource
> sub:literals ?title. ?title bif:contains "'her*'" .  ?resource a
> <http://creativecommons.org/ns#Work> . ?resource dct:title ?actualtitle
> } ORDER BY ?actualtitle LIMIT 120 OFFSET 0
> ==============================
> 
> 
> Can any of you see an error in the query, any hints on where to log or
> debug, or anything else that can resolve this issue and make it possible
> to upgrade the production environment?
> (The queries are generated by a multimedia application, but its
> sourcecode can be changed if needed)
> 




Reply via email to