SPARQL construct - not finishing on larger data #987
-
Hello, could you please help me with another problem with larger data? PREFIX sp: <http://spinrdf.org/sp#>
PREFIX msmt: <http://msmt.cz/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
CONSTRUCT {
?parent ?p3 ?sub .
?parent ?p4 ?o4 .
?sub ?p ?o .
?o ?p2 ?o2 .
?o2 ?p5 ?o3 .
}
WHERE {
?sub ?p ?o .
?sub msmt:kraj ?kraj .
FILTER(?kraj = 'Pardubický kraj') .
OPTIONAL {?o ?p2 ?o2} .
OPTIONAL {?o2 ?p5 ?o3} .
?parent ?p3 ?sub .
?parent ?p4 ?o4 .
} Input data are attached... |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
The query is quite generic like this, causing lots of joins and poor performance. It would be better to fit the predicates and classes present in the data. This one without the parents works quite well: PREFIX sp: <http://spinrdf.org/sp#>
PREFIX msmt: <http://msmt.cz/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
CONSTRUCT {
?sub ?p ?o .
?o ?p2 ?o2 .
?o2 ?p5 ?o3 .
}
WHERE {
?sub ?p ?o .
?sub msmt:kraj ?kraj .
FILTER(?kraj = 'Pardubický kraj') .
OPTIONAL {?o ?p2 ?o2 OPTIONAL {?o2 ?p5 ?o3} } .
} |
Beta Was this translation helpful? Give feedback.
-
Thank you very much for your answer, it helped a lot. I am learning sparql here and wasn't aware about the optionals problem... Without the parents clause, it runs ok... with the parents, it is significantly slower... but finishes. I think I need the parents as well, but maybe I'll find a way how to live without them. |
Beta Was this translation helpful? Give feedback.
The query is quite generic like this, causing lots of joins and poor performance. It would be better to fit the predicates and classes present in the data.
Also, careful of the OPTIONALS as like this, you are doing a cartesian product as ?o ?p2 ?o2 is independent of ?o2 ?p5 ?o3.
This one without the parents works quite well: