query-bcae36c6c5044c6bb55d447a0e668bcb
Query Optimization for bypassing the TimeOut ExceptionHello, I wrote the following Query that consists of extracting the products and their brands, but the result that I received is not efficient and generates the TimeOut Exception. Therefore, I need to optimize it and please provide me some relevant references for SPARQL Query Optimization.
Use at
- https://query.wikidata.org/sparql
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bd: <http://www.bigdata.com/rdf#>
select DISTINCT ?brand ?brandLabel (GROUP_CONCAT(?itemName; SEPARATOR=", ") AS ?ProductsItemName)
where {
?CompanyID wdt:P31 wd:Q4830453.
OPTIONAL{?CompanyID wdt:P1056 ?MaterialProduced.}
OPTIONAL {?item wdt:P279* ?MaterialProduced.
?item wdt:P1716 ?brand.}
SERVICE wikibase:label{
bd:serviceParam wikibase:language "en".
?item rdfs:label ?itemName.
?brand rdfs:label ?brandLabel.
}
}
GROUP BY ?brand ?brandLabel
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v1("?CompanyID")
v2("?MaterialProduced")
v7("?ProductsItemName")
v4("?brand"):::projected
v6("?brandLabel"):::projected
v3("?item")
v5("?itemName"):::projected
c7(["bd:serviceParam"]):::iri
c2(["wd:Q4830453"]):::iri
c9(["en"]):::literal
v1 --"wdt:P31"--> c2
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v1 -."wdt:P1056".-> v2
end
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v3 -."wdt:P279".-> v2
v3 --"wdt:P1716"--> v4
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c7 --"wikibase:language"--> c9
v3 --"rdfs:label"--> v5
v4 --"rdfs:label"--> v6
end
bind1[/"?itemName"/]
v5 --o bind1
bind1 --as--o v7