This seems like a very strange query plan … Any ideas to change this massive join being done twice?
Explaining Query:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX event: <http://ontology.causeex.com/ontology/odps/Event#>
PREFIX general: <http://ontology.causeex.com/ontology/odps/GeneralConcepts#>
select (COUNT(?s) as ?count)
# location IRIs are returned in ?relatedIRI to facilitate getting events that involve a particular location
FROM <http://graph.causeex.com>
FROM <http://ontology.causeex.com>
where {
?s a ?type . ?type rdfs:subClassOf* event:Event .
?s ?p ?relatedIRI .
FILTER ( ?p IN ( general:located_at, general:located_near,
event:has_origin, event:has_destination ) ) .
?relatedIRI ?p1 ?label .
FILTER ( ?p1 IN ( rdfs:label, general:has_canonical_label ) ) .
BIND ( 'event-relatedLocation' as ?textFrom ) .
BIND ( ?label as ?relatedText )
}
The Query Plan:
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix event: <http://ontology.causeex.com/ontology/odps/Event#>
prefix general: <http://ontology.causeex.com/ontology/odps/GeneralConcepts#>
From <http://ontology.causeex.com>
From <http://graph.causeex.com>
Projection(?count) [#1]
`─ Group(aggregates=[(COUNT(*) AS ?count)]) [#1]
`─ HashJoin(?p1) [#1]
+─ HashJoin(?p1) [#1]
│ +─ Bind("event-relatedLocation" AS ?textFrom) (?label AS ?relatedText) [#433]
│ │ `─ MergeJoin(?relatedIRI) [#433]
│ │ +─ Sort(?relatedIRI) [#433]
│ │ │ `─ MergeJoin(?s) [#433]
│ │ │ +─ Sort(?s) [#69]
│ │ │ │ `─ MergeJoin(?type) [#69]
│ │ │ │ +─ Sort(?type) [#214]
│ │ │ │ │ `─ PropertyPath(event:Event -> ?type, minLength=0) [#214]
│ │ │ │ │ `─ Scan[POSC](?type, rdfs:subClassOf, event:Event) [#107]
│ │ │ │ `─ Scan[POSC](?s, rdf:type, ?type) [#3.6M]
│ │ │ `─ Scan[SPOC](?s, ?p, ?relatedIRI) [#20.1M]
│ │ `─ Scan[SPOC](?relatedIRI, ?p1, ?label) [#20.1M]
│ `─ VALUES (?p1) {
│ +─ ( rdfs:label )
│ `─ ( general:has_canonical_label )
│ }
`─ HashJoin(?p) [#1]
+─ Bind("event-relatedLocation" AS ?textFrom) (?label AS ?relatedText) [#433]
│ `─ MergeJoin(?relatedIRI) [#433]
│ +─ Sort(?relatedIRI) [#433]
│ │ `─ MergeJoin(?s) [#433]
│ │ +─ Sort(?s) [#69]
│ │ │ `─ MergeJoin(?type) [#69]
│ │ │ +─ Sort(?type) [#214]
│ │ │ │ `─ PropertyPath(event:Event -> ?type, minLength=0) [#214]
│ │ │ │ `─ Scan[POSC](?type, rdfs:subClassOf, event:Event) [#107]
│ │ │ `─ Scan[POSC](?s, rdf:type, ?type) [#3.6M]
│ │ `─ Scan[SPOC](?s, ?p, ?relatedIRI) [#20.1M]
│ `─ Scan[SPOC](?relatedIRI, ?p1, ?label) [#20.1M]
`─ VALUES (?p) {
+─ ( general:located_at )
+─ ( general:located_near )
+─ ( event:has_origin )
`─ ( event:has_destination )
}
Thanks.
Andrea