Virtuoso Open-Source Wiki
Virtuoso Open-Source, OpenLink Data Spaces, and OpenLink Ajax Toolkit
Advanced Search
Help?
Location: / Dashboard / Main / VirtTipsAndTricksGuide / VirtTipsAndTricksGuideMergeOneByOne

Is there a difference between a "merge" vs "one by one" execution of the queries across the named graphs?

Indeed there should be difference. Wrapping everything into GRAPH ?g { ... } means that all triple patterns inside this "graph group pattern" should be bound by values from one and the same ?g whereas without specifying ?g the triples in question may be found in different graphs. Thus graph group pattern can dramatically reduce the amount of data to process for all triple patterns after the first in join order, so it's typically faster.

Virtuoso does not make a union of all graphs to make a single big "default graph", it makes a sum, so the behavior slightly differs from the SPARQL spec (same data, but some duplicate results can appear if same combination of S P and O appears in two or more different graphs). So the equivalent of:

[PREFIXes here]
 SELECT ?serial ?sr ?ct1 ?ct2 
WHERE 
  {
    ?sr a dm:SessionRecord .
    ?sr dm:hasDataSnapshot ?snap .
    ?device dm:hasSessionRecord ?sr .
    ?device dm:hasSerialNumber ?serial .
    [etc.] 
  }

with graphs would be:

[PREFIXes here]
SELECT ?serial ?sr ?ct1 ?ct2 
WHERE 
  {
    graph ?g1 { ?sr a dm:SessionRecord . }
    graph ?g2 { ?sr dm:hasDataSnapshot ?snap . }
    graph ?g3 { ?device dm:hasSessionRecord ?sr . }
    graph ?g4 { ?device dm:hasSerialNumber ?serial . }
    [etc.] 
  }

i.e. every triple pattern can be found in same or different graph with previous.

Related

Powered By Virtuoso