query-7a6f8e1c95ffca6ec51e5f03223bfe19

rq turtle/ttl

Sitelinks query optimizationHello. The task is to get a list of river items, which have specific language sitelinks and do not have Russian sitelink. I have made a query for this task, but it takes too much time, leading to timeout with full list on languages ("uk" "be" "pl" "cs" "sk" "bg" "mk" "sh" "hr" "sl" "bs" "hsb" "csb" "rue" "szl"). Is it possible to optimize this query? Now it takes 50 seconds to complete:

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX schema: <http://schema.org/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT DISTINCT ?item ?itemLabel WHERE {
  ?item wdt:P31 wd:Q4022 .
  OPTIONAL {
    ?sitelink schema:about ?item .
    ?sitelink schema:isPartOf <https://ru.wikipedia.org/>
  }
  FILTER (!BOUND(?sitelink))
  VALUES ?lang { "bg" "mk" "sh" "hr" "sl" "bs" "hsb" "csb" "rue" "szl" } .
  ?sitelink2 schema:about ?item .
  ?sitelink2 schema:inLanguage ?lang .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "ru,uk,be,pl,cs,sk,bg,mk,sh,hr,sl,bs,hsb,csb,rue,szl" }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v2("?item"):::projected v3("?lang") v1("?sitelink") v4("?sitelink2") c8(["bd:serviceParam"]):::iri c2(["wd:Q4022"]):::iri c5([https://ru.wikipedia.org/]):::iri c10(["ru,uk,be,pl,cs,sk,bg,mk,sh,hr,sl,bs,hsb,csb,rue,szl"]):::literal f0[["not bound(?sitelink)"]] f0 --> v1 v2 --"wdt:P31"--> c2 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v1 -."schema:about".-> v2 v1 --"schema:isPartOf"--> c5 end bind1[/VALUES ?lang/] bind1-->v3 bind10(["bg"]) bind10 --> bind1 bind11(["mk"]) bind11 --> bind1 bind12(["sh"]) bind12 --> bind1 bind13(["hr"]) bind13 --> bind1 bind14(["sl"]) bind14 --> bind1 bind15(["bs"]) bind15 --> bind1 bind16(["hsb"]) bind16 --> bind1 bind17(["csb"]) bind17 --> bind1 bind18(["rue"]) bind18 --> bind1 bind19(["szl"]) bind19 --> bind1 v4 --"schema:about"--> v2 v4 --"schema:inLanguage"--> v3 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c8 --"wikibase:language"--> c10 end