Hey STARDOG community,
I am having issues with a DELETE query which causes high load and timeouts in my stardog instance.
I want to delete specific triples in my graph if they are existing. The tree I am specifying for the delete looks like this:
Instance of the class A are connected to instances of the class B.
Instances of the classes C, D, E, F, G and H are connected to the instances of class B.
The classes C, D, E, F, G and H could also have connected classes (example class X). The instances of directly connected classes like class X should also be deleted if existent.
My SPARQL query looks like this:
PREFIX ex: <http://example.org/>
DELETE {
?A ?p1 ?o1 .
?B ?p2 ?o2 .
?C ?p3 ?o3.
?D ?p4 ?o4.
?E ?p5 ?o5.
?F ?p6 ?o6.
?G ?p7 ?o7.
?H ?p8 ?o8.
}
WHERE {
VALUES ?A {
{{#each data_array}}
:A_{{this.instancesOfA}}
{{/each}}
}
?A ?p1 ?o1 .
OPTIONAL {
?A ex:AisConnectedToB ?B.
OPTIONAL {?B ?p2 ?o2 .}
OPTIONAL {
?B ex:BisConnectedToC ?C.
?C ?p3 ?o3.
}
OPTIONAL {
?B ex:BisConnectedToD ?D.
?D ?p4 ?o4.
}
OPTIONAL {
?B ex:BisConnectedToE ?E.
?E ?p5 ?o5.
}
OPTIONAL {
?B ex:BisConnectedToF ?F.
?F ?p6 ?o6.
}
OPTIONAL {
?B ex:BisConnectedToG ?G.
?G ?p7 ?o7.
}
OPTIONAL {
?B ex:BisConnectedToH ?H.
?H ?p8 ?o8.
}
}
}
I am using a template which loads ca. 4100 different instances of the class A and inserts them with the VALUES clause.
Can I somehow optimize the performance of the query?
I thought of this:
- Instead of starting with the class A as the root, I could start with the class B as the root as class B has all the other classes are connected to B
- Instead using one query, I could use several separate DELETE queries like `DELETE WHERE {
?a a ex:A ;
?p1 ?o1 .
}
DELETE WHERE {
?b a ex:B ;
?p2 ?o2 .
}
DELETE WHERE {
?c a ex:C ;
?p3 ?o3 .
}`
Guidance will be very helpful,
cheers!