Page MenuHomePhabricator

Optimize SERVICE wikibase:label
Open, MediumPublic

Description

The following SPARQL query runs in less than 1 second...

SELECT ?item ?itemLabel WHERE {
  {
    SELECT ?item WHERE { ?item wdt:P31 wd:Q5. }
    LIMIT 10
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

... while the following query, which is equivalent but much simpler and common, runs in more than 17 seconds...

SELECT ?item ?itemLabel WHERE {
  ?item wdt:P31 wd:Q5.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
LIMIT 10

There's no point in having SERVICE wikibase:label optimized for the first case, we need a cleverer implementation that doesn't cause unnecessary timeouts. This optimization becomes more necessary as the number of triples grows.

Event Timeline

Smalyshev triaged this task as Medium priority.Jan 4 2019, 8:24 PM
Smalyshev added a project: WDQS-Optimizer.

One possible optimization that would cover this case is discussed in T166139.

A good example, from https://twitter.com/27point7/status/1070440727488933888 :

#Authors of scientific articles 
SELECT ?item ?itemLabel WHERE {
  ?item wdt:P31 wd:Q13442814.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
LIMIT 10

-> timeout